Skip to content

Commit 2bce2b1

Browse files
wata727mcmire
authored andcommitted
Add support for instance_of argument matcher
1 parent 5027bd7 commit 2bce2b1

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

lib/super_diff/rspec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ def self.an_instance_of_something?(value)
6868
value.base_matcher.is_a?(::RSpec::Matchers::BuiltIn::BeAnInstanceOf)
6969
end
7070

71+
# HINT: `an_instance_of` is a matcher in the rspec-expectations gem.
72+
# `instance_of` is an argument matcher in the rspec-mocks gem.
73+
def self.instance_of_something?(value)
74+
value.is_a?(::RSpec::Mocks::ArgumentMatchers::InstanceOf)
75+
end
76+
7177
def self.a_value_within_something?(value)
7278
fuzzy_object?(value) &&
7379
value.base_matcher.is_a?(::RSpec::Matchers::BuiltIn::BeWithin)

lib/super_diff/rspec/object_inspection/inspectors/instance_of.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,20 @@ module ObjectInspection
44
module Inspectors
55
class InstanceOf < SuperDiff::ObjectInspection::Inspectors::Base
66
def self.applies_to?(value)
7-
SuperDiff::RSpec.an_instance_of_something?(value)
7+
SuperDiff::RSpec.an_instance_of_something?(value) || SuperDiff::RSpec.instance_of_something?(value)
88
end
99

1010
protected
1111

1212
def inspection_tree
1313
SuperDiff::ObjectInspection::InspectionTree.new do
14-
add_text do |aliased_matcher|
15-
"#<an instance of #{aliased_matcher.expected}>"
14+
add_text do |value|
15+
klass = if SuperDiff::RSpec.an_instance_of_something?(value)
16+
value.expected
17+
else
18+
value.instance_variable_get(:@klass)
19+
end
20+
"#<an instance of #{klass}>"
1621
end
1722
end
1823
end

0 commit comments

Comments
 (0)