Sha256: a22aaf581fb358cff72d7c8ff4c72364a380aa98cd84c98b6e6de37f16887bc0

Contents?: true

Size: 644 Bytes

Versions: 31

Compression:

Stored size: 644 Bytes

Contents

Spec::Matchers.define(:run_callbacks) do |*callbacks|
  match do |instance|
    instance.history == expand_callbacks(callbacks)
  end
  
  failure_message_for_should do |instance|
    "expected #{instance.inspect} to run callbacks #{callbacks.inspect} but got #{compress_callbacks(instance.history).inspect}"
  end
  
  def compress_callbacks(callbacks)
    callbacks.inject([]) { |result, (callback, type)|
      result << callback if type == :string
      result
    }
  end
  
  def expand_callbacks(callbacks)
    callbacks.map { |c| [ [c, :string], [c, :proc], [c, :object], [c, :block] ] }.inject([]) { |result, c| result + c }
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
mongomodel-0.3.3 spec/support/matchers/run_callbacks.rb
mongomodel-0.3.2 spec/support/matchers/run_callbacks.rb
mongomodel-0.3.1 spec/support/matchers/run_callbacks.rb
mongomodel-0.3.0 spec/support/matchers/run_callbacks.rb
mongomodel-0.2.20 spec/support/matchers/run_callbacks.rb
mongomodel-0.2.19 spec/support/matchers/run_callbacks.rb
mongomodel-0.2.18 spec/support/matchers/run_callbacks.rb
mongomodel-0.2.17 spec/support/matchers/run_callbacks.rb
mongomodel-0.2.16 spec/support/matchers/run_callbacks.rb
mongomodel-0.2.15 spec/support/matchers/run_callbacks.rb
mongomodel-0.2.14 spec/support/matchers/run_callbacks.rb
mongomodel-0.2.13 spec/support/matchers/run_callbacks.rb
mongomodel-0.2.12 spec/support/matchers/run_callbacks.rb
mongomodel-0.2.11 spec/support/matchers/run_callbacks.rb
mongomodel-0.2.10 spec/support/matchers/run_callbacks.rb
mongomodel-0.2.9 spec/support/matchers/run_callbacks.rb
mongomodel-0.2.8 spec/support/matchers/run_callbacks.rb
mongomodel-0.2.7 spec/support/matchers/run_callbacks.rb
mongomodel-0.2.6 spec/support/matchers/run_callbacks.rb
mongomodel-0.2.5 spec/support/matchers/run_callbacks.rb