class Fixturama::Changes::Chain

@private Stub a chain of messages

Attributes

arguments[R]

Public Class Methods

new(**options) click to toggle source
   # File lib/fixturama/changes/chain.rb
37 def initialize(**options)
38   @receiver  = receiver_from(options)
39   @messages  = messages_from(options)
40   @arguments = [Arguments.new(options)]
41 end

Public Instance Methods

call(example) click to toggle source
   # File lib/fixturama/changes/chain.rb
22 def call(example)
23   call_action = example.send(:receive_message_chain, *@messages) do |*real|
24     action = arguments.find { |expected| expected.match?(*real) }
25     action ? action.call : raise("Unexpected arguments: #{real}")
26   end
27 
28   example.send(:allow, @receiver).to call_action
29 end
key() click to toggle source
   # File lib/fixturama/changes/chain.rb
12 def key
13   @key ||= ["chain", @receiver.name, *@messages].join(".")
14 end
merge(other) click to toggle source
   # File lib/fixturama/changes/chain.rb
16 def merge(other)
17   return self unless other.instance_of?(self.class) && other.key == key
18 
19   tap { @arguments = (other.arguments | arguments).sort_by(&:order) }
20 end

Private Instance Methods

messages_from(options) click to toggle source
   # File lib/fixturama/changes/chain.rb
53 def messages_from(options)
54   case value = options[:chain]
55   when Array  then value.map(&:to_sym)
56   when String then [value.to_sym]
57   when Symbol then value
58   else raise
59   end
60 rescue StandardError => err
61   raise Fixturama::FixtureError.new("a messages chain", options, err)
62 end
receiver_from(options) click to toggle source
   # File lib/fixturama/changes/chain.rb
43 def receiver_from(options)
44   case options.slice(:class, :object).keys
45   when %i[class]  then Kernel.const_get(options[:class])
46   when %i[object] then Object.send(:eval, options[:object])
47   else raise
48   end
49 rescue StandardError => err
50   raise Fixturama::FixtureError.new("a stabbed object", options, err)
51 end