Class: GrapeEntityMatchers::RepresentMatcher::RepresentMatcher
- Inherits:
-
Object
- Object
- GrapeEntityMatchers::RepresentMatcher::RepresentMatcher
- Defined in:
- lib/grape_entity_matchers/represent_matcher.rb
Instance Method Summary collapse
- #as(representation) ⇒ Object
- #description ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(representable) ⇒ RepresentMatcher
constructor
A new instance of RepresentMatcher.
- #matches?(subject) ⇒ Boolean
- #negative_failure_message ⇒ Object
- #using(other_entity) ⇒ Object
- #when(conditions) ⇒ Object
- #with_root(root) ⇒ Object
Constructor Details
#initialize(representable) ⇒ RepresentMatcher
Returns a new instance of RepresentMatcher.
11 12 13 14 |
# File 'lib/grape_entity_matchers/represent_matcher.rb', line 11 def initialize(representable) @expected_representable = representable RSpec::Mocks::setup end |
Instance Method Details
#as(representation) ⇒ Object
22 23 24 25 |
# File 'lib/grape_entity_matchers/represent_matcher.rb', line 22 def as(representation) @actual_representation = representation self end |
#description ⇒ Object
74 75 76 |
# File 'lib/grape_entity_matchers/represent_matcher.rb', line 74 def description "Ensures that #{@subject} properly obtains the value of #{@expected_representable} from a mock class." end |
#failure_message ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/grape_entity_matchers/represent_matcher.rb', line 46 def # why did it fail??? # 3 options, exposure, object not called, value not returned. # TODO: fix this #"Expected #{@expected_representable} to be called on mock, but it wasn't: #{@subject.exposures[@expected_representable]}" = "" << "#{@subject} didn't expose #{@expected_representable} as expected: #{@subject.exposures[@expected_representable]}" unless verify_exposure << "#{@subject} didn't call the method #{@actual_representation || @expected_representable} to get #{@expected_representable} from the test class.\n" unless check_methods << "#{@subject} didn't return the correct value for #{@expected_representable}. (#{@serialized_hash[@actual_representation || @expected_representable] } != #{@represented_attribute || :value})" unless check_value end |
#failure_message_when_negated ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/grape_entity_matchers/represent_matcher.rb', line 58 def = "" << "Didn't expect #{@subject} to expose #{@expected_representable} correctly: #{@subject.exposures[@expected_representable]} \n" if verify_exposure << "Didn't expect #{@subject} to call #{@actual_representation || @expected_representable} to get #{@expected_representable} from the test class.\n" if check_methods << "Didn't expect #{@subject} to return the correct value for #{@expected_representable}. (#{@serialized_hash[@actual_representation || @expected_representable] } != #{@represented_attribute || :value})" if check_value end |
#matches?(subject) ⇒ Boolean
16 17 18 19 20 |
# File 'lib/grape_entity_matchers/represent_matcher.rb', line 16 def matches?(subject) @subject = subject check_methods && verify_exposure && check_value end |
#negative_failure_message ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/grape_entity_matchers/represent_matcher.rb', line 66 def = "" << "Didn't expect #{@subject} to expose #{@expected_representable} correctly: #{@subject.exposures[@expected_representable]} \n" if verify_exposure << "Didn't expect #{@subject} to call #{@actual_representation || @expected_representable} to get #{@expected_representable} from the test class.\n" if check_methods << "Didn't expect #{@subject} to return the correct value for #{@expected_representable}. (#{@serialized_hash[@actual_representation || @expected_representable] } != #{@represented_attribute || :value})" if check_value end |
#using(other_entity) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/grape_entity_matchers/represent_matcher.rb', line 32 def using(other_entity) @other_entity = other_entity @represented_attribute = double("RepresetedAttribute") @other_entity.exposures.keys.each do |key| allow(@represented_attribute ).to receive(key).and_return( @other_entity.exposures[key].nil? ? :value : nil) end self end |
#when(conditions) ⇒ Object
27 28 29 30 |
# File 'lib/grape_entity_matchers/represent_matcher.rb', line 27 def when(conditions) @conditions = conditions self end |