Skip to content

Commit

Permalink
Add support for instance_of argument matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
wata727 committed May 3, 2021
1 parent 3996ab6 commit c98b483
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
6 changes: 6 additions & 0 deletions lib/super_diff/rspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ def self.an_instance_of_something?(value)
value.base_matcher.is_a?(::RSpec::Matchers::BuiltIn::BeAnInstanceOf)
end

# HINT: `an_instance_of` is a matcher in the rspec-expectations gem.
# `instance_of` is an argument matcher in the rspec-mocks gem.
def self.instance_of_something?(value)
value.is_a?(::RSpec::Mocks::ArgumentMatchers::InstanceOf)
end

def self.a_value_within_something?(value)
fuzzy_object?(value) &&
value.base_matcher.is_a?(::RSpec::Matchers::BuiltIn::BeWithin)
Expand Down
11 changes: 8 additions & 3 deletions lib/super_diff/rspec/object_inspection/inspectors/instance_of.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@ module ObjectInspection
module Inspectors
class InstanceOf < SuperDiff::ObjectInspection::Inspectors::Base
def self.applies_to?(value)
SuperDiff::RSpec.an_instance_of_something?(value)
SuperDiff::RSpec.an_instance_of_something?(value) || SuperDiff::RSpec.instance_of_something?(value)
end

protected

def inspection_tree
SuperDiff::ObjectInspection::InspectionTree.new do
add_text do |aliased_matcher|
"#<an instance of #{aliased_matcher.expected}>"
add_text do |value|
klass = if SuperDiff::RSpec.an_instance_of_something?(value)
value.expected
else
value.instance_variable_get(:@klass)
end
"#<an instance of #{klass}>"
end
end
end
Expand Down

0 comments on commit c98b483

Please sign in to comment.