Permalink
Browse files

Merge pull request #7 from chendry/master

Fix for AssignToMatcher failure message when object is of the wrong kind.
  • Loading branch information...
2 parents 8cc8592 + de11b4b commit 224f2e5a70bf10718dff40e2021741c1279f600e @jasonm jasonm committed May 20, 2011
@@ -82,8 +82,8 @@ def kind_of_expected_class?
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
@@ -2,6 +2,18 @@
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' }

0 comments on commit 224f2e5

Please sign in to comment.