chrisjroos@gmail.com
9/21/2006 1:22:00 PM
On 9/21/06, aidy <aidy.rutter@gmail.com> wrote:
> Hi,
>
> I have a test class the inherits from Test::Unit::TestCase.
>
> If I create a setup and teardown method
>
> def setup
> Browser.start
> log_in
> end
>
>
> def teardown
> log_out
> Browser.close
> end
>
> # and create class attributes here
>
> @search = "Employee was created successfully"
>
> they are not seen in my test method ...
>
> def test_ST_MSE_4
>
> enter_employee
> click_submit
> assert($ie.contains_text(@search))
>
> end
>
> But if I put the class attributes in the setup method, they are seen by
> my test(s).
> Is it normal practice to enter your class attributes in the setup
> method?
>
Yup.
A class that derives from Test::Unit::TestCase is still just a normal
class. Normal classes don't follow what you seem to expect of a
test_case derived class.
Consider...
class Foo
@foo = 123
def bar
p @foo
end
end
Foo.new.bar
#=> nil
The instance of Foo that we create can't see the class instance
variable (@foo = 123).
You could change the bar method to..
p self.class.instance_variable_get(:@foo)
but I'd guess you don't want to do that.
Hope this helps,
Chris