Fix for AssignToMatcher failure message

AssignToMatcher did not include the assigned object in the failure
message when the assigned object is of the wrong kind.
This commit is contained in:
Chad Hendry 2011-03-30 17:30:23 -05:00
parent dc769d3524
commit de11b4b59b
2 changed files with 14 additions and 2 deletions

View File

@ -82,8 +82,8 @@ module Shoulda # :nodoc:
else
@failure_message =
"Expected action to assign a kind of #{@expected_class} " <<
"for #{@variable}, but got #{@variable.inspect} " <<
"(#{@variable.class.name})"
"for #{@variable}, but got #{assigned_value.inspect} " <<
"(#{assigned_value.class.name})"
false
end
end

View File

@ -2,6 +2,18 @@ require 'spec_helper'
describe Shoulda::Matchers::ActionController::AssignToMatcher do
it "should include the actual class in the failure message" do
WrongClass = Class.new do
def to_s; "wrong class" end
end
controller = build_response { @var = WrongClass.new }
matcher = AssignToMatcher.new(:var).with_kind_of(Fixnum)
matcher.matches?(controller)
matcher.failure_message.should =~ /but got wrong class \(WrongClass\)$/
end
context "a controller that assigns to an instance variable" do
before do
@controller = build_response { @var = 'value' }