class TestRoleBuilder
Public Instance Methods
app()
click to toggle source
# File lib/belphanior/servant/test/tc_role_builder.rb, line 41 def app Sinatra::Application end
setup()
click to toggle source
# File lib/belphanior/servant/test/tc_role_builder.rb, line 45 def setup app.set :roles, [] @default_description = { "name" => "test description", "description" => "An example of a role description.", "commands" => [ { "name" => "test command", "description" => "An example command.", "arguments" => [ { "name" => "test arg", "description" => "An example argument." } ] } ] } @default_usage = [ "GET", "/path", "data" ] end
teardown()
click to toggle source
# File lib/belphanior/servant/test/tc_role_builder.rb, line 70 def teardown app.clear_handlers end
test_add_handler_adds_handler()
click to toggle source
# File lib/belphanior/servant/test/tc_role_builder.rb, line 81 def test_add_handler_adds_handler app.add_role_description @default_description app.add_handler("test command", ["argument 1", "argument 2"], "POST", "/test/$(argument 1)", "$(argument 2)") { |arg1| "arg1 is "+arg1+" arg2 is "+(request.body.read) } post '/test/foo', 'bar' assert last_response.ok? assert_equal("arg1 is foo arg2 is bar", last_response.body) end
test_add_handler_updates_protocol()
click to toggle source
# File lib/belphanior/servant/test/tc_role_builder.rb, line 92 def test_add_handler_updates_protocol app.add_role_description @default_description app.set_role_url("/test") app.add_handler("test command", ["argument 1"], "GET", "/test/$(argument 1)", "") {|arg1|} get '/protocol' assert_equal(200, last_response.status) assert_equivalent_json_objects( { "roles" => [{ "role_url" => "/test", "handlers" => [{ "name" => "test command", "method" => "GET", "path" => "/test/$(argument 1)"}] }]}, JSON.parse(last_response.body)) end
test_identifier_case_insensitivity()
click to toggle source
# File lib/belphanior/servant/test/tc_role_builder.rb, line 116 def test_identifier_case_insensitivity app.add_role_description @default_description app.set_role_url "/test" app.add_handler("My command", ["Cap"], "GET", "path", "data") do end get '/protocol' assert_equal(200, last_response.status) assert_equivalent_json_objects( { "roles" => [{ "role_url" => "/test", "handlers" => [{ "name" => "my command", "method" => "GET", "path" => "path", "data" => "data"}] }]}, JSON.parse(last_response.body)) end
test_multi_role()
click to toggle source
# File lib/belphanior/servant/test/tc_role_builder.rb, line 134 def test_multi_role app.add_role_description @default_description app.add_role_description({ "name" => "second role", "description" => "An example of a role description.", "commands" => [ { "name" => "test command 2", "description" => "An example command.", "arguments" => [ { "name" => "test arg b", "description" => "An example argument." } ] } ] } ) app.add_handler("test command", ["test arg"], "POST", "/test2/$(test arg)", "", 0) { |arg1| "arg1 is " + arg1 } app.add_handler("test command 2", ["test arg b"], "GET", "/test3/$(test arg b)", "", 1) { |arg1| "arg1b is " + arg1 } post '/test2/foo', "" assert last_response.ok? assert_equal("arg1 is foo", last_response.body) get '/test3/bar' assert last_response.ok? assert_equal("arg1b is bar", last_response.body) end
test_role_builder_utils_usage_string_to_sinatra_path()
click to toggle source
# File lib/belphanior/servant/test/tc_role_builder.rb, line 110 def test_role_builder_utils_usage_string_to_sinatra_path assert_equal "/test/:value/test/:value2", RoleBuilderUtils.usage_string_to_sinatra_path( "/test/$(value)/test/$(value2)") end
test_role_describer_accepts_role_description()
click to toggle source
# File lib/belphanior/servant/test/tc_role_builder.rb, line 74 def test_role_describer_accepts_role_description app.add_role_description @default_description get '/role_descriptions/test_description' assert last_response.ok? assert_equal JSON.generate(@default_description), last_response.body end