From 0c828140f435973c25839f7032a05f82343a6576 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 7 Feb 2023 02:55:45 +0000 Subject: [PATCH 1/3] Update rspec requirement from ~> 2.13.0 to ~> 3.12.0 Updates the requirements on [rspec](https://github.com/rspec/rspec-metagem) to permit the latest version. - [Release notes](https://github.com/rspec/rspec-metagem/releases) - [Commits](https://github.com/rspec/rspec-metagem/compare/v2.13.0...v3.12.0) --- updated-dependencies: - dependency-name: rspec dependency-type: direct:development ... Signed-off-by: dependabot[bot] --- trino-client.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/trino-client.gemspec b/trino-client.gemspec index e06fe590..9fa2dc2a 100644 --- a/trino-client.gemspec +++ b/trino-client.gemspec @@ -22,7 +22,7 @@ Gem::Specification.new do |gem| gem.add_dependency "msgpack", [">= 1.5.1"] gem.add_development_dependency "rake", [">= 0.9.2", "< 11.0"] - gem.add_development_dependency "rspec", ["~> 2.13.0"] + gem.add_development_dependency "rspec", "~> 3.12.0" gem.add_development_dependency "webmock", ["~> 3.0"] gem.add_development_dependency "addressable", "~> 2.8.1" # 2.5.0 doesn't support Ruby 1.9.3 gem.add_development_dependency "simplecov", "~> 0.22.0" From 7354526411a61522557d7ce01ae7e136b4bfe4de Mon Sep 17 00:00:00 2001 From: TATSUNO Yasuhiro Date: Tue, 21 Feb 2023 17:20:58 +0900 Subject: [PATCH 2/3] Bump rake so it works with rspec 3.x --- trino-client.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/trino-client.gemspec b/trino-client.gemspec index 9fa2dc2a..0d085720 100644 --- a/trino-client.gemspec +++ b/trino-client.gemspec @@ -21,7 +21,7 @@ Gem::Specification.new do |gem| gem.add_dependency "faraday_middleware", ["~> 1.0"] gem.add_dependency "msgpack", [">= 1.5.1"] - gem.add_development_dependency "rake", [">= 0.9.2", "< 11.0"] + gem.add_development_dependency "rake", [">= 0.9.2", "< 14.0"] gem.add_development_dependency "rspec", "~> 3.12.0" gem.add_development_dependency "webmock", ["~> 3.0"] gem.add_development_dependency "addressable", "~> 2.8.1" # 2.5.0 doesn't support Ruby 1.9.3 From 9c22bb0294ddeee4860c1fb4bd3ef7738d361a7b Mon Sep 17 00:00:00 2001 From: TATSUNO Yasuhiro Date: Tue, 21 Feb 2023 17:26:41 +0900 Subject: [PATCH 3/3] Migrate legacy "should" to "expect" --- spec/client_spec.rb | 32 +++++----- spec/model_spec.rb | 6 +- spec/statement_client_spec.rb | 116 +++++++++++++++++----------------- 3 files changed, 78 insertions(+), 76 deletions(-) diff --git a/spec/client_spec.rb b/spec/client_spec.rb index 4621c373..cb163b81 100644 --- a/spec/client_spec.rb +++ b/spec/client_spec.rb @@ -22,23 +22,23 @@ rehashed = client.run_with_names('fake query') - rehashed.length.should == 3 + expect(rehashed.length).to eq 3 - rehashed[0]['animal'].should == 'dog' - rehashed[0]['score'].should == 1 - rehashed[0]['name'].should == 'Lassie' + expect(rehashed[0]['animal']).to eq 'dog' + expect(rehashed[0]['score']).to eq 1 + expect(rehashed[0]['name']).to eq 'Lassie' - rehashed[0].values[0].should == 'dog' - rehashed[0].values[1].should == 1 - rehashed[0].values[2].should == 'Lassie' + expect(rehashed[0].values[0]).to eq 'dog' + expect(rehashed[0].values[1]).to eq 1 + expect(rehashed[0].values[2]).to eq 'Lassie' - rehashed[1]['animal'].should == 'horse' - rehashed[1]['score'].should == 5 - rehashed[1]['name'].should == 'Mr. Ed' + expect(rehashed[1]['animal']).to eq 'horse' + expect(rehashed[1]['score']).to eq 5 + expect(rehashed[1]['name']).to eq 'Mr. Ed' - rehashed[1].values[0].should == 'horse' - rehashed[1].values[1].should == 5 - rehashed[1].values[2].should == 'Mr. Ed' + expect(rehashed[1].values[0]).to eq 'horse' + expect(rehashed[1].values[1]).to eq 5 + expect(rehashed[1].values[2]).to eq 'Mr. Ed' end it 'empty results' do @@ -47,14 +47,14 @@ rehashed = client.run_with_names('fake query') - rehashed.length.should == 0 + expect(rehashed.length).to eq 0 end it 'handles too few result columns' do rows = [['wrong', 'count']] client.stub(:run).and_return([columns, rows]) - client.run_with_names('fake query').should == [{ + expect(client.run_with_names('fake query')).to eq [{ "animal" => "wrong", "score" => "count", "name" => nil, @@ -65,7 +65,7 @@ rows = [['wrong', 'count', 'too', 'much', 'columns']] client.stub(:run).and_return([columns, rows]) - client.run_with_names('fake query').should == [{ + expect(client.run_with_names('fake query')).to eq [{ "animal" => "wrong", "score" => "count", "name" => 'too', diff --git a/spec/model_spec.rb b/spec/model_spec.rb index 5f6cadb6..e8d1a8d9 100644 --- a/spec/model_spec.rb +++ b/spec/model_spec.rb @@ -29,7 +29,9 @@ "info" => {"k" => "v"} } - stats = Models::OperatorStats.decode(h) - stats.blocked_reason.should == :waiting_for_memory + it 'decode blocked_reason' do + stats = Models::OperatorStats.decode(h) + expect(stats.blocked_reason).to eq :waiting_for_memory + end end end diff --git a/spec/statement_client_spec.rb b/spec/statement_client_spec.rb index ad1bf34f..17805d23 100644 --- a/spec/statement_client_spec.rb +++ b/spec/statement_client_spec.rb @@ -76,9 +76,9 @@ }).to_return(body: lambda { |req| if retry_p; response_json.to_json; else; retry_p = true; raise Timeout::Error.new("execution expired"); end }) sc = StatementClient.new(faraday, query, options.merge(http_open_timeout: 1)) - sc.has_next?.should be_true - sc.advance.should be_true - retry_p.should be_true + expect(sc.has_next?).to eq true + expect(sc.advance).to eq true + expect(retry_p).to eq true end it "uses 'Accept: application/x-msgpack' if option is set" do @@ -108,9 +108,9 @@ options.merge!(http_open_timeout: 1, enable_x_msgpack: "application/x-msgpack") sc = StatementClient.new(faraday, query, options) - sc.has_next?.should be_true - sc.advance.should be_true - retry_p.should be_true + expect(sc.has_next?).to eq true + expect(sc.advance).to eq true + expect(retry_p).to eq true end # trino version could be "V0_ddd" or "Vddd" @@ -127,17 +127,17 @@ "connectorHandle" => {} } }) - dh.handle.should be_a_kind_of Models::TableHandle - dh.handle.connector_id.should == "c1" - dh.handle.connector_handle.should == {} + expect(dh.handle).to be_a_kind_of Models::TableHandle + expect(dh.handle.connector_id).to eq "c1" + expect(dh.handle.connector_handle).to eq {} end it "validates models" do - lambda do + expect do Models::DeleteHandle.decode({ "handle" => "invalid" }) - end.should raise_error(TypeError, /String to Hash/) + end.to raise_error(TypeError, /String to Hash/) end else it "decodes DeleteTarget" do @@ -147,18 +147,18 @@ "connectorHandle" => {} } }) - dh.handle.should be_a_kind_of Models::TableHandle - dh.handle.catalog_name.should == "c1" - dh.handle.connector_handle.should == {} + expect(dh.handle).to be_a_kind_of(Models::TableHandle) + expect(dh.handle.catalog_name).to eq "c1" + expect(dh.handle.connector_handle).to eq({}) end it "validates models" do - lambda do + expect do Models::DeleteTarget.decode({ "catalogName" => "c1", "handle" => "invalid" }) - end.should raise_error(TypeError, /String to Hash/) + end.to raise_error(TypeError, /String to Hash/) end end @@ -167,7 +167,7 @@ with(body: query).to_return(body: response_json2.to_json, headers: {"X-Test-Header" => "123"}) sc = StatementClient.new(faraday, query, options.merge(http_open_timeout: 1)) - sc.current_results_headers["X-Test-Header"].should == "123" + expect(sc.current_results_headers["X-Test-Header"]).to eq "123" end it "receives headers of POST through Query" do @@ -175,7 +175,7 @@ with(body: query).to_return(body: response_json2.to_json, headers: {"X-Test-Header" => "123"}) q = Trino::Client.new(options).query(query) - q.current_results_headers["X-Test-Header"].should == "123" + expect(q.current_results_headers["X-Test-Header"]).to eq "123" end describe "#query_id" do @@ -187,10 +187,10 @@ to_return(body: response_json.to_json, headers: {"X-Test-Header" => "123"}) sc = StatementClient.new(faraday, query, options.merge(http_open_timeout: 1)) - sc.query_id.should == "queryid" - sc.has_next?.should be_true - sc.advance.should be_true - sc.query_id.should == "queryid" + expect(sc.query_id).to eq "queryid" + expect(sc.has_next?).to eq true + expect(sc.advance).to eq true + expect(sc.query_id).to eq "queryid" end end @@ -214,21 +214,21 @@ end it "raises an exception with sample JSON if response is unexpected" do - lambda do + expect do stub_request(:get, "http://localhost/v1/query/#{response_json2[:id]}"). with(headers: headers). to_return(body: {"session" => "invalid session structure"}.to_json) statement_client.query_info - end.should raise_error(TrinoHttpError, /Trino API returned unexpected structure at \/v1\/query\/queryid\. Expected Trino::Client::ModelVersions::.*::QueryInfo but got {"session":"invalid session structure"}/) + end.to raise_error(TrinoHttpError, /Trino API returned unexpected structure at \/v1\/query\/queryid\. Expected Trino::Client::ModelVersions::.*::QueryInfo but got {"session":"invalid session structure"}/) end it "raises an exception if response format is unexpected" do - lambda do + expect do stub_request(:get, "http://localhost/v1/query/#{response_json2[:id]}"). with(headers: headers). to_return(body: "unexpected data structure (not JSON)") statement_client.query_info - end.should raise_error(TrinoHttpError, /Trino API returned unexpected data format./) + end.to raise_error(TrinoHttpError, /Trino API returned unexpected data format./) end it "is redirected if server returned 301" do @@ -241,7 +241,7 @@ to_return(body: {"queryId" => "queryid"}.to_json) query_info = statement_client.query_info - query_info.query_id.should == "queryid" + expect(query_info.query_id).to eq "queryid" end end @@ -345,12 +345,12 @@ end it "forbids using basic auth when ssl is disabled" do - lambda do + expect do Query.__send__(:faraday_client, { server: 'localhost', password: 'abcd' }) - end.should raise_error(ArgumentError) + end.to raise_error(ArgumentError) end end @@ -359,7 +359,7 @@ f = Query.__send__(:faraday_client, { server: "localhost", }) - f.url_prefix.to_s.should == "http://localhost/" + expect(f.url_prefix.to_s).to eq "http://localhost/" end it "is enabled with ssl: true" do @@ -367,8 +367,8 @@ server: "localhost", ssl: true, }) - f.url_prefix.to_s.should == "https://localhost/" - f.ssl.verify?.should == true + expect(f.url_prefix.to_s).to eq "https://localhost/" + expect(f.ssl.verify?).to eq true end it "is enabled with ssl: {verify: false}" do @@ -376,17 +376,17 @@ server: "localhost", ssl: {verify: false} }) - f.url_prefix.to_s.should == "https://localhost/" - f.ssl.verify?.should == false + expect(f.url_prefix.to_s).to eq "https://localhost/" + expect(f.ssl.verify?).to eq false end it "rejects invalid ssl: verify: object" do - lambda do + expect do f = Query.__send__(:faraday_client, { server: "localhost", ssl: {verify: "??"} }) - end.should raise_error(ArgumentError, /String/) + end.to raise_error(ArgumentError, /String/) end it "is enabled with ssl: Hash" do @@ -405,31 +405,31 @@ ssl: ssl, }) - f.url_prefix.to_s.should == "https://localhost/" - f.ssl.verify?.should == true - f.ssl.ca_file.should == ssl[:ca_file] - f.ssl.ca_path.should == ssl[:ca_path] - f.ssl.cert_store.should == ssl[:cert_store] - f.ssl.client_cert.should == ssl[:client_cert] - f.ssl.client_key.should == ssl[:client_key] + expect(f.url_prefix.to_s).to eq "https://localhost/" + expect(f.ssl.verify?).to eq true + expect(f.ssl.ca_file).to eq ssl[:ca_file] + expect(f.ssl.ca_path).to eq ssl[:ca_path] + expect(f.ssl.cert_store).to eq ssl[:cert_store] + expect(f.ssl.client_cert).to eq ssl[:client_cert] + expect(f.ssl.client_key).to eq ssl[:client_key] end it "rejects an invalid string" do - lambda do + expect do Query.__send__(:faraday_client, { server: "localhost", ssl: '??', }) - end.should raise_error(ArgumentError, /String/) + end.to raise_error(ArgumentError, /String/) end it "rejects an integer" do - lambda do + expect do Query.__send__(:faraday_client, { server: "localhost", ssl: 3, }) - end.should raise_error(ArgumentError, /:ssl/) + end.to raise_error(ArgumentError, /:ssl/) end end @@ -440,13 +440,13 @@ faraday = Faraday.new(url: "http://localhost") client = StatementClient.new(faraday, query, options.merge(model_version: "316")) - client.current_results.should be_a_kind_of(ModelVersions::V316::QueryResults) + expect(client.current_results).to be_a_kind_of(ModelVersions::V316::QueryResults) end it "rejects unsupported model version" do - lambda do + expect do StatementClient.new(faraday, query, options.merge(model_version: "0.111")) - end.should raise_error(NameError) + end.to raise_error(NameError) end let :nested_json do @@ -543,9 +543,9 @@ stub_request(:get, "localhost/v1/next_uri"). with(headers: headers). to_return(body: planning_response.to_json) - lambda do + expect do client.advance - end.should raise_error(Trino::Client::TrinoQueryTimeoutError, "Query queryid timed out") + end.to raise_error(Trino::Client::TrinoQueryTimeoutError, "Query queryid timed out") end it "raises TrinoQueryTimeoutError if timeout during initial resuming" do @@ -553,9 +553,9 @@ with(headers: headers). to_return(body: lambda { |req| raise Timeout::Error.new("execution expired") }) - lambda do + expect do StatementClient.new(faraday, query, options.merge(timeout_type => 1), "/v1/next_uri") - end.should raise_error(Trino::Client::TrinoQueryTimeoutError, "Query timed out") + end.to raise_error(Trino::Client::TrinoQueryTimeoutError, "Query timed out") end it "raises TrinoHttpError if timeout during initial resuming and #{timeout_type} < retry_timeout" do @@ -563,9 +563,9 @@ with(headers: headers). to_return(body: lambda { |req| raise Timeout::Error.new("execution expired") }) - lambda do + expect do StatementClient.new(faraday, query, options.merge(timeout_type => 2, retry_timeout: 1), "/v1/next_uri") - end.should raise_error(Trino::Client::TrinoHttpError, "Trino API error due to timeout") + end.to raise_error(Trino::Client::TrinoHttpError, "Trino API error due to timeout") end end @@ -605,9 +605,9 @@ stub_request(:get, "localhost/v1/next_uri"). with(headers: headers). to_return(body: late_running_response.to_json) - lambda do + expect do client.advance - end.should raise_error(Trino::Client::TrinoQueryTimeoutError, "Query queryid timed out") + end.to raise_error(Trino::Client::TrinoQueryTimeoutError, "Query queryid timed out") end it "doesn't raise errors if query is done" do