Class: Fixturama::Changes::Chain

Inherits:
Base
  • Object
show all
Defined in:
lib/fixturama/changes/chain.rb,
lib/fixturama/changes/chain/actions.rb,
lib/fixturama/changes/chain/arguments.rb,
lib/fixturama/changes/chain/raise_action.rb,
lib/fixturama/changes/chain/return_action.rb

Overview

Stub a chain of messages

Defined Under Namespace

Classes: Actions, Arguments, RaiseAction, ReturnAction

Instance Attribute Summary

Attributes inherited from Base

#key The key identifier of the change

Instance Method Summary collapse

Instance Method Details

#call(example) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/fixturama/changes/chain.rb', line 22

def call(example)
  call_action = example.send(:receive_message_chain, *@messages) do |*real|
    action = arguments.find { |expected| expected.match?(*real) }
    action ? action.call : raise("Unexpected arguments: #{real}")
  end

  example.send(:allow, @receiver).to call_action
end

#keyObject



12
13
14
# File 'lib/fixturama/changes/chain.rb', line 12

def key
  @key ||= ["chain", @receiver.name, *@messages].join(".")
end

#merge(other) ⇒ Object



16
17
18
19
20
# File 'lib/fixturama/changes/chain.rb', line 16

def merge(other)
  return self unless other.class == self.class && other.key == key

  tap { @arguments = (other.arguments | arguments).sort_by(&:order) }
end