Permalink
Browse files

Merge pull request #184 from mortice/implicit-docstring-for-instance-…

…of-matcher

Fix generated docstring for BeAnInstanceOf when Class#inspect changed
  • Loading branch information...
2 parents e2a9e3f + 071710a commit d5d073ee73fa3820a9dc4672995a560c85aa6ce3 @myronmarston myronmarston committed Oct 27, 2012
Showing with 23 additions and 2 deletions.
  1. +4 −0 lib/rspec/matchers/built_in/be_instance_of.rb
  2. +19 −2 spec/rspec/matchers/be_instance_of_spec.rb
@@ -5,6 +5,10 @@ class BeAnInstanceOf < BaseMatcher
def match(expected, actual)
actual.instance_of? expected
end
+
+ def description
+ "be an instance of #{expected}"
+ end
end
end
end
@@ -25,10 +25,27 @@ module Matchers
matcher.matches?(Numeric)
matcher.description.should == "be an instance of Fixnum"
end
+
+ context "when expected provides an expanded inspect, e.g. AR::Base" do
+ let(:user_klass) do
+ Class.new do
+ def self.inspect
+ "User(id: integer, name: string)"
+ end
+ end
+ end
+
+ before { stub_const("User", user_klass) }
+
+ it "provides a description including only the class name" do
+ matcher = be_an_instance_of(User)
+ matcher.description.should == "be an instance of User"
+ end
+ end
end
-
+
describe "actual.should_not #{method}(expected)" do
-
+
it "fails with failure message for should_not if actual is instance of expected class" do
lambda { "foo".should_not send(method, String) }.should fail_with(%Q{expected "foo" not to be an instance of String})
end

0 comments on commit d5d073e

Please sign in to comment.