class Metacosm::TestHarness::GivenWhenThen

Public Instance Methods

expect_events(evts) click to toggle source
# File lib/metacosm/support/test_harness.rb, line 14
def expect_events(evts)
  @then_events = evts
  verify!
  self
end
expect_query(query, to_find:) click to toggle source
# File lib/metacosm/support/test_harness.rb, line 20
def expect_query(query, to_find:)
  @query = query
  @expected_query_results = to_find
  verify!
  self
end
when(*commands) click to toggle source
# File lib/metacosm/support/test_harness.rb, line 6
def when(*commands)
  @when_commands ||= []
  commands.each do |command|
    @when_commands.push command
  end
  self
end

Protected Instance Methods

verify!() click to toggle source
# File lib/metacosm/support/test_harness.rb, line 29
def verify!
  clean_slate!
  receive_events!
  fire_commands!

  validate_events!
  validate_query!

  self
end

Private Instance Methods

clean_slate!() click to toggle source
# File lib/metacosm/support/test_harness.rb, line 42
def clean_slate!
  PassiveRecord.drop_all
  Simulation.current.clear!
  self
end
fire_commands!() click to toggle source
# File lib/metacosm/support/test_harness.rb, line 57
def fire_commands!
  unless @when_commands.nil?
    @when_commands.each do |cmd|
      sim.apply(cmd)
    end
  end
  self
end
receive_events!() click to toggle source
# File lib/metacosm/support/test_harness.rb, line 48
def receive_events!
  unless self.given_events.nil?
    self.given_events.each do |evt| 
      sim.receive(evt, record: false)
    end
  end
  self
end
sim() click to toggle source
# File lib/metacosm/support/test_harness.rb, line 91
def sim
  @sim ||= Simulation.current
end
validate_events!() click to toggle source
# File lib/metacosm/support/test_harness.rb, line 66
def validate_events!
  if @then_event_class
    expect(@then_event_class).to eq(sim.events.last.class) 
  end

  if @then_events
    expect(@then_events).to match_array(sim.events) 
  end

  if @then_event_attrs
    @then_event_attrs.each do |k,v|
      expect(sim.events.last.send(k)).to eq(v)
    end
  end

  self
end
validate_query!() click to toggle source
# File lib/metacosm/support/test_harness.rb, line 84
def validate_query!
  if @query
    expect(@query.execute).to eq(@expected_query_results)
  end
  self
end