Sha256: 6e0746badf062bbae39720691a4caeb2245ec2b44b878409c3ad883c3d85ae3c

Contents?: true

Size: 842 Bytes

Versions: 6

Compression:

Stored size: 842 Bytes

Contents

module ClassMethods

  require "rspec/mocks/standalone"
  require "rspec/expectations"

    include RSpec::Matchers

  def expected
    @expected ||= {}
  end

  def actual
    @actual ||= {}
  end

  def should_receive_message(message,name=self.name, &blk)
    blk.call
    called = false
    10.times do
      if actual.has_key?(name)
        called = true
        break
      end
      sleep 0.020
    end
    expect(actual[name]).to eq(message)
    actual.delete(name)
  end

end

module InstanceMethods

    def onReceive(message)
      on_receive(message)
      self.class.actual[get_self.path.name] = message
    end

end
result = []
ObjectSpace.each_object(::Class) {|klass| result << klass if klass < GameMachine::Actor::Base }
result.each do |klass|
  klass.send(:include, InstanceMethods)
  klass.send(:extend, ClassMethods)
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
game_machine-1.0.4 spec/message_expectations.rb
game_machine-1.0.2 spec/message_expectations.rb
game_machine-0.0.11 spec/message_expectations.rb
game_machine-0.0.10 spec/message_expectations.rb
game_machine-0.0.9 spec/message_expectations.rb
game_machine-0.0.8 spec/message_expectations.rb