[rspec-users] Symbols in strings out in stubbed response

David Chelimsky dchelimsky at gmail.com
Sat Oct 23 21:51:05 EDT 2010

On Oct 23, 2010, at 7:29 PM, Peter Havens wrote:

> On Oct 23, 1:40 pm, Katrina <katrina.o... at gmail.com> wrote:
>> [...]
>> It fails with the following:
>> expected {:total=>139 #...
>>        got {"total"=>139 #...
>> [...}
> I think the problem you're having is that you're expecting/stubbing
> symbols for your keys, but the keys for parameters are strings.

This hash wasn't a params hash - it was coming directly from a model, and then exposed to the view by Rails. The problem is that Rails converts hashes assigned to views into HashWithIndifferentAccess, which do not treat Symbols and Strings indifferently when comparing complete hashes, even though they let you access the keys indifferently. in Katrina's case, this would pass:

  assigns(:summary)[:total].should eq(139)
  assigns(:summary)[:submitted].should eq(97)
  assigns(:summary)[:published].should eq(82)
  assigns(:summary)[:removed].should eq(12)

Make sense?

More information about the rspec-users mailing list