Module: Orocos::Test::Component::ClassExtension

Defined in:
lib/orocos/test/component.rb

Overview

Support module for declarations in tests

Instance Method Summary collapse

Instance Method Details

#reader(name, port_name, options = Hash.new) ⇒ Object



187
188
189
190
191
192
193
194
195
# File 'lib/orocos/test/component.rb', line 187

def reader(name, port_name, options = Hash.new)
    if options.respond_to?(:to_str)
        options = { :attr_name => options }
    end
    options, policy = Kernel.filter_options options,
        :attr_name => "#{name}_#{port_name}"
    attr_reader options[:attr_name]
    reader_specs << [name, port_name, options[:attr_name], policy]
end

#start(attr_name, task_name, run_spec) ⇒ Object #start(attr_name, run_spec) ⇒ Object

Starts a new task context on test setup and assigns it to a local variable

Requires the unit test to start a deployment/task at startup and shut it down during teardown. In test methods, the task object can be accessed as the attr_name attribute

Examples:

start a task context and tests that configuration fails


require 'minitest/spec'
require 'orocos/test/component'
describe 'xsens_imu::Task' do
  include Orocos::Test::Component
  start 'task', 'xsens_imu::Task' => 'task'

  def test_configure_fails_if_no_device_is_present
    task.device = ""
    assert_raises(Orocos::StateTransitionFailed) { task.configure }
  end
end

Overloads:

  • #start(attr_name, task_name, run_spec) ⇒ Object

    Parameters:

    • attr_name (String, Symbol)

      the attribute name

    • task_name (String)

      the name of the orocos task that should be assigned to

    • run_spec (Hash)

      arguments that should be passed to Orocos.run. Once Orocos.run is called, there should exists a task called task_name

  • #start(attr_name, run_spec) ⇒ Object

    Parameters:

    • attr_name (String, Symbol)

      the attribute name as well as the orocos task name. See above.

    • run_spec (Hash)

      arguments that should be passed to Orocos.run. Once Orocos.run is called, there should exists a task called attr_name



176
177
178
179
180
181
182
183
184
185
# File 'lib/orocos/test/component.rb', line 176

def start(attr_name, *options)
    attr_reader attr_name
    if options.size == 2
        run_specs << [attr_name, *options]
    elsif options.size == 1
        run_specs << [attr_name, attr_name, *options]
    else
        raise ArgumentError, "expected two or three arguments, got #{options.size}"
    end
end

#writer(name, port_name, options = Hash.new) ⇒ Object



197
198
199
200
201
202
203
204
205
# File 'lib/orocos/test/component.rb', line 197

def writer(name, port_name, options = Hash.new)
    if options.respond_to?(:to_str)
        options = { :attr_name => options }
    end
    options, policy = Kernel.filter_options options,
        :attr_name => "#{name}_#{port_name}"
    attr_reader options[:attr_name]
    writer_specs << [name, port_name, options[:attr_name], policy]
end