views:

441

answers:

1

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

+1  A: 

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"

marcgg
do you know if its possible to make the post pass it in as a symbol as I want to create the hash from a machinist blueprint and they return symbols not strings
ssmithstone
I don't think you can do such a thing, it's just the way POST works
marcgg