Class: ComposableOperations::Matcher::UtilizeOperation::Matcher
- Inherits:
-
Object
- Object
- ComposableOperations::Matcher::UtilizeOperation::Matcher
- Includes:
- RSpec::Mocks::ExampleMethods
- Defined in:
- lib/composable_operations/matcher/utilize_operation.rb
Instance Attribute Summary collapse
-
#composite_operations ⇒ Object
readonly
Returns the value of attribute composite_operations.
-
#tested_instance ⇒ Object
readonly
Returns the value of attribute tested_instance.
-
#tested_operation ⇒ Object
readonly
Returns the value of attribute tested_operation.
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object (also: #negative_failure_message)
-
#initialize(*composite_operations) ⇒ Matcher
constructor
A new instance of Matcher.
- #matches?(class_or_instance) ⇒ Boolean
Constructor Details
#initialize(*composite_operations) ⇒ Matcher
Returns a new instance of Matcher.
37 38 39 |
# File 'lib/composable_operations/matcher/utilize_operation.rb', line 37 def initialize(*composite_operations) @composite_operations = composite_operations.flatten end |
Instance Attribute Details
#composite_operations ⇒ Object (readonly)
Returns the value of attribute composite_operations.
33 34 35 |
# File 'lib/composable_operations/matcher/utilize_operation.rb', line 33 def composite_operations @composite_operations end |
#tested_instance ⇒ Object (readonly)
Returns the value of attribute tested_instance.
35 36 37 |
# File 'lib/composable_operations/matcher/utilize_operation.rb', line 35 def tested_instance @tested_instance end |
#tested_operation ⇒ Object (readonly)
Returns the value of attribute tested_operation.
34 35 36 |
# File 'lib/composable_operations/matcher/utilize_operation.rb', line 34 def tested_operation @tested_operation end |
Instance Method Details
#description ⇒ Object
63 64 65 |
# File 'lib/composable_operations/matcher/utilize_operation.rb', line 63 def description "utilize the following operations: #{composite_operations.map(&:to_s).join(', ')}" end |
#failure_message ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/composable_operations/matcher/utilize_operation.rb', line 67 def expected_but_not_used = composite_operations - tested_operation.operations used_but_not_exptected = tested_operation.operations - composite_operations = ["Unexpected operation utilization:"] << "Expected: #{expected_but_not_used.join(', ')}" unless expected_but_not_used.empty? << "Not expected: #{used_but_not_exptected.join(', ')}" unless used_but_not_exptected.empty? .join("\n\t") end |
#failure_message_when_negated ⇒ Object Also known as: negative_failure_message
76 77 78 |
# File 'lib/composable_operations/matcher/utilize_operation.rb', line 76 def "Unexpected operation utilization" end |
#matches?(class_or_instance) ⇒ Boolean
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/composable_operations/matcher/utilize_operation.rb', line 41 def matches?(class_or_instance) if class_or_instance.is_a?(Class) @tested_operation = class_or_instance @tested_instance = class_or_instance.new else @tested_operation = class_or_instance.class @tested_instance = class_or_instance end allow(Operation).to receive(:new).and_return(DummyOperation.new) composite_operations.each do |composite_operation| dummy_operation = DummyOperation.new expect(dummy_operation).to receive(:perform).and_call_original expect(composite_operation).to receive(:new).and_return(dummy_operation) end allow(tested_instance).to receive(:prepare).and_return(true) allow(tested_instance).to receive(:finalize).and_return(true) tested_instance.perform tested_operation.operations == composite_operations end |