From de11b4b59bed0cdd79e4b958f378d9d3c3c1d598 Mon Sep 17 00:00:00 2001 From: Chad Hendry Date: Wed, 30 Mar 2011 17:30:23 -0500 Subject: [PATCH] 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. --- .../matchers/action_controller/assign_to_matcher.rb | 4 ++-- .../action_controller/assign_to_matcher_spec.rb | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/shoulda/matchers/action_controller/assign_to_matcher.rb b/lib/shoulda/matchers/action_controller/assign_to_matcher.rb index 705cdf7b..9662a0e4 100644 --- a/lib/shoulda/matchers/action_controller/assign_to_matcher.rb +++ b/lib/shoulda/matchers/action_controller/assign_to_matcher.rb @@ -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 diff --git a/spec/shoulda/action_controller/assign_to_matcher_spec.rb b/spec/shoulda/action_controller/assign_to_matcher_spec.rb index 87bd8a21..22a894e9 100644 --- a/spec/shoulda/action_controller/assign_to_matcher_spec.rb +++ b/spec/shoulda/action_controller/assign_to_matcher_spec.rb @@ -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' }