Solution for documentation: not everything has to go inside a describe
block. Create/collect the array before any describe methods.
@Array = [...] or Method to collect array data
@array.each do |name, stuff|
describe name do
it "should put the lotion in the basket" do
<code>
end
end
end
On Mar 3, 9:12 am, Adam Reed <[email protected]> wrote:
> Thanks guys, that makes sense. I'm definitely focusing too much on
> the new element (RSpec) and too little on the basic architecture!
>
> On Mar 3, 7:18 am, Ethan <[email protected]> wrote:
>
> > You're defining the @countries instance variable outside of any method.
> > You're making @countries an instance variable of whatever 'self' is in the
> > describe block (which appears to be a class or a module), which is not the
> > same thing that your methods are being called on (presumably an instance of
> > that class or a class including that module). If you want 'countries' to be
> > the same across all instances of the class, use a class variable. If you
> > want it to be the same throughout the program, use a global. If it should be
> > per-instance, use an instance variable defined in some method of the class
> > (#initialize, most likely).
>
> > On Tue, Mar 2, 2010 at 16:11, Adam Reed <[email protected]> wrote:
> > > This script works, but only if I explicitly define the array that I'm
> > > iterating over (][countryname, url]].each do, rather than
> > > @countries.each do). In a nutshell, the script goes to a static page,
> > > collects the links, visits each linked page and verifies an item - it
> > > has been significantly dumbed down for the purpose of this question
> > > and I have tested this simplified version to make sure it gives the
> > > same output.
>
> > > Can someone help me understand why my array here (@countries) is not
> > > recognized? I tried to instantiate it as a global variable
> > > ($countries) and it still was not recognized. Is it an issue with my
> > > organization/format, or something else?
>
> > > **** Again, if I explicitly describe an array in place of the
> > > variable, the script works ****.
>
> > > global_page_spec.rb
> > > $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') if $0 ==
> > > __FILE__
> > > require 'helpers/example_helper'
>
> > > describe "The country page for" do
> > > include ExHelper
>
> > > before(:all) do
> > > setup
> > > collect_global_countries
> > > end
>
> > > �[email protected] do |name, link|
> > > describe name do
> > > it "should contain the word #{name} in the title" do
> > > �[email protected] link
> > > �[email protected](:id, /content-content/).text.should include(name)
> > > end #it
> > > end #desc
> > > end #countries
>
> > > after(:all) do
> > > teardown
> > > end #after
> > > end #spec
>
> > > example_helper.rb
> > > $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') if $0 ==
> > > __FILE__
> > > require 'helpers/global_helper'
>
> > > module ExHelper
> > > include GlobalHelper
>
> > > def setup
> > > �...@browser = Watir::Browser.new
> > > �[email protected]_checker lambda {|b| b.text.should_not include('The
> > > requested page could not be found.')}
> > > end # setup
>
> > > def collect_global_countries
> > > �...@countries = Array.new
> > > �[email protected] be_empty
>
> > > �[email protected] "http://www.#{$env}.com/global"
> > > �[email protected](:class, /global-list/).links.each do |link|
> > > �...@countries << [link.text, link.href]
> > > end #links
>
> > > �[email protected]_not be_empty
>
> > > def teardown
> > > �[email protected]
> > > end # teardown
> > > end #module
>
> > > The Error:
>
> > > global_page_spec.rb:12: undefined method `each' for nil:NilClass
> > > (NoMethodError)
> > > from C:/Ruby/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/example/
> > > example_group_methods.rb:183:in `module_eval'
> > > from C:/Ruby/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/example/
> > > example_group_methods.rb:183:in `subclass'
> > > from C:/Ruby/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/example/
> > > example_group_methods.rb:55:in `describe'
> > > from C:/Ruby/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/example/
> > > example_group_factory.rb:31:in `create_example_group'
> > > from
> > > C:/Ruby/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/dsl/main.rb:
> > > 28:in `describe'
> > > from global_page_spec.rb:4
>
> > > --
> > > You received this message because you are subscribed to the Google Groups
> > > "Watir General" group.
> > > To post to this group, send email to [email protected]
> > > Before posting, please read the following guidelines:
> > >http://wiki.openqa.org/display/WTR/Support
> > > To unsubscribe from this group, send email to
> > > [email protected]<watir-general%[email protected]>
> > > For more options, visit this group at
> > >http://groups.google.com/group/watir-general
>
>
--
You received this message because you are subscribed to the Google Groups
"Watir General" group.
To post to this group, send email to [email protected]
Before posting, please read the following guidelines:
http://wiki.openqa.org/display/WTR/Support
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/watir-general