Class: Surrogate::RSpec::SubstitutionMatcher
- Inherits:
-
Object
- Object
- Surrogate::RSpec::SubstitutionMatcher
- Defined in:
- lib/surrogate/rspec/substitution_matcher.rb
Instance Method Summary collapse
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(original_class, options = {}) ⇒ SubstitutionMatcher
constructor
A new instance of SubstitutionMatcher.
- #matches?(surrogate) ⇒ Boolean
Constructor Details
#initialize(original_class, options = {}) ⇒ SubstitutionMatcher
Returns a new instance of SubstitutionMatcher.
4 5 6 7 8 9 10 |
# File 'lib/surrogate/rspec/substitution_matcher.rb', line 4 def initialize(original_class, ={}) @original_class = original_class @comparison = nil @subset_only = .fetch :subset, false @types = .fetch :types, true @names = .fetch :names, false end |
Instance Method Details
#failure_message ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/surrogate/rspec/substitution_matcher.rb', line 18 def extra_instance_methods = @comparison[:instance][:not_on_actual ].to_a # these come in as sets extra_class_methods = @comparison[:class ][:not_on_actual ].to_a missing_instance_methods = @comparison[:instance][:not_on_surrogate].to_a missing_class_methods = @comparison[:class ][:not_on_surrogate].to_a instance_type_mismatch = @comparison[:instance][:types ] class_type_mismatch = @comparison[:class ][:types ] instance_name_mismatch = @comparison[:instance][:names ] class_name_mismatch = @comparison[:class ][:names ] differences = [] differences << "has extra instance methods: #{extra_instance_methods.inspect}" if extra_instance_methods.any? differences << "has extra class methods: #{extra_class_methods.inspect}" if extra_class_methods.any? differences << "is missing instance methods: #{missing_instance_methods}" if !@subset_only && missing_instance_methods.any? differences << "is missing class methods: #{missing_class_methods}" if !@subset_only && missing_class_methods.any? if @types # this conditional is not tested, nor are these error messages instance_type_mismatch.each { |name, types| differences << "##{name} had types #{types.inspect}" } class_type_mismatch.each { |name, types| differences << ".#{name} had types #{types.inspect}" } end if @names # this conditional is not tested, nor are these error messages instance_name_mismatch.each { |method_name, param_names| differences << "##{method_name} had parameter names #{param_names.inspect}" } class_type_mismatch.each { |method_name, param_names| differences << ".#{method_name} had parameter names #{param_names.inspect}" } end "Was not substitutable because surrogate " << differences.join("\n") end |
#failure_message_when_negated ⇒ Object
47 48 49 |
# File 'lib/surrogate/rspec/substitution_matcher.rb', line 47 def "Should not have been substitute, but was" end |
#matches?(surrogate) ⇒ Boolean
12 13 14 15 |
# File 'lib/surrogate/rspec/substitution_matcher.rb', line 12 def matches?(surrogate) @comparison = ApiComparer.new(surrogate, @original_class).compare comparing_fields(@comparison, @subset_only, @types, @names).values.inject(:+).empty? end |