Merge pull request #7 from chendry/master

Fix for AssignToMatcher failure message when object is of the wrong kind.
This commit is contained in:
Jason Morrison 2011-05-20 07:34:17 -07:00
commit 224f2e5a70
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' }