In my controller spec I am doing this:
it "should create new message" do
Client.should_receive(:create).with({:title => 'Mr'})
post 'create' , :client => {:title => "Mr" }
end
... and in my controller I am doing ...
def create
client = Client.create(params[:client])
end
However this is failing with the following error message :
expected: ({:title=>"Mr"})
got: ({"title"=>"Mr"})
I'm wondering why this is happening and how to get it to work
It's because you are passing a symbol and not a string. This should fix it :
it "should create new message" do
Client.should_receive(:create).with({:title => 'Mr'})
post 'create' , :client => {"title" => "Mr" }
end
Here's a blogpost about it: "Understanding Ruby Symbols"
@ssmithone you could use ActiveSupport::HashWithIndifferentAccess to pass params as symbols instead of strings. This should work:
it "should create new message" do
Client.should_receive(:create).with({:title => 'Mr'}.with_indifferent_access)
post 'create', :client => {:title => "Mr"}
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With