Kostas
Kostas

Reputation: 8595

How to access the params variable in helper specs

I am writing some specs for helpers that check for values in the params variable. Until now I have been doing:

helper.stub!(:params).and_return(:user => {:username => "jack"})

The problem is that while the actual params Hash has string/symbol-agnostic keys and params[:user] == params["user"], my implementation does not and produces various failures where it should not.

Is there a way to set the proper (key-type agnostic) params variable in helper specs?

Upvotes: 2

Views: 1676

Answers (1)

nathanvda
nathanvda

Reputation: 50057

THe easiest way to do this is to use with_indifferent_access.

In your case :

helper.stub!(:params).and_return({:user => {:username => "jack"}}.with_indifferent_access)

Upvotes: 5

Related Questions