Skip to content

Instantly share code, notes, and snippets.

@sevenseacat
Created May 17, 2013 03:27
Show Gist options
  • Select an option

  • Save sevenseacat/5596719 to your computer and use it in GitHub Desktop.

Select an option

Save sevenseacat/5596719 to your computer and use it in GitHub Desktop.
RSpec::Matchers.define :assign_to do |variable|
chain :with do |value|
@value = value
end
match do |response|
if @value
assigns[variable] == @value
else
assigns.has_key?(variable)
end
end
failure_message_for_should do |model|
if @value
"Subject: @#{variable}
Expected: #{@value.inspect}
Actual: #{assigns[variable].inspect}"
else
"Subject: @#{variable}
Expected: anything
Actual: not set"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment