[rspec-users] Using Mechanize in Story Step Implementations

David Chelimsky dchelimsky at gmail.com
Wed Oct 24 16:50:38 EDT 2007


On 10/24/07, James Hughes <hughes.james at gmail.com> wrote:
> On 10/24/07, Andy Watts <andywatts at yahoo.com> wrote:
> >
> > Hi,
> >
> > Thought this might be of interest story writers.
> > The mechanize plugin seems to play nice with RSpec.
> > The following mix of methods seems to work just fine.
> > I especially like the helpers for populating forms.
> >
> > agent = WWW::Mechanize.new
> > page = agent.get 'http://www.gmail.com'
> > page.should have_tag('form', :count => 1)
> > form = page.forms.first
> > form.email = 'd at d.com'
> > page = agent.submit form
> >
> > Could make for some nice step implementations.
> > Almost seems too easy, is there anything that mechanize will break?
>
> Can't see why this wouldn't work, and it might be useful for setting
> up more complex interactions, but for this simple case why not just do
> something like:
>
> post '/form_action', {:email => 'd at d.com'}

Because even if the form has no email field, as long as the model
supports it, your example will pass. Andy's example specifies that
there should be an email field in the form, in addition to specifying
that the model should be able to handle it.

Cheers,
David


More information about the rspec-users mailing list