[rspec-users] AmbiguousReturnError

barunio barunio at gmail.com
Sun Mar 14 18:45:59 EDT 2010


Ah, of course. Thanks, David, this works.

On Mar 14, 4:11 pm, David Chelimsky <dchelim... at gmail.com> wrote:
> On Mar 14, 2010, at 2:20 PM, barunio wrote:
>
> > I'm trying to use RSpec to test some screen-scraping code.  Because I
> > don't want to hit external websites for my tests, I'm stubbing out the
> > html I expect to receive, and trying to focus my tests on making sure
> > the code is parsing the html correctly, and submitting the correct
> > values when requesting external pages.
>
> > However, I'm running into a problem.  The following code causes RSpec
> > to raise a "Spec::Mocks::AmbiguousReturnError" exception:
>
> > @agent.should_receive(:submit) do |form, form_button|
> >  form.class.should == Mechanize::Form
> >  form.username.should == 'username'
> >  form.password.should == 'password'
> > end.and_return(@bad_login_page)
>
> When you pass a block to should_receive or stub, rspec wants to return the value returned by the block:
>
> @agent.should_receive(:submit) do |form, form_button|
>   form.class.should == Mechanize::Form
>   form.username.should == 'username'
>   form.password.should == 'password'
>   @bad_login_page
> end
>
> HTH,
> David
>
>
>
> > Am I doing something incorrectly here, or is the problem just that
> > RSpec doesn't like for explicit return values to be specified when a
> > block is supplied to the message expectation?  If it is the latter,
> > what would be the recommendation for how to appropriately write this
> > spec?
>
> > Thanks.
>
> _______________________________________________
> rspec-users mailing list
> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users


More information about the rspec-users mailing list