Module: Roby::Test::DSL

Extended by:
MetaRuby::Attributes
Includes:
Minitest::Spec::DSL
Included in:
Spec
Defined in:
lib/roby/test/dsl.rb

Defined Under Namespace

Modules: InstanceExtension

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(mod) ⇒ Object



155
156
157
# File 'lib/roby/test/dsl.rb', line 155

def self.extended(mod)
    mod.include InstanceExtension
end

Instance Method Details

#describe(*desc, &block) ⇒ Object

Register sub-hooks



121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/roby/test/dsl.rb', line 121

def describe(*desc, &block)
    if kind_of?(Class)
        super
    else
        behaviour = Module.new do
            extend Roby::Test::DSL
            class_eval(&block)
        end

        @__describe_blocks ||= []
        @__describe_blocks << [desc, behaviour]
    end
end

#included(target) ⇒ Object



159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/roby/test/dsl.rb', line 159

def included(target)
    super

    @__describe_blocks ||= []
    if Class === target
        @__describe_blocks.each do |desc, behaviour|
            target.describe(desc) { include behaviour }
        end
    else
        target_blocks = (target.instance_variable_get(:@__describe_blocks) || [])
            .concat(@__describe_blocks)
        target.instance_variable_set(:@__describe_blocks, target_blocks)
    end
end

#roby_should_run(test, app) ⇒ Boolean

Tests whether self should run on the given app configuration

Parameters:

Returns:

  • (Boolean)


109
110
111
112
113
114
115
116
117
118
# File 'lib/roby/test/dsl.rb', line 109

def roby_should_run(test, app)
    run_modes = all_run_mode
    enabled_robots = all_enabled_robot

    if !run_modes.empty? && run_modes.all? { |blk| !blk.call(app) }
        test.skip("#{test.name} cannot run in this roby test configuration")
    elsif !enabled_robots.empty? && !enabled_robots.include?(app.robot_name)
        test.skip("#{test.name} can only be run on robots #{enabled_robots.sort.join(', ')}")
    end
end

#run_if {|app| ... } ⇒ Object

Enable this test only on the configurations in which the given block returns true

If more than one call to the run_ methods is given, the test will run as soon as at least one of the conditions is met

otherwise

By default, the tests are enabled in all modes. As soon as one of the run_ methods gets called, it is restricted to this particular mode

Yield Parameters:

Yield Returns:

  • (Boolean)

    true if the spec should run, false



25
26
27
# File 'lib/roby/test/dsl.rb', line 25

def run_if(&block)
    run_modes << lambda(&block)
end

#run_interactive(&block) ⇒ Object

Enable this test in interactive mode

By default, the tests are enabled in all modes. As soon as one of the run_ methods gets called, it is restricted to this particular mode



94
95
96
97
98
99
100
101
102
103
# File 'lib/roby/test/dsl.rb', line 94

def run_interactive(&block)
    if block
        describe "in interactive mode" do
            run_interactive
            class_eval(&block)
        end
    else
        run_if { |app| !app.automatic_testing? }
    end
end

#run_live(&block) ⇒ Object

Enable this test in live (non-simulated mode)

By default, the tests are enabled in all modes. As soon as one of the run_ methods gets called, it is restricted to this particular mode



78
79
80
81
82
83
84
85
86
87
# File 'lib/roby/test/dsl.rb', line 78

def run_live(&block)
    if block
        describe "in live mode" do
            run_live
            class_eval(&block)
        end
    else
        run_if { |app| !app.simulation? }
    end
end

#run_on_robot(*robot_names, &block) ⇒ Object

Enable this test only on the given robot



30
31
32
33
34
35
36
37
38
39
# File 'lib/roby/test/dsl.rb', line 30

def run_on_robot(*robot_names, &block)
    if block
        describe "in robot configurations #{robot_names.sort.join(', ')}" do
            run_on_robot(*robot_names)
            class_eval(&block)
        end
    else
        enabled_robots.merge(robot_names)
    end
end

#run_simulated(&block) ⇒ Object

Enable this test in simulated mode

By default, the tests are enabled in all modes. As soon as one of the run_ methods gets called, it is restricted to this particular mode



62
63
64
65
66
67
68
69
70
71
# File 'lib/roby/test/dsl.rb', line 62

def run_simulated(&block)
    if block
        describe "in simulation mode" do
            run_simulated
            class_eval(&block)
        end
    else
        run_if(&:simulation?)
    end
end

#run_single(&block) ⇒ Object

Enable this test in single mode

By default, the tests are enabled in all modes. As soon as one of the run_ methods gets called, it is restricted to this particular mode



46
47
48
49
50
51
52
53
54
55
# File 'lib/roby/test/dsl.rb', line 46

def run_single(&block)
    if block
        describe "in single mode" do
            run_single
            class_eval(&block)
        end
    else
        run_if(&:single?)
    end
end