From f1638acd5113af041e3ab588a004c4b7525a32c2 Mon Sep 17 00:00:00 2001 From: Mike DeAngelo Date: Tue, 27 Aug 2024 16:13:36 -0400 Subject: [PATCH] chore: upgrade deps and fix tests for new format Change-Id: I7eb31a94ee2aaca875bbafda82da11e074ae9b74 --- Gemfile | 4 +-- Gemfile.lock | 11 +++--- test/helper.rb | 14 +++++--- test/looker/test_client.rb | 4 +-- test/looker/test_dynamic_client.rb | 12 +++---- test/looker/test_dynamic_client_agent.rb | 46 ++++++++++++++++++------ 6 files changed, 60 insertions(+), 31 deletions(-) diff --git a/Gemfile b/Gemfile index 247b608..f7ce597 100644 --- a/Gemfile +++ b/Gemfile @@ -11,8 +11,8 @@ end group :test do # gem 'json', '~> 1.7', :platforms => [:jruby] look TODO needed? - gem 'minitest', '~> 5.11.0' - gem 'mocha', '~> 1.1.0' + gem 'minitest', '~> 5.25.1' + gem 'mocha', '~> 2.4.5' gem 'rack', '~> 2.2.8' gem 'netrc', '~> 0.11.0' gem 'rack-test', '~> 2' diff --git a/Gemfile.lock b/Gemfile.lock index fed3e19..f8e6608 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -29,10 +29,9 @@ GEM faraday-net_http (3.0.2) faraday-rack (2.0.0) faraday (~> 2.0) - metaclass (0.0.4) - minitest (5.11.3) - mocha (1.1.0) - metaclass (~> 0.0.1) + minitest (5.25.1) + mocha (2.4.5) + ruby2_keywords (>= 0.0.5) multipart-post (2.3.0) netrc (0.11.0) public_suffix (5.0.1) @@ -66,8 +65,8 @@ DEPENDENCIES faraday-multipart (~> 1.0) faraday-rack (~> 2) looker-sdk! - minitest (~> 5.11.0) - mocha (~> 1.1.0) + minitest (~> 5.25.1) + mocha (~> 2.4.5) netrc (~> 0.11.0) rack (~> 2.2.8) rack-test (~> 2) diff --git a/test/helper.rb b/test/helper.rb index 4beb731..6c9e79e 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -23,9 +23,7 @@ ############################################################################################ require 'simplecov' -SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[ - SimpleCov::Formatter::HTMLFormatter -] +SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new SimpleCov::Formatter::HTMLFormatter SimpleCov.start require 'rubygems' @@ -38,12 +36,20 @@ require 'minitest/autorun' require 'minitest/spec' require 'minitest/mock' -require 'mocha/mini_test' +require 'mocha/minitest' require "rack/test" require "rack/request" require "faraday/rack" require "faraday/multipart" if ENV['USE_FARADAY_MULTIPART'] == 'true' +module Minitest + class Mock + def is_a?( _a ) + false + end + end +end + def fixture_path File.expand_path("../fixtures", __FILE__) end diff --git a/test/looker/test_client.rb b/test/looker/test_client.rb index 19d073e..dc04076 100644 --- a/test/looker/test_client.rb +++ b/test/looker/test_client.rb @@ -304,7 +304,7 @@ expected_path = '/api/4.0/users/foo%252Fbar' resp = OpenStruct.new(:data => "hi", :status => 204) - mock = MiniTest::Mock.new.expect(:call, resp, [method, expected_path, nil, {}]) + mock = Minitest::Mock.new.expect(:call, resp, [method, expected_path, nil]) Sawyer::Agent.stubs(:new).returns(mock, mock) sdk = LookerSDK::Client.new @@ -314,7 +314,7 @@ args = [method, path, nil, nil, encoded] end sdk.without_authentication do - value = sdk.public_send *args + value = sdk.public_send(*args) assert_equal "hi", value end mock.verify diff --git a/test/looker/test_dynamic_client.rb b/test/looker/test_dynamic_client.rb index 4f7c221..01235b1 100644 --- a/test/looker/test_dynamic_client.rb +++ b/test/looker/test_dynamic_client.rb @@ -24,7 +24,7 @@ require_relative '../helper' -class LookerDynamicClientTest < MiniTest::Spec +class LookerDynamicClienttest < Minitest::Spec def access_token '87614b09dd141c22800f96f11737ade5226d7ba8' @@ -70,7 +70,7 @@ def confirm_env(env, method, path, body, query, content_type) begin JSON.parse(req_body, :symbolize_names => true).must_equal body - rescue JSON::ParserError => e + rescue JSON::ParserError req_body.must_equal body end @@ -86,7 +86,7 @@ def confirm_env(env, method, path, body, query, content_type) end def verify(response, method, path, body='', query={}, content_type = nil) - mock = MiniTest::Mock.new.expect(:call, response){|env| confirm_env(env, method, path, body, query, content_type)} + mock = Minitest::Mock.new.expect(:call, response){|env| confirm_env(env, method, path, body, query, content_type)} yield sdk_client(default_swagger, mock) mock.verify end @@ -94,7 +94,7 @@ def verify(response, method, path, body='', query={}, content_type = nil) describe "swagger" do it "raises when swagger.json can't be loaded" do - mock = MiniTest::Mock.new.expect(:call, nil) {raise "no swagger for you"} + mock = Minitest::Mock.new.expect(:call, nil) {raise "no swagger for you"} mock.expect(:call, nil) {raise "still no swagger for you"} err = assert_raises(RuntimeError) { sdk_client(nil, mock) } assert_equal "still no swagger for you", err.message @@ -102,14 +102,14 @@ def verify(response, method, path, body='', query={}, content_type = nil) it "loads swagger without authentication" do resp = [200, {'Content-Type' => 'application/json'}, [default_swagger.to_json]] - mock = MiniTest::Mock.new.expect(:call, resp, [Hash]) + mock = Minitest::Mock.new.expect(:call, resp, [Hash]) sdk = sdk_client(nil, mock) assert_equal default_swagger, sdk.swagger end it "loads swagger with authentication" do resp = [200, {'Content-Type' => 'application/json'}, [default_swagger.to_json]] - mock = MiniTest::Mock.new.expect(:call, nil) {raise "login first!"} + mock = Minitest::Mock.new.expect(:call, nil) {raise "login first!"} mock.expect(:call, resp, [Hash]) sdk = sdk_client(nil, mock) assert_equal default_swagger, sdk.swagger diff --git a/test/looker/test_dynamic_client_agent.rb b/test/looker/test_dynamic_client_agent.rb index 53c93d4..bb7c92e 100644 --- a/test/looker/test_dynamic_client_agent.rb +++ b/test/looker/test_dynamic_client_agent.rb @@ -64,7 +64,7 @@ def delete_response describe "swagger" do it "get" do - mock = MiniTest::Mock.new.expect(:call, response, [:get, '/api/4.0/user', nil, {}]) + mock = Minitest::Mock.new.expect(:call, response, [:get, '/api/4.0/user', nil]) with_stub(Sawyer::Agent, :new, mock) do sdk.me mock.verify @@ -72,7 +72,10 @@ def delete_response end it "get with params" do - mock = MiniTest::Mock.new.expect(:call, response, [:get, '/api/4.0/users/25', nil, {}]) + #mock = Minitest::Mock.new.expect(:call, response, [:get, '/api/4.0/users/25', nil, {}]) + mock = Minitest::Mock.new.expect :call, response do | verb, route, body | + verb == :get && route == '/api/4.0/users/25' && body.nil? + end with_stub(Sawyer::Agent, :new, mock) do sdk.user(25) mock.verify @@ -80,7 +83,10 @@ def delete_response end it "get with query" do - mock = MiniTest::Mock.new.expect(:call, response, [:get, '/api/4.0/user', nil, {query:{bar:"foo"}}]) + #mock = Minitest::Mock.new.expect(:call, response, [:get, '/api/4.0/user', nil, {query:{bar:"foo"}}]) + mock = Minitest::Mock.new.expect :call, response do | verb, route, body, query: | + verb == :get && route == '/api/4.0/user' && body.nil? && query == {bar:"foo"} + end with_stub(Sawyer::Agent, :new, mock) do sdk.me({bar:'foo'}) mock.verify @@ -88,7 +94,10 @@ def delete_response end it "get with params and query" do - mock = MiniTest::Mock.new.expect(:call, response, [:get, '/api/4.0/users/25', nil, {query:{bar:"foo"}}]) + #mock = Minitest::Mock.new.expect(:call, response, [:get, '/api/4.0/users/25', nil, {query:{bar:"foo"}}]) + mock = Minitest::Mock.new.expect :call, response do | verb, route, body, query: | + verb == :get && route == '/api/4.0/users/25' && body.nil? && query == {bar:"foo"} + end with_stub(Sawyer::Agent, :new, mock) do sdk.user(25, {bar:'foo'}) mock.verify @@ -96,7 +105,10 @@ def delete_response end it "post" do - mock = MiniTest::Mock.new.expect(:call, response, [:post, '/api/4.0/users', {first_name:'Joe'}, {:headers=>{:content_type=>"application/json"}}]) + #mock = Minitest::Mock.new.expect(:call, response, [:post, '/api/4.0/users', {first_name:'Joe'}, {:headers=>{:content_type=>"application/json"}}]) + mock = Minitest::Mock.new.expect :call, response do | verb, route, body, headers: | + verb == :post && route == '/api/4.0/users' && body == {first_name:'Joe'} && headers == {:content_type=>"application/json"} + end with_stub(Sawyer::Agent, :new, mock) do sdk.create_user({first_name:'Joe'}) mock.verify @@ -104,7 +116,10 @@ def delete_response end it "post with default body" do - mock = MiniTest::Mock.new.expect(:call, response, [:post, '/api/4.0/users', {}, {:headers=>{:content_type=>"application/json"}}]) + #mock = Minitest::Mock.new.expect(:call, response, [:post, '/api/4.0/users', {}, {:headers=>{:content_type=>"application/json"}}]) + mock = Minitest::Mock.new.expect :call, response do | verb, route, body, headers: | + verb == :post && route == '/api/4.0/users' && body.empty? && headers == {:content_type=>"application/json"} + end with_stub(Sawyer::Agent, :new, mock) do sdk.create_user() mock.verify @@ -112,7 +127,10 @@ def delete_response end it "patch" do - mock = MiniTest::Mock.new.expect(:call, response, [:patch, '/api/4.0/users/25', {first_name:'Jim'}, {:headers=>{:content_type=>"application/json"}}]) + #mock = Minitest::Mock.new.expect(:call, response, [:patch, '/api/4.0/users/25', {first_name:'Jim'}, {:headers=>{:content_type=>"application/json"}}]) + mock = Minitest::Mock.new.expect :call, response do | verb, route, body, headers: | + verb == :patch && route == '/api/4.0/users/25' && body == {first_name:'Jim'} && headers == {:content_type=>"application/json"} + end with_stub(Sawyer::Agent, :new, mock) do sdk.update_user(25, {first_name:'Jim'}) mock.verify @@ -120,7 +138,10 @@ def delete_response end it "put" do - mock = MiniTest::Mock.new.expect(:call, response, [:put, '/api/4.0/users/25/roles', [10, 20], {:headers=>{:content_type=>"application/json"}}]) + #mock = Minitest::Mock.new.expect(:call, response, [:put, '/api/4.0/users/25/roles', [10, 20], {:headers=>{:content_type=>"application/json"}}]) + mock = Minitest::Mock.new.expect :call, response do | verb, route, body, headers: | + verb == :put && route == '/api/4.0/users/25/roles' && body == [10, 20] && headers == {:content_type=>"application/json"} + end with_stub(Sawyer::Agent, :new, mock) do sdk.set_user_roles(25, [10,20]) mock.verify @@ -128,7 +149,7 @@ def delete_response end it "put with nil body" do - mock = MiniTest::Mock.new.expect(:call, response, [:put, '/api/4.0/users/25/roles', nil, {}]) + mock = Minitest::Mock.new.expect(:call, response, [:put, '/api/4.0/users/25/roles', nil]) with_stub(Sawyer::Agent, :new, mock) do sdk.set_user_roles(25, nil) mock.verify @@ -136,7 +157,10 @@ def delete_response end it "put with empty body" do - mock = MiniTest::Mock.new.expect(:call, response, [:put, '/api/4.0/users/25/roles', {}, {:headers=>{:content_type=>"application/json"}}]) + #mock = Minitest::Mock.new.expect(:call, response, [:put, '/api/4.0/users/25/roles', {}, {:headers=>{:content_type=>"application/json"}}]) + mock = Minitest::Mock.new.expect :call, response do | verb, route, body, headers: | + verb == :put && route == '/api/4.0/users/25/roles' && body.empty? && headers == {:content_type=>"application/json"} + end with_stub(Sawyer::Agent, :new, mock) do sdk.set_user_roles(25, {}) mock.verify @@ -144,7 +168,7 @@ def delete_response end it "delete" do - mock = MiniTest::Mock.new.expect(:call, delete_response, [:delete, '/api/4.0/users/25', nil, {}]) + mock = Minitest::Mock.new.expect(:call, delete_response, [:delete, '/api/4.0/users/25', nil]) with_stub(Sawyer::Agent, :new, mock) do sdk.delete_user(25) mock.verify