Hey everyone,
I''m trying to spec a controller and I can''t seem to get a test
to pass
because rspec seems to see the difference between params I expect and
params that I pass. However, this comes from the same params
variable. What should I do to get this to work?
Spec::Mocks::MockExpectationError in ''UsersController handling POST
/users should create a new user from params''
Mock ''Class'' expected :new with ({:email=>"user at
email.com"}) but
received it with ({"email"=>"user at email.com"})
Code is here: http://pastie.org/309263
Thanks!
Ramon Tayag
On Thu, Nov 6, 2008 at 9:53 PM, Ramon Tayag <ramon.tayag at gmail.com> wrote:> Hey everyone, > > I''m trying to spec a controller and I can''t seem to get a test to pass > because rspec seems to see the difference between params I expect and > params that I pass. However, this comes from the same params > variable. What should I do to get this to work? > > Spec::Mocks::MockExpectationError in ''UsersController handling POST > /users should create a new user from params'' > Mock ''Class'' expected :new with ({:email=>"user at email.com"}) but > received it with ({"email"=>"user at email.com"})expected {:email=>"user at email.com"} got {"email"=>"user at email.com"} Rails is converting what''s really passed (with a Symbol key) to a String key. It''ll work if you expect the String instead.> > Code is here: http://pastie.org/309263 > > Thanks! > Ramon Tayag > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Thanks for you reply. With what you said I ended up doing this
before do
@user = mock_model(User, :to_param => "1", :login =>
"loginator",
:email => "user at email.com", :save! => true)
User.stub!(:new).and_return(@user)
@params = { :login => "loginator", :email => "user at
email.com" }
end
...
it "should create a new user from params" do
User.should_receive(:new).with({"login" =>
"loginator", "email" =>
"user at email.com"}).and_return(@user)
do_post
end
On Fri, Nov 7, 2008 at 11:03 AM, David Chelimsky <dchelimsky at gmail.com>
wrote:> On Thu, Nov 6, 2008 at 9:53 PM, Ramon Tayag <ramon.tayag at
gmail.com> wrote:
>> Hey everyone,
>>
>> I''m trying to spec a controller and I can''t seem to
get a test to pass
>> because rspec seems to see the difference between params I expect and
>> params that I pass. However, this comes from the same params
>> variable. What should I do to get this to work?
>>
>> Spec::Mocks::MockExpectationError in ''UsersController handling
POST
>> /users should create a new user from params''
>> Mock ''Class'' expected :new with
({:email=>"user at email.com"}) but
>> received it with ({"email"=>"user at
email.com"})
>
> expected {:email=>"user at email.com"}
> got {"email"=>"user at email.com"}
>
> Rails is converting what''s really passed (with a Symbol key) to a
> String key. It''ll work if you expect the String instead.
>
>>
>> Code is here: http://pastie.org/309263
>>
>> Thanks!
>> Ramon Tayag