describe ChannelsController, “GET edit” do
it “assigns the greetings summary” do
summary = {:total => 139, :submitted => 97, :published =>
82, :removed => 12}
Greeting.stub(:summary).and_return summary
get :index
assigns(:summary).should eq(summary)
end
end
It fails with the following:
expected {:total=>139, :submitted=>97, :published=>82, :removed=>12}
got {“total”=>139, “submitted”=>97, “published”=>82,
“removed”=>12}
end @summary = Greeting.summary
end
The definition of self.summary shouldn’t matter here since it’s being
stubbed in the example.
I expected this example to pass,
I would have too, but it looks like Rails is converting hashes that get
assigned to views to HashWithIndifferentAccess, which only looks at
Strings in its implementation of ==.
The problem here is that it would be unwise for
HashWithIndifferentAccess to implement == any differently, because you’d
end up with surprising results (a == b would pass, but b == a would
fail).
So you have to assume that the keys are Strings regardless of what you
set in the example. Therefore, I’d recommend setting Strings in the
example in order to keep sane
[…]
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:
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.
(snip)
Make sense?
Ah, sanity returns. Thanks
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.