Module: RPicSim::RSpec::Helpers

Includes:
PersistentExpectations
Defined in:
lib/rpicsim/rspec/helpers.rb

Overview

This module gets included into your RSpec examples if you use the following line in your spec_helper.rb:

require 'rpicsim/rspec'

It provides the #start_sim method and includes all the methods from PersistentExpectations.

For more information, see RSpecIntegration.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from PersistentExpectations

#check_expectations, #expectations, #expecting

Instance Attribute Details

#simObject (readonly)

This attribute allows you to type sim in your specs instead of @sim to get access to the Sim instance which represents the simulation. You must call #start_sim before using sim.



22
23
24
# File 'lib/rpicsim/rspec/helpers.rb', line 22

def sim
  @sim
end

Instance Method Details

#start_sim(klass, *args) ⇒ Object

Starts a new simulation with the specified class, makes it accessible via the attribute #sim, and adds convenient shortcut methods that can be used in the RSpec example.

Parameters:

  • klass (Class)

    This should be a subclass of Sim or at least act like it.

  • args

    A list of arguments to pass on to the the new method of the class. This should usually be empty unless you have modified your class to take arguments in its constructor.



31
32
33
34
35
# File 'lib/rpicsim/rspec/helpers.rb', line 31

def start_sim(klass, *args)
  @sim = klass.new(*args)
  add_shortcuts
  sim.every_step { check_expectations }
end