class ActiveOperation::Matcher::UtilizeOperation::Matcher

Attributes

composite_operations[R]
tested_instance[R]
tested_operation[R]

Public Class Methods

new(*composite_operations) click to toggle source
# File lib/active_operation/matcher/utilize_operation.rb, line 33
def initialize(*composite_operations)
  @composite_operations = composite_operations.flatten
end

Public Instance Methods

description() click to toggle source
# File lib/active_operation/matcher/utilize_operation.rb, line 59
def description
  "utilize the following operations: #{composite_operations.map(&:to_s).join(', ')}"
end
failure_message() click to toggle source
# 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_negated() click to toggle source
# File lib/active_operation/matcher/utilize_operation.rb, line 72
def failure_message_when_negated
  "Unexpected operation utilization"
end
Also aliased as: negative_failure_message
matches?(class_or_instance) click to toggle source
# 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
negative_failure_message()