Class: ActiveOperation::Matcher::UtilizeOperation::Matcher

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*composite_operations) ⇒ Matcher

Returns a new instance of Matcher.



33
34
35
# File 'lib/active_operation/matcher/utilize_operation.rb', line 33

def initialize(*composite_operations)
  @composite_operations = composite_operations.flatten
end

Instance Attribute Details

#composite_operationsObject (readonly)

Returns the value of attribute composite_operations.



29
30
31
# File 'lib/active_operation/matcher/utilize_operation.rb', line 29

def composite_operations
  @composite_operations
end

#tested_instanceObject (readonly)

Returns the value of attribute tested_instance.



31
32
33
# File 'lib/active_operation/matcher/utilize_operation.rb', line 31

def tested_instance
  @tested_instance
end

#tested_operationObject (readonly)

Returns the value of attribute tested_operation.



30
31
32
# File 'lib/active_operation/matcher/utilize_operation.rb', line 30

def tested_operation
  @tested_operation
end

Instance Method Details

#descriptionObject



59
60
61
# File 'lib/active_operation/matcher/utilize_operation.rb', line 59

def description
  "utilize the following operations: #{composite_operations.map(&:to_s).join(', ')}"
end

#failure_messageObject



63
64
65
66
67
68
69
70
# File 'lib/active_operation/matcher/utilize_operation.rb', line 63

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



72
73
74
# File 'lib/active_operation/matcher/utilize_operation.rb', line 72

def failure_message_when_negated
  "Unexpected operation utilization"
end

#matches?(class_or_instance) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/active_operation/matcher/utilize_operation.rb', line 37

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(Base).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