class Roby::Test::Spec

Attributes

models_present_in_setup[R]

Set of models present during {#setup}

This is used to clear all the models created during the test in {#teardown}

Public Class Methods

roby_plan_with(matcher, handler) click to toggle source

Declare what {#roby_run_planner} should use to develop a given task during a test

The latest handler registered wins

@param [PlanningHandler] a planning handler

# File lib/roby/test/spec.rb, line 177
def self.roby_plan_with(matcher, handler)
    RunPlanners.roby_plan_with(matcher, handler)
end
test_methods() click to toggle source
Calls superclass method
# File lib/roby/test/spec.rb, line 37
def self.test_methods
    methods = super
    # Duplicate each method 'repeat' times
    methods.inject([]) do |list, m|
        list.concat([m] * Roby.app.test_repeat)
    end
end

Public Instance Methods

__full_name__() click to toggle source
# File lib/roby/test/spec.rb, line 45
def __full_name__
    "#{self.class}##{name}"
end
app() click to toggle source
# File lib/roby/test/spec.rb, line 23
def app
    Roby.app
end
clear_newly_defined_models() click to toggle source
# File lib/roby/test/spec.rb, line 89
def clear_newly_defined_models
    app.root_models.each do |root_model|
        ([root_model] + root_model.each_submodel.to_a).each do |m|
            if !models_present_in_setup.include?(m)
                m.permanent_model = false
                m.clear_model
            end
        end
    end
end
engine() click to toggle source
# File lib/roby/test/spec.rb, line 29
def engine
    Roby.warn_deprecated "#engine is deprecated, use #execution_engine instead"
    execution_engine
end
execution_engine() click to toggle source
# File lib/roby/test/spec.rb, line 33
def execution_engine
    app.execution_engine
end
inhibit_fatal_messages(&block) click to toggle source

@deprecated use capture_log instead

# File lib/roby/test/spec.rb, line 144
def inhibit_fatal_messages(&block)
    Roby.warn_deprecated "#{__method__} is deprecated, use capture_log instead"
    with_log_level(Roby, Logger::FATAL, &block)
end
plan() click to toggle source
# File lib/roby/test/spec.rb, line 26
def plan
    app.plan
end
process_events(timeout: 10, **options, &caller_block) click to toggle source
# File lib/roby/test/spec.rb, line 100
def process_events(timeout: 10, **options, &caller_block)
    Roby.warn_deprecated "do not use #process_events. Use the expect_execution infrastructure instead"

    exceptions = Array.new
    first_pass = true
    while first_pass || execution_engine.has_waiting_work?
        first_pass = false

        execution_engine.join_all_waiting_work(timeout: timeout)
        execution_engine.start_new_cycle
        errors = execution_engine.process_events(**options, &caller_block)
        caller_block = nil
        exceptions.concat(errors.exceptions)
        execution_engine.cycle_end(Hash.new)
    end

    if !exceptions.empty?
        if exceptions.size == 1
            raise exceptions.first.exception
        else
            raise SynchronousEventProcessingMultipleErrors.new(exceptions.map(&:exception))
        end
    end
end
process_events_until(timeout: 5, **options) click to toggle source

Repeatedly process events until a condition is met

@yieldreturn [Boolean] true if the condition is met, false otherwise

# File lib/roby/test/spec.rb, line 128
def process_events_until(timeout: 5, **options)
    Roby.warn_deprecated "do not use #process_events. Use the expect_execution infrastructure with the 'achieve' expectation instead"

    start = Time.now
    while !yield
        now = Time.now
        remaining = timeout - (now - start)
        if remaining < 0
            flunk("failed to reach expected condition within #{timeout} seconds")
        end
        process_events(timeout: remaining, **options)
        sleep 0.01
    end
end
roby_run_planner(root_task, recursive: true, **options) click to toggle source

@deprecated use {#run_planners} instead

# File lib/roby/test/spec.rb, line 167
def roby_run_planner(root_task, recursive: true, **options)
    run_planners(root_task, recursive: true, **options)
end
run() click to toggle source

Filters out the test suites that are not enabled by the current Roby configuration

Calls superclass method
# File lib/roby/test/spec.rb, line 183
def run
    time_it do
        capture_exceptions do
            self.class.roby_should_run(self, app)
            super
        end
    end
end
setup() click to toggle source
Calls superclass method Roby::Test::Assertions#setup
# File lib/roby/test/spec.rb, line 55
def setup
    plan.execution_engine.display_exceptions = false
    # Mark every app-defined model as permanent, so that the tests can define
    # their own and get cleanup up properly on teardown
    @models_present_in_setup = Set.new
    app.root_models.each do |root_model|
        models_present_in_setup << root_model
        root_model.each_submodel do |m|
            models_present_in_setup << m
        end
    end
    register_plan(plan)

    super
end
teardown() click to toggle source
Calls superclass method Roby::Test::Assertions#teardown
# File lib/roby/test/spec.rb, line 71
def teardown
    Timecop.return

    begin
        super
    rescue ::Exception => e
        teardown_failure = e
    end

    teardown_registered_plans

ensure
    clear_registered_plans
    if teardown_failure
        raise teardown_failure
    end
end
with_log_level(log_object, level) { || ... } click to toggle source

@deprecated use capture_log instead

# File lib/roby/test/spec.rb, line 150
def with_log_level(log_object, level)
    Roby.warn_deprecated "#{__method__} is deprecated, use capture_log instead"
    if log_object.respond_to?(:logger)
        log_object = log_object.logger
    end
    current_level = log_object.level
    log_object.level = level

    yield

ensure
    if current_level
        log_object.level = current_level
    end
end