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
@countries.each do |name, link|
describe name do
it "should contain the word #{name} in the title" do
@browser.goto link
@browser.div(: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
@browser.add_checker lambda {|b| b.text.should_not include('The
requested page could not be found.')}
end # setup
def collect_global_countries
@countries = Array.new
@countries.should be_empty
@browser.goto "http://www.#{$env}.com/global"
@browser.table(:class, /global-list/).links.each do |link|
@countries << [link.text, link.href]
end #links
@countries.should_not be_empty
def teardown
@browser.close
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]
For more options, visit this group at
http://groups.google.com/group/watir-general