Class: ComposableOperations::Matcher::UtilizeOperation::Matcher

Inherits:
Object
  • Object
show all
Includes:
RSpec::Mocks::ExampleMethods
Defined in:
lib/composable_operations/matcher/utilize_operation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_operationsObject (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_instanceObject (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_operationObject (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

#descriptionObject



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_messageObject



67
68
69
70
71
72
73
74
# File 'lib/composable_operations/matcher/utilize_operation.rb', line 67

def failure_message
  expected_but_not_used = composite_operations - tested_operation.operations
  used_but_not_exptected = tested_operation.operations - composite_operations
  message = ["Unexpected operation utilization:"]
  message << "Expected: #{expected_but_not_used.join(', ')}" unless expected_but_not_used.empty?
  message << "Not expected: #{used_but_not_exptected.join(', ')}" unless used_but_not_exptected.empty?
  message.join("\n\t")
end

#failure_message_when_negatedObject Also known as: negative_failure_message



76
77
78
# File 'lib/composable_operations/matcher/utilize_operation.rb', line 76

def failure_message_when_negated
  "Unexpected operation utilization"
end

#matches?(class_or_instance) ⇒ Boolean

Returns:

  • (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