Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Assign_to should check for nil #109

ropiku opened this Issue May 15, 2012 · 2 comments


None yet
3 participants

ropiku commented May 15, 2012

In case your controller does set a variable to nil then should_not assign_to :variable raises Didn't expect action to assign a value for @variable, but it was assigned to nil.

This is because https://github.com/thoughtbot/shoulda-matchers/blob/master/lib/shoulda/matchers/action_controller/assign_to_matcher.rb#L67 checks if the variable is defined, not its value.

I would expect that assigning nil should be the same as not assigning the variable.


mike-burns commented Jul 9, 2012

Assigning something to nil certainly does assign to it, but I can see how this is of little practical value for this specific case. Is there a better name for that matcher?

Though, that matcher itself is of questionable value unless #with is also used. @ropiku , how about we make it an error to use #assign_to without specifying #with or #with_kind_of?


drapergeek commented Oct 5, 2012

This matcher will be deprecated in the next version of shoulda-matchers.

@drapergeek drapergeek closed this Oct 5, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment