Module: Roby::Test::ArubaMinitest

Defined in:
lib/roby/test/aruba_minitest.rb

Overview

Minitest-usable Aruba wrapper

Aruba 0.14 is incompatible with Minitest because of their definition of the #run method This change hacks around the problem, by moving the Aruba API to a side stub object.

The run methods are renamed as they have been renamed in Aruba 1.0 alpha, run -> run_command and run_simple -> run_command_and_stop

Defined Under Namespace

Classes: API

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



78
79
80
81
82
83
84
# File 'lib/roby/test/aruba_minitest.rb', line 78

def method_missing(name, *args, &block)
    if @aruba_api.respond_to?(name)
        return @aruba_api.send(name, *args, &block)
    end

    super
end

Instance Attribute Details

#roby_binObject (readonly)

Returns the value of attribute roby_bin.



26
27
28
# File 'lib/roby/test/aruba_minitest.rb', line 26

def roby_bin
  @roby_bin
end

Instance Method Details

#assert_command_finished_successfully(cmd) ⇒ Object



91
92
93
94
95
96
97
98
99
# File 'lib/roby/test/aruba_minitest.rb', line 91

def assert_command_finished_successfully(cmd)
    refute cmd.timed_out?,
           "#{cmd} timed out on stop\n-- STDOUT\n#{cmd.stdout}\n"\
           "STDERR\n#{cmd.stderr}"
    assert_equal 0, cmd.exit_status,
                 "#{cmd} finished with a non-zero exit status "\
                 "(#{cmd.exit_status})\n-- STDOUT\n#{cmd.stdout}\n"\
                 "-- STDERR\n#{cmd.stderr}"
end

#assert_command_stops(cmd, fail_on_error: true) ⇒ Object



86
87
88
89
# File 'lib/roby/test/aruba_minitest.rb', line 86

def assert_command_stops(cmd, fail_on_error: true)
    cmd.stop
    assert_command_finished_successfully(cmd) if fail_on_error
end

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/roby/test/aruba_minitest.rb', line 74

def respond_to_missing?(name, include_private = false)
    @aruba_api.respond_to?(name) || super
end

#roby_allocate_portObject



40
41
42
43
44
45
# File 'lib/roby/test/aruba_minitest.rb', line 40

def roby_allocate_port
    server = ::TCPServer.new(0)
    server.local_address.ip_port
ensure
    server&.close
end

#run_command(cmd, exit_timeout: 45, **opts) ⇒ Object



55
56
57
58
# File 'lib/roby/test/aruba_minitest.rb', line 55

def run_command(cmd, exit_timeout: 45, **opts)
    opts[:exit_timeout] ||= exit_timeout
    @aruba_api.run_command(cmd, opts)
end

#run_command_and_stop(cmd, fail_on_error: true, exit_timeout: 45, **opts) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/roby/test/aruba_minitest.rb', line 47

def run_command_and_stop(cmd, fail_on_error: true, exit_timeout: 45, **opts)
    opts[:exit_timeout] ||= exit_timeout
    cmd = run_command(cmd, **opts)
    cmd.stop
    assert_command_finished_successfully(cmd) if fail_on_error
    cmd
end

#run_roby(cmd, *args, fail_on_error: true, exit_timeout: 45, **opts) ⇒ Object



68
69
70
71
72
# File 'lib/roby/test/aruba_minitest.rb', line 68

def run_roby(cmd, *args, fail_on_error: true, exit_timeout: 45, **opts)
    opts[:exit_timeout] ||= exit_timeout
    run_command("#{Gem.ruby} #{roby_bin} #{cmd}", *args,
                fail_on_error: fail_on_error, **opts)
end

#run_roby_and_stop(cmd, *args, fail_on_error: true, exit_timeout: 45, **opts) ⇒ Object



60
61
62
63
64
65
66
# File 'lib/roby/test/aruba_minitest.rb', line 60

def run_roby_and_stop(
    cmd, *args, fail_on_error: true, exit_timeout: 45, **opts
)
    opts[:exit_timeout] ||= exit_timeout
    run_command_and_stop("#{Gem.ruby} #{roby_bin} #{cmd}", *args,
                         fail_on_error: fail_on_error, **opts)
end

#setupObject



28
29
30
31
32
33
# File 'lib/roby/test/aruba_minitest.rb', line 28

def setup
    super
    @aruba_api = API.new
    @aruba_api.setup_aruba
    @roby_bin = File.join(Roby::BIN_DIR, "roby")
end

#teardownObject



35
36
37
38
# File 'lib/roby/test/aruba_minitest.rb', line 35

def teardown
    stop_all_commands
    super
end

#wait_for_output(cmd, channel, timeout: 5) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
# File 'lib/roby/test/aruba_minitest.rb', line 101

def wait_for_output(cmd, channel, timeout: 5)
    deadline = Time.now + timeout
    while Time.now < deadline
        if yield(cmd.send(channel))
            assert(true) # To account for the assertion
            return
        end
    end

    flunk("timed out waiting for #{channel} to match in #{cmd}")
end