Forum: Ruby on Rails When i use rspec(with built-in mock framework) ,errof occurs

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
C7b7ddf91aa9dd80fc7d65ec86ae0274?d=identicon&s=25 Guofeng Ma (guofeng)
on 2008-10-09 10:36
I use rspec_scaffold generate a example as below:

      it "should expose a newly created awarding_body as @awarding_body"
do
        AwardingBody.should_receive(:new).with(:these
                         =>'params').and_return(mock_awarding_body(:save
=> true))

         post :create,  :awarding_body => {:these => 'params'}
        assigns(:awarding_body).should == (mock_awarding_body)
      end


after execute the example , a error occurs as below :

Mock 'Class' expected :new with ({:these=>"params"}) but received it
with ({"the
se"=>"params"})
B14575f0ca69f10938fdd67e7156e0e1?d=identicon&s=25 Craig Demyanovich (Guest)
on 2008-10-09 13:45
(Received via mailing list)
Everything in the params hash is a string when it comes through the
controller. If you're passing the entire params hash to
AwardingBody.new,
the params hash looks like {'these' => 'params'}. Thus, if you change
your
expectation to {'these' => 'params'}, it will be satisfied.

In the future, it's probably best to post RSpec questions to the
rspec-users
mailing list: http://rubyforge.org/mailman/listinfo/rspec-users .

Regards,
Craig
This topic is locked and can not be replied to.