getting started with webrat

1 view
Skip to first unread message

lsiden

unread,
Sep 27, 2009, 10:15:06 PM9/27/09
to Detroit.rb
Anybody use webrat? I want to get started using Ruby to to test (non-
Ruby) websites I build. The page http://gitrdoc.com/brynary/webrat/tree/master
shows this example:

class SignupTest < ActionController::IntegrationTest

def test_trial_account_sign_up
visit home_path
click_link "Sign up"
fill_in "Email", :with => "go...@example.com"
select "Free account"
click_button "Register"
end
end

Whats confusing me is that ActionController::IntegrationTest is
defined in the Rails API, but there are no methods like "visit",
"click_link", & co. visit() is defined in Webrat::Session, but how
can it be called in this example without it's invocation being
qualified as in Webrat::Session.visit()? What am I missing here?

Zach Church

unread,
Sep 27, 2009, 10:46:20 PM9/27/09
to rubyd...@googlegroups.com
hey Isiden,

class SignupTest < ActionController::IntegrationTest

 def test_trial_account_sign_up
   visit home_path
   click_link "Sign up"
   fill_in "Email", :with => "go...@example.com"
   select "Free account"
   click_button "Register"
 end
end

These methods are not documented in Rails's API because they don't come with Rails; they are only available when you also insert the example code below that:

require "webrat"

Webrat.configure do |config|
  config.mode = :rails
end

Whats confusing me is that ActionController::IntegrationTest is
defined in the Rails API, but there are no methods like "visit",
"click_link", & co.  visit() is defined in Webrat::Session, but how
can it be called in this example without it's invocation being
qualified as in Webrat::Session.visit()?  What am I missing here?

Check out this file to see how it's done:
Lines 6 and 7 make the methods from Webrat::Methods and Webrat::Matchers available from IntegrationTest.

The methods you are asking about are, from there, delegated to Webrat::Session, as seen here:


Hope this helps!

Zach

Mike Sassak

unread,
Sep 28, 2009, 12:19:15 PM9/28/09
to rubyd...@googlegroups.com

Hi Larry,

If you're looking to test non-Ruby websites with Webrat, have you looked Webrat's Mechanize support [0]? It doesn't support Javascript (yet), but it's quite useful for driving plain-old HTML websites written in any language.

Mike
 
[0] http://wiki.github.com/brynary/webrat/mechanize


 

lsiden

unread,
Sep 29, 2009, 1:00:51 AM9/29/09
to Detroit.rb
Thanks. I finally found this page that actually offers some
documentation on using Mechanize: http://mechanize.rubyforge.org/mechanize/GUIDE_rdoc.html

BTW - Is there a central place to look for docs on all this stuff?
When I installed mechanize w/ gem, command output said it was building
rDocs and ri, but when I enter "ri mechanize" at command line, it
returns "Nothing known about mechanize".

Next I want to figure out how to use this with rspec so that I can
start to develop tests.

I think I need to get a book. I think someone mentioned this one:
http://www.pragprog.com/titles/achbd/the-rspec-book Does anyone
second that recommendation? I want to make sure it's going to help
before I fork over $24 for the beta e-book.

On Sep 28, 12:19 pm, Mike Sassak <msas...@gmail.com> wrote:
> On Sun, Sep 27, 2009 at 10:15 PM, lsiden <lsi...@gmail.com> wrote:
>
> > Anybody use webrat?  I want to get started using Ruby to to test (non-
> > Ruby) websites I build.  The page
> >http://gitrdoc.com/brynary/webrat/tree/master
> > shows this example:
>
> > class SignupTest < ActionController::IntegrationTest
>
> >  def test_trial_account_sign_up
> >    visit home_path
> >    click_link "Sign up"
> >    fill_in "Email", :with => "g...@example.com"

Mike Sassak

unread,
Sep 29, 2009, 1:11:40 AM9/29/09
to rubyd...@googlegroups.com

The RSpec book is well worth it. Kent Beck also has an oldish book on test-driven development you may find helpful. It uses Java and jUnit, but the practices, especially the red/green/refactor loop, remain basically the same between TDD and BDD.

As for generated docs, gem serve --daemon is quite helpful.

On Sep 29, 2009 1:00 AM, "lsiden" <lsi...@gmail.com> wrote:


Thanks.  I finally found this page that actually offers some
documentation on using Mechanize: http://mechanize.rubyforge.org/mechanize/GUIDE_rdoc.html

BTW - Is there a central place to look for docs on all this stuff?
When I installed mechanize w/ gem, command output said it was building
rDocs and ri, but when I enter "ri mechanize" at command line, it
returns "Nothing known about mechanize".

Next I want to figure out how to use this with rspec so that I can
start to develop tests.

I think I need to get a book.  I think someone mentioned this one:
http://www.pragprog.com/titles/achbd/the-rspec-book  Does anyone
second that recommendation?  I want to make sure it's going to help
before I fork over $24 for the beta e-book.

On Sep 28, 12:19 pm, Mike Sassak <msas...@gmail.com> wrote:

> On Sun, Sep 27, 2009 at 10:15 PM, lsiden <lsi...@gmail.com> wrote: > > > Anybody use webrat?  I wa...

> >    fill_in "Email", :with => "g...@example.com"

> >    select "Free account" > >    click_button "Register" > >  end > > end > > > Whats confusing m...

Larry Siden

unread,
Sep 29, 2009, 9:15:52 AM9/29/09
to rubyd...@googlegroups.com

RubyGems Documentation Index

Summary

There are 21 gems installed:


Awesome!  Thanks!  :)



Larry Siden
http://umich.edu/~lsiden
734-926-9614
skype: lsiden

lsiden

unread,
Oct 4, 2009, 1:37:37 AM10/4/09
to Detroit.rb
Mike, when I try to run the script you pointed me to before at
http://wiki.github.com/brynary/webrat/mechanize (which I copied and
pasted as test.rb)

$ ruby -rubygems test.rb

it responds:
/usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in
`gem_original_require': no such file to load -- net/https (LoadError)

Is this example complete?

On Sep 29, 9:15 am, Larry Siden <lsi...@gmail.com> wrote:
> http://localhost:8808-->
>
> > RubyGems Documentation Index Summary
>
> > There are 21 gems installed:
>
> Awesome!  Thanks!  :)
>
> Larry Sidenhttp://umich.edu/~lsiden<http://umich.edu/%7Elsiden>
> 734-926-9614
> skype: lsiden
Reply all
Reply to author
Forward
0 new messages