Sha256: 066ba4169b3b208f16c8b2b8a51ae86f760e87d64728dbd5a23978e4fc7c1f7e

Contents?: true

Size: 1.08 KB

Versions: 33

Compression:

Stored size: 1.08 KB

Contents

class RecordedEvent
  attr_reader :name, :data

  def initialize(name, data)
    @name = name.to_s
    @data = data
  end

  def inspect
    "<Event:#{name} #{inspect_data}>"
  end

  def ==(other)
    name == other.name && data == other.data
  end

  private

  def inspect_data
    data.inject([]) { |result, (key, value)|
      result << "#{key.inspect} => #{value.inspect.slice(0, 20)}"
    }.join(", ")
  end
end

class RecordingObserver
  attr_reader :events

  def initialize
    @events = []
  end

  def method_missing(name, data)
    @events << RecordedEvent.new(name, data)
  end
end

RSpec::Matchers.define :notify_observers do |event_name, data|
  match do |ignored_subject|
    @event = RecordedEvent.new(event_name, data)
    recorder.events.should include(@event)
  end

  failure_message do
    "Expected event:\n#{@event.inspect}\n\nGot events:\n#{recorder.events.map(&:inspect).join("\n")}"
  end

  def recorder
    Saucy::Configuration.observers.last
  end
end

RSpec.configure do |config|
  config.before do
    Saucy::Configuration.observers = [RecordingObserver.new]
  end
end

Version data entries

33 entries across 33 versions & 2 rubygems

Version Path
saasy-0.0.2.alpha3 spec/support/notifications.rb
saasy-0.0.2.alpha2 spec/support/notifications.rb
saasy-0.0.2.alpha1 spec/support/notifications.rb
saucy-0.8.5 spec/support/notifications.rb
saucy-0.8.4 spec/support/notifications.rb
saucy-0.8.3 spec/support/notifications.rb
saasy-0.0.1 spec/support/notifications.rb
saucy-0.8.2 spec/support/notifications.rb
saucy-0.8.1 spec/support/notifications.rb
saucy-0.8.0 spec/support/notifications.rb
saucy-0.7.3 spec/support/notifications.rb
saucy-0.7.2 spec/support/notifications.rb
saucy-0.7.1 spec/support/notifications.rb
saucy-0.7.0 spec/support/notifications.rb
saucy-0.6.1 spec/support/notifications.rb
saucy-0.6.0 spec/support/notifications.rb
saucy-0.5.5 spec/support/notifications.rb
saucy-0.5.4 spec/support/notifications.rb
saucy-0.5.3 spec/support/notifications.rb
saucy-0.5.2 spec/support/notifications.rb