Hash / params causing errors

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=>“[email protected]”}) but
received it with ({“email”=>“[email protected]”})

Code is here: http://pastie.org/309263

Ramon T.

On Thu, Nov 6, 2008 at 9:53 PM, Ramon T. [email protected]

received it with ({“email”=>“[email protected]”})
expected {:email=>“[email protected]”}
got {“email”=>“[email protected]”}

Rails is converting what’s really passed (with a Symbol key) to a
String key. It’ll work if you expect the String instead.

A bit dryer:

@params = { “login” => “loginator”, “email” => “[email protected]” }


Ramon T.

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 => “[email protected]”, :save! => true)
@params = { :login => “loginator”, :email => “[email protected]” }

it “should create a new user from params” do
User.should_receive(:new).with({“login” => “loginator”, “email” =>
[email protected]”}).and_return(@user)

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs