Class: Roby::Test::ValidateStateMachine

Inherits:
Object
  • Object
show all
Includes:
MetaRuby::DSLs::FindThroughMethodMissing
Defined in:
lib/roby/test/validate_state_machine.rb

Overview

Implementation of the #validate_state_machine context

Instance Method Summary collapse

Constructor Details

#initialize(test, task_or_action) ⇒ ValidateStateMachine

Returns a new instance of ValidateStateMachine.



5
6
7
8
9
10
11
12
13
14
# File 'lib/roby/test/validate_state_machine.rb', line 5

def initialize(test, task_or_action)
    @test = test
    @toplevel_task = @test.roby_run_planner(task_or_action)

    @state_machines = @toplevel_task.each_coordination_object.
        find_all { |obj| obj.kind_of?(Coordination::ActionStateMachine) }
    if @state_machines.empty?
        raise ArgumentError, "#{task_or_action} has no state machines"
    end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



65
66
67
68
69
70
71
# File 'lib/roby/test/validate_state_machine.rb', line 65

def method_missing(m, *args, &block)
    if @test.respond_to?(m)
        @test.public_send(m, *args, &block)
    else
        super
    end
end

Instance Method Details

#assert_transitions_to_state(state_name, timeout: 5, start: true) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/roby/test/validate_state_machine.rb', line 16

def assert_transitions_to_state(state_name, timeout: 5, start: true)
    if state_name.respond_to?(:to_str) && !state_name.end_with?('_state')
        state_name = "#{state_name}_state"
    end

    done = false
    @state_machines.each do |m|
        m.on_transition do |_, new_state|
            if state_name === new_state.name
                done = true
            end
        end
    end
    yield if block_given?
    @test.process_events_until(timeout: timeout, garbage_collect_pass: false) do
        done
    end
    @test.roby_run_planner(@toplevel_task)
    state_task = @toplevel_task.current_task_child
    if start
        expect_execution.to { emit state_task.start_event }
    end
    state_task
end

#evaluate(&block) ⇒ Object



41
42
43
# File 'lib/roby/test/validate_state_machine.rb', line 41

def evaluate(&block)
    instance_eval(&block)
end

#find_through_method_missing(m, args) ⇒ Object



45
46
47
48
49
50
# File 'lib/roby/test/validate_state_machine.rb', line 45

def find_through_method_missing(m, args)
    MetaRuby::DSLs.find_through_method_missing(
        @toplevel_task, m, args,
        '_event' => :find_event,
        '_child' => :find_child_from_role) || super
end

#has_through_method_missing?(m) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
55
56
57
# File 'lib/roby/test/validate_state_machine.rb', line 52

def has_through_method_missing?(m)
    MetaRuby::DSLs.has_through_method_missing?(
        @toplevel_task, m,
        '_event' => :has_event?,
        '_child' => :has_role?) || super
end

#respond_to_missing?(m, include_private) ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/roby/test/validate_state_machine.rb', line 61

def respond_to_missing?(m, include_private)
    @test.respond_to?(m) || super
end