Howdy! I’m relatively new to RSpec, but I’ve worked with Watir and Ruby
for
about 5 years now. My company is redesigning a web app from the ground
up,
so I’m taking the opportunity to leverage RSpec instead of Test/Unit.
I’ve run into a problem with RSpec organization that I just can’t sort
out
on my own, so I’m hoping it’s straightforward enough that someone can
help
me out.
Basically I have a single HTML page with an organized list of links.
Each
link points to a new page with a single verifiable item on it. The
script
collects all the links into an array, then iterates over the array,
loading
each link and verifying a single piece of text. That’s the easy part.
Here’s the relevant code for what I believe to be the closest attempt
right
now:
@links = Array.new
@browser = Watir::Browser.new
@browser.goto(page)
@browser.link.each do |link|
@links << [link.name, link.href]
end
@links.each do |name, link|
describe name do
it "should contain the word #{name}" do
@browser.goto link
@browser.div(:id, /example/).text.should
include(name)
end #it
end #desc
end #@links
I’ve tried a combination of methods – putting all of this code inside a
describe block, etc, but I end up with the variables being unknown
because
they’re not inside the same describe or it block (even when set to
$global),
or the describe/it blocks being layered incorrectly.
I’m sure there’s a simple solution to the format, but unfortunately I
haven’t been able to Google or RDoc my way to an answer. I appreciate
any
advice you can offer!
Thanks,
Adam
View this message in context:
http://old.nabble.com/RSpec-and-Watir%2C-easy-script-structure-question-tp27758607p27758607.html
Sent from the rspec-users mailing list archive at Nabble.com.