Sha256: 59b0af61ce53515080e9dd599477935e84401425ca6e533fb97800c8a40bf676
Contents?: true
Size: 1.26 KB
Versions: 9
Compression:
Stored size: 1.26 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 def self.instance @@instance ||= self.new end attr_accessor :events def initialize @events = [] end def respond_to?(message) true 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 RecordingObserver.instance end end RSpec.configure do |config| config.before do Saucy::Notifications.clear_observers Saucy::Notifications.register_observer(RecordingObserver.instance) RecordingObserver.instance.events = [] end end
Version data entries
9 entries across 9 versions & 1 rubygems