[rspec-users] RSpec and Watir, easy script structure question

Adam Reed reed.adam at gmail.com
Tue Mar 2 20:40:15 EST 2010


Thanks David.  I have the basic format working in other scripts, so that's a
good sign.  Another user pointed me to this example, which is why I was
exploring a different format:


> ["Los Angeles", "Austin"].each do |location|
>     it "should show #{location}" do
>       @browser.div(:id, /example/).text.should include(location)
>     end
> end
>

Is this not correct/usable?

Thanks again,
Adam

On Tue, Mar 2, 2010 at 6:11 PM, David Chelimsky <dchelimsky at gmail.com>wrote:

> On Tue, Mar 2, 2010 at 11:24 AM, Adam R <reed.adam at gmail.com> wrote:
> >
> > 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!
>
> describe "something" do
>  it "does something" do
>  end
> end
>
> That's the simplest format - everything should go in the example (it
> block), not directly inside the describe block.
>
> HTH,
> David
>
> >
> > 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.
> >
> > _______________________________________________
> > rspec-users mailing list
> > rspec-users at rubyforge.org
> > http://rubyforge.org/mailman/listinfo/rspec-users
> >
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20100302/b04b3514/attachment.html>


More information about the rspec-users mailing list