@countries is an instance variable of whatever 'self' is in the scope where
@countries is used. I don't know if that ends up being the same object
inside the 'describe' block and the 'it' blocks, but it sounds like it's
not. one simple test would be just to add
puts self.inspect
to the beginning of the describe block, and also to an 'it' block. if
they're not the same, then using an instance variable as you have it (used
in both 'describe' and 'it') won't work.
Alan: I don't know really know much about rspec, but it sounds like each
'it' block gets a different instance of ... whatever is being instantiated.
so instance variables are different for each 'it' block. if before(:all) is
run first, then the instance variable is defined before each 'it' block, on
each instance.

On Fri, Mar 5, 2010 at 00:06, Alan Baird <aba...@bairdsnet.net> wrote:

> Adam -
>
> I think the problem is here:
>
> it "should contain a table with links" do
>        @browser.table(:class, /example/).links.each do |link|
>          @countries << [link.text, link.href]
>        end #links
>
>        @countries.should_not be_empty
>      end #it
>
> You are defining @countries in this method and then proceed to use it
> outside of subsequent "it" statements.  Although I can't really describe
> exactly what is going on in RSpec, I think "a" way you can fix this is put
> '@countries = []' in before(:all). It's probably not good form, but it might
> be a workaround until you can get something going.  The general rule I go
> with is that you can't assign an instance variable in a "it" block in one
> test and use it in another.  It has to be declared in the before(:all)
> section.  If anyone has a good explanation for why this happens I'd love to
> hear it.
>
> Alan
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Watir General" group.
To post to this group, send email to watir-general@googlegroups.com
Before posting, please read the following guidelines: 
http://wiki.openqa.org/display/WTR/Support
To unsubscribe from this group, send email to 
watir-general+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/watir-general

Reply via email to