From 23d64ef9d85044621778328a080eabccf95b276f Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Fri, 11 Aug 2023 14:44:51 +0100 Subject: [PATCH] test files renamed with test_ prefix error tests added Rakefile updated with new test file names event tasks moved into :e namespace --- Gemfile.lock | 2 +- Rakefile | 30 +++++++++++-------- main.rb | 2 +- test/obsws/{attrs_test.rb => test_attrs.rb} | 0 test/obsws/test_error.rb | 17 +++++++++++ .../{request_test.rb => test_request.rb} | 0 6 files changed, 37 insertions(+), 14 deletions(-) rename test/obsws/{attrs_test.rb => test_attrs.rb} (100%) create mode 100644 test/obsws/test_error.rb rename test/obsws/{request_test.rb => test_request.rb} (100%) diff --git a/Gemfile.lock b/Gemfile.lock index b5ad144..cfbcccc 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - obsws (0.5.2) + obsws (0.5.3) waitutil (~> 0.2.1) websocket-driver (~> 0.7.5) diff --git a/Rakefile b/Rakefile index b337b7c..81f7b3b 100644 --- a/Rakefile +++ b/Rakefile @@ -5,19 +5,25 @@ HERE = __dir__ Minitest::TestTask.create(:test) do |t| t.libs << "test" t.warning = false - t.test_globs = ["test/**/*_test.rb"] + t.test_globs = ["test/**/test_*.rb"] end task default: :test -task :events do - filepath = File.join(HERE, "examples", "events", "main.rb") - ruby filepath -end -task :levels do - filepath = File.join(HERE, "examples", "levels", "main.rb") - ruby filepath -end -task :scene_rotate do - filepath = File.join(HERE, "examples", "scene_rotate", "main.rb") - ruby filepath + +namespace :e do + desc "Runs the events example" + task :events do + filepath = File.join(HERE, "examples", "events", "main.rb") + ruby filepath + end + desc "Runs the levels example" + task :levels do + filepath = File.join(HERE, "examples", "levels", "main.rb") + ruby filepath + end + desc "Runs the scene_rotate example" + task :scene_rotate do + filepath = File.join(HERE, "examples", "scene_rotate", "main.rb") + ruby filepath + end end diff --git a/main.rb b/main.rb index b360913..112fb30 100644 --- a/main.rb +++ b/main.rb @@ -1,4 +1,4 @@ -require_relative "lib/obsws" +require "obsws" class Main def run diff --git a/test/obsws/attrs_test.rb b/test/obsws/test_attrs.rb similarity index 100% rename from test/obsws/attrs_test.rb rename to test/obsws/test_attrs.rb diff --git a/test/obsws/test_error.rb b/test/obsws/test_error.rb new file mode 100644 index 0000000..b881218 --- /dev/null +++ b/test/obsws/test_error.rb @@ -0,0 +1,17 @@ +require_relative "../minitest_helper" + +class OBSWSConnectionErrorTest < Minitest::Test + def test_it_raises_an_obsws_connection_error_on_wrong_password + e = assert_raises(OBSWS::OBSWSConnectionError) { OBSWS::Requests::Client.new(host: "localhost", port: 4455, password: "wrongpassword", connect_timeout: 1).new } + assert_equal(e.message, "Timed out waiting for successful identification (1 seconds elapsed)") + end +end + +class OBSWSRequestErrorTest < Minitest::Test + def test_it_raises_an_obsws_request_error_on_invalid_request + e = assert_raises(OBSWS::OBSWSRequestError) { OBSWSTest.r_client.toggle_input_mute("unknown") } + assert_equal(e.req_name, "ToggleInputMute") + assert_equal(e.code, 600) + assert_equal(e.message, "Request ToggleInputMute returned code 600. With message: No source was found by the name of `unknown`.") + end +end diff --git a/test/obsws/request_test.rb b/test/obsws/test_request.rb similarity index 100% rename from test/obsws/request_test.rb rename to test/obsws/test_request.rb