[rspec-users] Odd parameter munging with with()

David Chelimsky dchelimsky at gmail.com
Mon Feb 19 19:58:59 EST 2007


On 2/19/07, James Hughes <hughes.james at gmail.com> wrote:
> On 2/15/07, Jerry West <jerry.west at ntlworld.com> wrote:
> >
> >  It might be worth filing an RFE on this as it's counter-intuitive and
> > likely to bite others as well
>
> Hello again,
>
> In trying to create some simple code that would reproduce this without
> all the rails dependencies for an RFE, I came up with this:
>
> class Test
>   def Test.amethod params
>     true
>   end
> end
> context "passing a hash to #with" do
>   specify "should pass a hash to #with" do
>     @params = { :param1 => "foo",
>       :param2 => "bar"}
>     Test.should_receive(:amethod).with(@params).and_return(true)
>     Test.amethod @params
>   end
> end
>
> I thought this was conceptually the same as my failing spec from the
> original post, but obviously it's not, as it passes. Can anyone
> explain what the difference is?

The difference that I see is that the new example passes @params
directly to Test.amethod, whereas the earlier example uses "post
:update". So I'm guessing that the problem is related specifically to
how "post :update" packages up the arguments to pass to the model.

WDYT?

>
> thanks,
> James
>
> >  James Hughes wrote:
> >
> > Hi,
> >
> > I have this setup block:
> >
> >  setup do
> >  session[:login] = 'jhughes'
> >  @user = mock("user")
> >  User.stub!(:find).and_return(@user)
> >  @params = {:cn => "Bilbo Baggins",
> >  :telephoneNumber => "416-277-4418",
> >  :mail => "bilbo at baggins.com"}
> >  end
> >
> > And then this spec:
> >
> >  specify "should update and save the attributes for user" do
> > @user.should_receive(:update_attributes).with(@params).and_return(true)
> >  post :update, :id => "jhughes", :user => @params
> >  end
> >
> > This fails like this:
> >
> > Mock 'user' expected :update_attributes with ([:telephoneNumber,
> > "416-277-4418"], [:mail, "bilbo at baggins.com"], [:cn, "Bilbo Baggins"])
> > but received it with ({"cn"=>"Bilbo Baggins",
> > "telephoneNumber"=>"416-277-4418",
> > "mail"=>"bilbo at baggins.com"})
> >
> > Puzzling, especially since inspecting the @params variable just before
> > the should_receive shows the expected hash.
> >
> > What am I doing wrong?
> >
> > James
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>


More information about the rspec-users mailing list