Module: Roby::Interface::REST::Test

Includes:
Rack::Test::Methods
Defined in:
lib/roby/interface/rest/test.rb

Overview

Test helpers to interact with a REST API embedded in a Roby app

It provides a Roby-compatible integration with Rack::Test. You only need to overload the #rest_api method to return your Grape API class

You cannot use this with a describe … block (yet). Instead, do

class TESTNAME < Syskit::Test::Spec
    include Roby::Interface::REST::Test
    # rest of the tests
end

Note that you can use describe block within the test class

Whenever you call an endpoint that acts on the execution engine (e.g. emits an event), wrap it in an execute { } block

Instance Method Summary collapse

Instance Method Details

#build_rack_mock_session(roby_execute: false) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Overloaded from Rack::Test to inject the app and plan and make them available to the API



42
43
44
45
46
47
48
49
50
51
# File 'lib/roby/interface/rest/test.rb', line 42

def build_rack_mock_session(roby_execute: false)
    interface = Roby::Interface::Interface.new(app)
    actual_api =
        Roby::Interface::REST::Server
        .attach_api_to_interface(
            rest_api, interface, roby_storage,
            roby_execute: roby_execute
        )
    Rack::MockSession.new(actual_api)
end

#rest_apiObject

Raises:

  • (NotImplementedError)


28
29
30
31
# File 'lib/roby/interface/rest/test.rb', line 28

def rest_api
    raise NotImplementedError, "implement #rest_api in your test "\
                               "to return the REST API"
end

#roby_storageObject

The Helpers#roby_storage object that is being accessed by the API



34
35
36
# File 'lib/roby/interface/rest/test.rb', line 34

def roby_storage
    @roby_storage ||= {}
end