From ea071780747626463f7641aaeb329e460418f441 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?KARASZI=20Istv=C3=A1n?= Date: Tue, 14 Dec 2021 09:49:23 +0100 Subject: [PATCH 01/15] Add rubocop recommended change --- mrkt.gemspec | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mrkt.gemspec b/mrkt.gemspec index 6812910..7015941 100644 --- a/mrkt.gemspec +++ b/mrkt.gemspec @@ -17,6 +17,8 @@ Gem::Specification.new do |spec| spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = %w[lib] + spec.metadata['rubygems_mfa_required'] = 'true' + spec.required_ruby_version = '>= 2.5' spec.add_dependency 'faraday', '~> 1.0' From dfff5c06cce5ddc4e2f140d8d7c7ecd8a2587559 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?KARASZI=20Istv=C3=A1n?= Date: Tue, 14 Dec 2021 09:49:37 +0100 Subject: [PATCH 02/15] Add rubocop-rspec to the dev dependencies --- Gemfile.lock | 3 +++ mrkt.gemspec | 1 + 2 files changed, 4 insertions(+) diff --git a/Gemfile.lock b/Gemfile.lock index 2b9e192..9d87f31 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -82,6 +82,8 @@ GEM parser (>= 3.0.1.1) rubocop-rake (0.6.0) rubocop (~> 1.0) + rubocop-rspec (2.6.0) + rubocop (~> 1.19) ruby-progressbar (1.11.0) ruby2_keywords (0.0.5) simplecov (0.21.2) @@ -108,6 +110,7 @@ DEPENDENCIES rspec (~> 3.2) rubocop (~> 1.23.0) rubocop-rake (~> 0.6.0) + rubocop-rspec (~> 2.6) simplecov (~> 0.21.2) webmock (~> 3.1) diff --git a/mrkt.gemspec b/mrkt.gemspec index 7015941..9d85e6f 100644 --- a/mrkt.gemspec +++ b/mrkt.gemspec @@ -31,6 +31,7 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'rspec', '~> 3.2' spec.add_development_dependency 'rubocop', '~> 1.23.0' spec.add_development_dependency 'rubocop-rake', '~> 0.6.0' + spec.add_development_dependency 'rubocop-rspec', '~> 2.6' spec.add_development_dependency 'simplecov', '~> 0.21.2' spec.add_development_dependency 'webmock', '~> 3.1' end From 292a48eb3cc1bd3077fb3601cfe16ac5a6ab1a9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?KARASZI=20Istv=C3=A1n?= Date: Tue, 14 Dec 2021 09:50:42 +0100 Subject: [PATCH 03/15] Exclude gemspec from Metrics/BlockLength --- .rubocop.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.rubocop.yml b/.rubocop.yml index 8df0472..c909057 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -24,6 +24,7 @@ Metrics/AbcSize: Metrics/BlockLength: Exclude: - 'spec/**/*' + - '**/*.gemspec' Metrics/MethodLength: Max: 20 Metrics/ParameterLists: From 74a063da55832a44f900af06a92cc17bf96755ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?KARASZI=20Istv=C3=A1n?= Date: Tue, 14 Dec 2021 09:51:38 +0100 Subject: [PATCH 04/15] Fix RuboCop issue --- lib/mrkt/concerns/crud_program_members.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mrkt/concerns/crud_program_members.rb b/lib/mrkt/concerns/crud_program_members.rb index 982daaa..7b73cec 100644 --- a/lib/mrkt/concerns/crud_program_members.rb +++ b/lib/mrkt/concerns/crud_program_members.rb @@ -6,7 +6,7 @@ def describe_program_members def createupdate_program_members(program_id, lead_ids, status) post_json("/rest/v1/programs/#{program_id}/members/status.json") do - params = { + { statusName: status, input: lead_ids.map { |lead_id| { leadId: lead_id } } } From fd2d9b40d1031fe8a2b9e372161b1ca444cdfcac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?KARASZI=20Istv=C3=A1n?= Date: Tue, 14 Dec 2021 09:56:05 +0100 Subject: [PATCH 05/15] Require rubocop-rspec --- .rubocop.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.rubocop.yml b/.rubocop.yml index c909057..e5a8548 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,4 +1,6 @@ -require: rubocop-rake +require: + - rubocop-rake + - rubocop-rspec AllCops: TargetRubyVersion: 2.5 From f9f59b9de7354dd4dbdf4d9d6ec00a9034004f5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?KARASZI=20Istv=C3=A1n?= Date: Tue, 14 Dec 2021 09:57:10 +0100 Subject: [PATCH 06/15] Autocorrect rubocop-rspec issues --- spec/concerns/authentication_spec.rb | 26 +++++++++---------- spec/concerns/crud_activities_spec.rb | 23 ++++++++++------ spec/concerns/crud_asset_folders_spec.rb | 8 +++--- spec/concerns/crud_asset_static_lists_spec.rb | 2 +- spec/concerns/crud_campaigns_spec.rb | 7 ++--- spec/concerns/crud_custom_activities_spec.rb | 25 +++++++++--------- spec/concerns/crud_custom_objects_spec.rb | 26 +++++++++---------- spec/concerns/crud_leads_spec.rb | 25 ++++++++++-------- spec/concerns/crud_lists_spec.rb | 10 ++++--- spec/concerns/crud_program_members_spec.rb | 9 ++++--- spec/concerns/crud_programs_spec.rb | 8 +++--- spec/concerns/import_custom_objects_spec.rb | 12 ++++++--- spec/concerns/import_leads_spec.rb | 12 ++++++--- spec/errors_spec.rb | 4 +-- spec/faraday/params_encoder_spec.rb | 8 +++--- spec/support/initialized_client.rb | 4 +-- 16 files changed, 116 insertions(+), 93 deletions(-) diff --git a/spec/concerns/authentication_spec.rb b/spec/concerns/authentication_spec.rb index 5608fab..2d58bd3 100644 --- a/spec/concerns/authentication_spec.rb +++ b/spec/concerns/authentication_spec.rb @@ -16,20 +16,22 @@ } end - it 'should raise an Error' do + it 'raises an Error' do expect { subject }.to raise_error(Mrkt::Errors::Error, 'Bad client credentials') end end end describe '#authenticate!' do - it 'should authenticate and then be authenticated?' do - expect(client.authenticated?).to_not be true + it 'authenticates and then be authenticated?' do + expect(client.authenticated?).not_to be true client.authenticate! expect(client.authenticated?).to be true end context 'with optional partner_id client option' do + subject(:client) { Mrkt::Client.new(client_options) } + before { remove_request_stub(@authentication_request_stub) } let(:partner_id) { SecureRandom.uuid } @@ -52,22 +54,22 @@ } end - subject(:client) { Mrkt::Client.new(client_options) } - before do stub_request(:get, "https://#{host}/identity/oauth/token") .with(query: query) .to_return(json_stub(authentication_stub)) end - it 'should authenticate and then be authenticated?' do - expect(client.authenticated?).to_not be true + it 'authenticates and then be authenticated?' do + expect(client.authenticated?).not_to be true client.authenticate! expect(client.authenticated?).to be true end end context 'when the token has expired and @retry_authentication = true' do + subject(:client) { Mrkt::Client.new(client_options) } + before { remove_request_stub(@authentication_request_stub) } let(:retry_count) { 3 } @@ -90,8 +92,6 @@ } end - subject(:client) { Mrkt::Client.new(client_options) } - before do stub_request(:get, "https://#{host}/identity/oauth/token") .with(query: { client_id: client_id, client_secret: client_secret, grant_type: 'client_credentials' }) @@ -99,8 +99,8 @@ .to_return(json_stub(valid_authentication_stub)) end - it 'should retry until getting valid token and then be authenticated?' do - expect(client.authenticated?).to_not be true + it 'retries until getting valid token and then be authenticated?' do + expect(client.authenticated?).not_to be true client.authenticate! expect(client.authenticated?).to be true end @@ -108,8 +108,8 @@ context 'when retry_authentication_count is low' do let(:retry_count) { 2 } - it 'should stop retrying after @retry_authentication_count tries and then raise an error' do - expect(client.authenticated?).to_not be true + it 'stops retrying after @retry_authentication_count tries and then raise an error' do + expect(client.authenticated?).not_to be true expect { client.authenticate! }.to raise_error(Mrkt::Errors::Error, 'Client not authenticated') end diff --git a/spec/concerns/crud_activities_spec.rb b/spec/concerns/crud_activities_spec.rb index 6cb0fcb..b680db4 100644 --- a/spec/concerns/crud_activities_spec.rb +++ b/spec/concerns/crud_activities_spec.rb @@ -2,6 +2,8 @@ include_context 'initialized client' describe '#get_activity_types' do + subject { client.get_activity_types } + let(:response_stub) do { requestId: 'c245#14cd6830ae2', @@ -29,7 +31,6 @@ success: true } end - subject { client.get_activity_types } before do stub_request(:get, "https://#{host}/rest/v1/activities/types.json") @@ -40,6 +41,8 @@ end describe '#get_paging_token' do + subject { client.get_paging_token(since_datetime) } + let(:since_datetime) { Time.utc(2017, 1, 1, 4, 30) } let(:response_stub) do { @@ -48,7 +51,6 @@ nextPageToken: '4GAX7YNCIJKO2VAED5LH5PQIYPUM7WCVKTQWEDMP2L24AXZT54LA====' } end - subject { client.get_paging_token(since_datetime) } before do stub_request(:get, "https://#{host}/rest/v1/activities/pagingtoken.json") @@ -60,6 +62,8 @@ end describe '#get_activities' do + subject { client.get_activities(token) } + let(:activity_type_ids) { [1, 2] } let(:lead_ids) { [100, 102] } let(:token) { '4GAX7YNCIJKO2VAED5LH5PQIYPUM7WCVKTQWEDMP2L24AXZT54LA====' } @@ -106,7 +110,6 @@ moreResult: false } end - subject { client.get_activities(token) } before do stub_request(:get, "https://#{host}/rest/v1/activities.json") @@ -117,6 +120,8 @@ it { is_expected.to eq(response_stub) } context 'specifying activity type ids' do + subject { client.get_activities(token, activity_type_ids: activity_type_ids) } + let(:response_stub) do { data: { @@ -147,7 +152,6 @@ moreResult: false } end - subject { client.get_activities(token, activity_type_ids: activity_type_ids) } before do stub_request(:get, "https://#{host}/rest/v1/activities.json") @@ -162,6 +166,8 @@ end context 'specifying lead ids' do + subject { client.get_activities(token, lead_ids: lead_ids) } + let(:response_stub) do { data: { @@ -192,7 +198,6 @@ moreResult: false } end - subject { client.get_activities(token, lead_ids: lead_ids) } before do stub_request(:get, "https://#{host}/rest/v1/activities.json") @@ -204,12 +209,13 @@ end context 'specifying arrays values as empty strings' do - let(:activity_type_ids) { '' } - let(:lead_ids) { '' } subject do client.get_activities(token, activity_type_ids: activity_type_ids, lead_ids: lead_ids) end + let(:activity_type_ids) { '' } + let(:lead_ids) { '' } + before do stub_request(:get, "https://#{host}/rest/v1/activities.json") .with(query: { nextPageToken: token }) @@ -239,6 +245,8 @@ end describe '#get_deleted_leads' do + subject { client.get_deleted_leads(token) } + let(:token) { '4GAX7YNCIJKO2VAED5LH5PQIYPUM7WCVKTQWEDMP2L24AXZT54LA====' } let(:response_stub) do { @@ -266,7 +274,6 @@ moreResult: false } end - subject { client.get_deleted_leads(token) } before do stub_request(:get, "https://#{host}/rest/v1/activities/deletedleads.json") diff --git a/spec/concerns/crud_asset_folders_spec.rb b/spec/concerns/crud_asset_folders_spec.rb index 9141889..fdf298b 100644 --- a/spec/concerns/crud_asset_folders_spec.rb +++ b/spec/concerns/crud_asset_folders_spec.rb @@ -123,7 +123,7 @@ } end - it 'should raise an Error' do + it 'raises an Error' do expect { subject }.to raise_error(Mrkt::Errors::TypeMismatch) end end @@ -196,7 +196,7 @@ } end - it 'should raise an Error' do + it 'raises an Error' do expect { subject }.to raise_error(Mrkt::Errors::System) end end @@ -216,7 +216,7 @@ } end - it 'should raise an Error' do + it 'raises an Error' do expect { subject }.to raise_error(Mrkt::Errors::UnspecifiedAction) end end @@ -265,7 +265,7 @@ } end - it 'should raise an Error' do + it 'raises an Error' do expect { subject }.to raise_error(Mrkt::Errors::RecordNotFound) end end diff --git a/spec/concerns/crud_asset_static_lists_spec.rb b/spec/concerns/crud_asset_static_lists_spec.rb index 66f58f2..6ee42f5 100644 --- a/spec/concerns/crud_asset_static_lists_spec.rb +++ b/spec/concerns/crud_asset_static_lists_spec.rb @@ -106,7 +106,7 @@ } end - it 'should raise an Error' do + it 'raises an Error' do expect { subject }.to raise_error(Mrkt::Errors::RecordNotFound) end end diff --git a/spec/concerns/crud_campaigns_spec.rb b/spec/concerns/crud_campaigns_spec.rb index 113c026..b24683a 100644 --- a/spec/concerns/crud_campaigns_spec.rb +++ b/spec/concerns/crud_campaigns_spec.rb @@ -2,6 +2,8 @@ include_context 'initialized client' describe '#request_campaign' do + subject { client.request_campaign(id, lead_ids, tokens) } + let(:id) { 42 } let(:lead_ids) { [1234, 5678] } let(:tokens) do @@ -13,7 +15,6 @@ value: 'Value for other token' }] end - subject { client.request_campaign(id, lead_ids, tokens) } before do stub_request(:post, "https://#{host}/rest/v1/campaigns/#{id}/trigger.json") @@ -33,7 +34,7 @@ } end - it 'should raise an Error' do + it 'raises an Error' do expect { subject }.to raise_error(Mrkt::Errors::ObjectNotFound) end end @@ -51,7 +52,7 @@ } end - it 'should raise an Error' do + it 'raises an Error' do expect { subject }.to raise_error(Mrkt::Errors::LeadNotFound) end end diff --git a/spec/concerns/crud_custom_activities_spec.rb b/spec/concerns/crud_custom_activities_spec.rb index 438f2ed..f960aa9 100644 --- a/spec/concerns/crud_custom_activities_spec.rb +++ b/spec/concerns/crud_custom_activities_spec.rb @@ -50,13 +50,13 @@ end context 'all activities' do + subject { client.get_list_of_custom_activity_types } + before do stub_request(:get, "https://#{host}/rest/v1/activities/types.json") .to_return(json_stub(response_stub)) end - subject { client.get_list_of_custom_activity_types } - it { is_expected.to eq(response_stub) } end end @@ -104,6 +104,8 @@ end context 'with no additional attributes' do + subject { client.create_custom_activity(lead_id, activity_type_id, primary_attribute_value, date: date) } + let(:request_body) do { input: [{ @@ -122,12 +124,14 @@ .to_return(json_stub(response_stub)) end - subject { client.create_custom_activity(lead_id, activity_type_id, primary_attribute_value, date: date) } - it { is_expected.to eq(response_stub) } end context 'with additional attributes' do + subject do + client.create_custom_activity(lead_id, activity_type_id, primary_attribute_value, attributes: attributes, date: date) + end + let(:request_body) do { input: [{ @@ -148,13 +152,6 @@ }] } end - - before do - stub_request(:post, "https://#{host}/rest/v1/activities/external.json") - .with(json_stub(request_body)) - .to_return(json_stub(response_stub)) - end - let(:attributes) do { percent: '0.20', @@ -162,8 +159,10 @@ } end - subject do - client.create_custom_activity(lead_id, activity_type_id, primary_attribute_value, attributes: attributes, date: date) + before do + stub_request(:post, "https://#{host}/rest/v1/activities/external.json") + .with(json_stub(request_body)) + .to_return(json_stub(response_stub)) end it { is_expected.to eq(response_stub) } diff --git a/spec/concerns/crud_custom_objects_spec.rb b/spec/concerns/crud_custom_objects_spec.rb index e999701..241a6b6 100644 --- a/spec/concerns/crud_custom_objects_spec.rb +++ b/spec/concerns/crud_custom_objects_spec.rb @@ -44,17 +44,19 @@ end context 'with no object names' do + subject { client.get_list_of_custom_objects } + before do stub_request(:get, "https://#{host}/rest/v1/customobjects.json") .to_return(json_stub(response_stub)) end - subject { client.get_list_of_custom_objects } - it { is_expected.to eq(response_stub) } end context 'with object names' do + subject { client.get_list_of_custom_objects(object_names) } + let(:object_names) { %w[device_c manufacturer_c] } before do @@ -63,13 +65,13 @@ .to_return(json_stub(response_stub)) end - subject { client.get_list_of_custom_objects(object_names) } - it { is_expected.to eq(response_stub) } end end describe '#describe_custom_object' do + subject { client.describe_custom_object(object_name) } + let(:response_stub) do { requestId: 'eeef#152858b17d2', @@ -129,8 +131,6 @@ .to_return(json_stub(response_stub)) end - subject { client.describe_custom_object(object_name) } - context 'when the object name is valid' do let(:object_name) { :device_c } @@ -140,13 +140,15 @@ context 'when the object name is invalid' do let(:object_name) { nil } - it 'should raise an Error' do + it 'raises an Error' do expect { subject }.to raise_error(Mrkt::Errors::Unknown) end end end describe '#createupdate_custom_objects' do + subject { client.createupdate_custom_objects(object_name, devices) } + let(:object_name) { 'device' } let(:devices) do @@ -178,8 +180,6 @@ } end - subject { client.createupdate_custom_objects(object_name, devices) } - before do stub_request(:post, "https://#{host}/rest/v1/customobjects/#{object_name}.json") .with(json_stub(request_body)) @@ -190,6 +190,8 @@ end describe '#delete_custom_objects' do + subject { client.delete_custom_objects(object_name, search_fields) } + let(:object_name) { 'device' } let(:search_fields) do @@ -215,8 +217,6 @@ } end - subject { client.delete_custom_objects(object_name, search_fields) } - before do stub_request(:post, "https://#{host}/rest/v1/customobjects/#{object_name}/delete.json") .with(json_stub(request_body)) @@ -227,6 +227,8 @@ end describe '#get_custom_objects' do + subject { client.get_custom_objects(object_name, filter_values) } + let(:object_name) { 'device' } let(:filter_values) do @@ -256,8 +258,6 @@ } end - subject { client.get_custom_objects(object_name, filter_values) } - before do stub_request(:post, "https://#{host}/rest/v1/customobjects/#{object_name}.json?_method=GET") .with(json_stub(request_body)) diff --git a/spec/concerns/crud_leads_spec.rb b/spec/concerns/crud_leads_spec.rb index 3f8bd43..5cdbb6b 100644 --- a/spec/concerns/crud_leads_spec.rb +++ b/spec/concerns/crud_leads_spec.rb @@ -56,6 +56,8 @@ end describe '#get_leads' do + subject { client.get_leads(filter_type, filter_values) } + let(:filter_type) { 'email' } let(:filter_values) { %w[user@example.com] } let(:response_stub) do @@ -74,7 +76,6 @@ success: true } end - subject { client.get_leads(filter_type, filter_values) } before do stub_request(:get, "https://#{host}/rest/v1/leads.json") @@ -86,6 +87,8 @@ end describe '#createupdate_leads' do + subject { client.createupdate_leads(leads, lookup_field: :email) } + let(:leads) do [ firstName: 'John', @@ -118,7 +121,6 @@ ] } end - subject { client.createupdate_leads(leads, lookup_field: :email) } before do stub_request(:post, "https://#{host}/rest/v1/leads.json") @@ -130,6 +132,8 @@ end describe '#delete_leads' do + subject { client.delete_leads(leads) } + let(:leads) { [1] } let(:request_body) do { @@ -147,7 +151,6 @@ success: true } end - subject { client.delete_leads(leads) } before do stub_request(:delete, "https://#{host}/rest/v1/leads.json") @@ -159,12 +162,12 @@ end describe '#associate_lead' do + subject { client.associate_lead(id, cookie) } + let(:id) { 1 } let(:cookie) { 'id:561-HYG-937&token:_mch-marketo.com-1427205775289-40768' } let(:request_stub) { {} } - subject { client.associate_lead(id, cookie) } - before do stub_request(:post, "https://#{host}/rest/v1/leads/#{id}/associate.json?#{URI.encode_www_form(cookie: cookie)}") .with(json_stub(request_stub)) @@ -197,19 +200,19 @@ } end - it 'should raise an Error' do + it 'raises an Error' do expect { subject }.to raise_error(Mrkt::Errors::LeadNotFound) end end end describe '#merge_leads' do + subject { client.merge_leads(id, losing_lead_ids) } + let(:id) { 1 } let(:losing_lead_ids) { [2, 3, 4] } let(:request_stub) { {} } - subject { client.merge_leads(id, losing_lead_ids) } - before do params = ::Faraday::Utils::ParamsHash.new params[:mergeInCRM] = false @@ -245,13 +248,15 @@ } end - it 'should raise an Error' do + it 'raises an Error' do expect { subject }.to raise_error(Mrkt::Errors::LeadNotFound) end end end describe '#describe_lead' do + subject { client.describe_lead } + let(:response_stub) do { requestId: '5c9e#169a68fa806', @@ -289,8 +294,6 @@ } end - subject { client.describe_lead } - before do stub_request(:get, "https://#{host}/rest/v1/leads/describe.json") .to_return(json_stub(response_stub)) diff --git a/spec/concerns/crud_lists_spec.rb b/spec/concerns/crud_lists_spec.rb index 054f251..3296fdc 100644 --- a/spec/concerns/crud_lists_spec.rb +++ b/spec/concerns/crud_lists_spec.rb @@ -2,6 +2,8 @@ include_context 'initialized client' describe '#get_leads_by_list' do + subject { client.get_leads_by_list(list_id) } + let(:list_id) { '1001' } let(:response_stub) do { @@ -20,8 +22,6 @@ } end - subject { client.get_leads_by_list(list_id) } - before do stub_request(:get, "https://#{host}/rest/v1/list/#{list_id}/leads.json") .with(query: {}) @@ -32,6 +32,8 @@ end describe '#add_leads_to_list' do + subject { client.add_leads_to_list(list_id, lead_ids) } + let(:list_id) { '1001' } let(:lead_ids) { ['1'] } let(:request_body) do @@ -53,7 +55,6 @@ success: true } end - subject { client.add_leads_to_list(list_id, lead_ids) } before do stub_request(:post, "https://#{host}/rest/v1/lists/#{list_id}/leads.json") @@ -65,6 +66,8 @@ end describe '#remove_leads_from_list' do + subject { client.remove_leads_from_list(list_id, lead_ids) } + let(:list_id) { '1001' } let(:lead_ids) { ['1'] } let(:request_body) do @@ -86,7 +89,6 @@ success: true } end - subject { client.remove_leads_from_list(list_id, lead_ids) } before do stub_request(:delete, "https://#{host}/rest/v1/lists/#{list_id}/leads.json") diff --git a/spec/concerns/crud_program_members_spec.rb b/spec/concerns/crud_program_members_spec.rb index d212c8e..6c9f267 100644 --- a/spec/concerns/crud_program_members_spec.rb +++ b/spec/concerns/crud_program_members_spec.rb @@ -2,6 +2,8 @@ include_context 'initialized client' describe '#describe_program_members' do + subject { client.describe_program_members } + let(:response_stub) do { requestId: 'c245#14cd6830ae2', @@ -38,7 +40,6 @@ success: true } end - subject { client.describe_program_members } before do stub_request(:get, "https://#{host}/rest/v1/programs/members/describe.json") @@ -49,6 +50,8 @@ end describe '#createupdate_program_members' do + subject { client.createupdate_program_members(program_id, lead_ids, status) } + let(:program_id) { 123 } let(:lead_ids) { [1, 2, 3] } let(:status) { 'Registered' } @@ -85,7 +88,6 @@ success: true } end - subject { client.createupdate_program_members(program_id, lead_ids, status) } before do stub_request(:post, "https://#{host}/rest/v1/programs/#{program_id}/members/status.json") @@ -97,6 +99,8 @@ end describe '#get_program_members' do + subject { client.get_program_members(program_id, filter_type, filter_values) } + let(:filter_type) { 'leadId' } let(:filter_values) { [1, 2] } let(:program_id) { 1014 } @@ -125,7 +129,6 @@ moreResult: false } end - subject { client.get_program_members(program_id, filter_type, filter_values) } before do stub_request(:get, "https://#{host}/rest/v1/programs/#{program_id}/members.json") diff --git a/spec/concerns/crud_programs_spec.rb b/spec/concerns/crud_programs_spec.rb index ee11d8b..52af631 100644 --- a/spec/concerns/crud_programs_spec.rb +++ b/spec/concerns/crud_programs_spec.rb @@ -2,6 +2,8 @@ include_context 'initialized client' describe '#browse_programs' do + subject { client.browse_programs } + let(:response_stub) do { success: true, @@ -30,8 +32,6 @@ } end - subject { client.browse_programs } - before do stub_request(:get, "https://#{host}/rest/asset/v1/programs.json") .to_return(json_stub(response_stub)) @@ -41,6 +41,8 @@ end describe '#get_program_by_id' do + subject { client.get_program_by_id(1107) } + let(:response_stub) do { success: true, @@ -76,8 +78,6 @@ } end - subject { client.get_program_by_id(1107) } - before do stub_request(:get, "https://#{host}/rest/asset/v1/program/1107.json") .to_return(json_stub(response_stub)) diff --git a/spec/concerns/import_custom_objects_spec.rb b/spec/concerns/import_custom_objects_spec.rb index 4075a81..94d190e 100644 --- a/spec/concerns/import_custom_objects_spec.rb +++ b/spec/concerns/import_custom_objects_spec.rb @@ -5,6 +5,8 @@ let(:custom_object) { 'car_c' } describe '#import_custom_object' do + subject { client.import_custom_object(file, custom_object) } + let(:file) { StringIO.new } let(:response_stub) do { @@ -19,7 +21,6 @@ ] } end - subject { client.import_custom_object(file, custom_object) } before do stub_request(:post, "https://#{host}/bulk/v1/customobjects/#{custom_object}/import.json") @@ -31,6 +32,8 @@ end describe '#import_custom_object_status' do + subject { client.import_custom_object_status(1, custom_object) } + let(:id) { 1 } let(:response_stub) do { @@ -51,7 +54,6 @@ success: true } end - subject { client.import_custom_object_status(1, custom_object) } before do stub_request(:get, "https://#{host}/bulk/v1/customobjects/#{custom_object}/import/#{id}/status.json") @@ -62,9 +64,10 @@ end describe '#import_custom_object_failures' do + subject { client.import_custom_object_failures(1, custom_object) } + let(:id) { 1 } let(:response_stub) { '' } - subject { client.import_custom_object_failures(1, custom_object) } before do stub_request(:get, "https://#{host}/bulk/v1/customobjects/#{custom_object}/import/#{id}/failures.json") @@ -75,9 +78,10 @@ end describe '#import_custom_object_warnings' do + subject { client.import_custom_object_warnings(1, custom_object) } + let(:id) { 1 } let(:response_stub) { '' } - subject { client.import_custom_object_warnings(1, custom_object) } before do stub_request(:get, "https://#{host}/bulk/v1/customobjects/#{custom_object}/import/#{id}/warnings.json") diff --git a/spec/concerns/import_leads_spec.rb b/spec/concerns/import_leads_spec.rb index b8c222a..0f9be33 100644 --- a/spec/concerns/import_leads_spec.rb +++ b/spec/concerns/import_leads_spec.rb @@ -5,6 +5,8 @@ include_context 'initialized client' describe '#import_lead' do + subject { client.import_lead(tempfile) } + let(:tempfile) { Tempfile.new(%w[import-leads csv]) } let(:response_stub) do { @@ -18,7 +20,6 @@ ] } end - subject { client.import_lead(tempfile) } before do CSV.open(tempfile, 'wb') do |csv| @@ -39,6 +40,8 @@ end describe '#import_lead_status' do + subject { client.import_lead_status(1) } + let(:id) { 1 } let(:response_stub) do { @@ -56,7 +59,6 @@ success: true } end - subject { client.import_lead_status(1) } before do stub_request(:get, "https://#{host}/bulk/v1/leads/batch/#{id}.json") @@ -67,9 +69,10 @@ end describe '#import_lead_failures' do + subject { client.import_lead_failures(1) } + let(:id) { 1 } let(:response_stub) { '' } - subject { client.import_lead_failures(1) } before do stub_request(:get, "https://#{host}/bulk/v1/leads/batch/#{id}/failures.json") @@ -80,9 +83,10 @@ end describe '#import_lead_warnings' do + subject { client.import_lead_warnings(1) } + let(:id) { 1 } let(:response_stub) { '' } - subject { client.import_lead_warnings(1) } before do stub_request(:get, "https://#{host}/bulk/v1/leads/batch/#{id}/warnings.json") diff --git a/spec/errors_spec.rb b/spec/errors_spec.rb index a23e0bc..7159a76 100644 --- a/spec/errors_spec.rb +++ b/spec/errors_spec.rb @@ -6,8 +6,8 @@ context 'known' do let(:code) { 413 } - it 'should return the mapped error class' do - is_expected.to eq(Mrkt::Errors::RequestEntityTooLarge) + it 'returns the mapped error class' do + expect(subject).to eq(Mrkt::Errors::RequestEntityTooLarge) end end diff --git a/spec/faraday/params_encoder_spec.rb b/spec/faraday/params_encoder_spec.rb index 5d192d7..081cadf 100644 --- a/spec/faraday/params_encoder_spec.rb +++ b/spec/faraday/params_encoder_spec.rb @@ -1,5 +1,7 @@ describe Mrkt::Faraday::ParamsEncoder do describe '.encode' do + subject { described_class.encode(params) } + let(:params) do { string: 'foobar', @@ -9,16 +11,14 @@ } end - subject { described_class.encode(params) } - it { is_expected.to eq(Faraday::Utils::ParamsHash.new.merge(params.merge(array: '1,2,3')).to_query) } end describe '.decode' do - let(:value) { 'foo=foo&bar=bar' } - subject { described_class.decode(value) } + let(:value) { 'foo=foo&bar=bar' } + it { is_expected.to eq('foo' => 'foo', 'bar' => 'bar') } end end diff --git a/spec/support/initialized_client.rb b/spec/support/initialized_client.rb index 3aa8e93..a6b00c1 100644 --- a/spec/support/initialized_client.rb +++ b/spec/support/initialized_client.rb @@ -2,6 +2,8 @@ require 'json' shared_context 'initialized client' do + subject(:client) { Mrkt::Client.new(host: host, client_id: client_id, client_secret: client_secret) } + let(:host) { '0-KBZ-0.mktorest.com' } let(:client_id) { SecureRandom.uuid } let(:client_secret) { SecureRandom.hex } @@ -9,8 +11,6 @@ { access_token: SecureRandom.uuid, token_type: 'bearer', expires_in: 2241, scope: 'RestClient' } end - subject(:client) { Mrkt::Client.new(host: host, client_id: client_id, client_secret: client_secret) } - before do @authentication_request_stub = stub_request(:get, "https://#{host}/identity/oauth/token") .with(query: { client_id: client_id, client_secret: client_secret, grant_type: 'client_credentials' }) From ad1c4581eb2ad1a110b890a14a703301da55df73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?KARASZI=20Istv=C3=A1n?= Date: Tue, 14 Dec 2021 10:24:35 +0100 Subject: [PATCH 07/15] Remove duplicate before actions --- spec/concerns/authentication_spec.rb | 30 ++++++++++++++-------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/spec/concerns/authentication_spec.rb b/spec/concerns/authentication_spec.rb index 2d58bd3..d7ab800 100644 --- a/spec/concerns/authentication_spec.rb +++ b/spec/concerns/authentication_spec.rb @@ -32,7 +32,13 @@ context 'with optional partner_id client option' do subject(:client) { Mrkt::Client.new(client_options) } - before { remove_request_stub(@authentication_request_stub) } + before do + remove_request_stub(@authentication_request_stub) + + stub_request(:get, "https://#{host}/identity/oauth/token") + .with(query: query) + .to_return(json_stub(authentication_stub)) + end let(:partner_id) { SecureRandom.uuid } @@ -54,12 +60,6 @@ } end - before do - stub_request(:get, "https://#{host}/identity/oauth/token") - .with(query: query) - .to_return(json_stub(authentication_stub)) - end - it 'authenticates and then be authenticated?' do expect(client.authenticated?).not_to be true client.authenticate! @@ -70,7 +70,14 @@ context 'when the token has expired and @retry_authentication = true' do subject(:client) { Mrkt::Client.new(client_options) } - before { remove_request_stub(@authentication_request_stub) } + before do + remove_request_stub(@authentication_request_stub) + + stub_request(:get, "https://#{host}/identity/oauth/token") + .with(query: { client_id: client_id, client_secret: client_secret, grant_type: 'client_credentials' }) + .to_return(json_stub(expired_authentication_stub)).times(3).then + .to_return(json_stub(valid_authentication_stub)) + end let(:retry_count) { 3 } @@ -92,13 +99,6 @@ } end - before do - stub_request(:get, "https://#{host}/identity/oauth/token") - .with(query: { client_id: client_id, client_secret: client_secret, grant_type: 'client_credentials' }) - .to_return(json_stub(expired_authentication_stub)).times(3).then - .to_return(json_stub(valid_authentication_stub)) - end - it 'retries until getting valid token and then be authenticated?' do expect(client.authenticated?).not_to be true client.authenticate! From ced2e2a164750c53af3ae0f6820a1bdfdcbb6508 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?KARASZI=20Istv=C3=A1n?= Date: Tue, 14 Dec 2021 10:26:14 +0100 Subject: [PATCH 08/15] Name subjects explicitly --- spec/concerns/authentication_spec.rb | 4 ++-- spec/concerns/crud_asset_folders_spec.rb | 14 +++++++------- spec/concerns/crud_asset_static_lists_spec.rb | 4 ++-- spec/concerns/crud_campaigns_spec.rb | 6 +++--- spec/concerns/crud_custom_objects_spec.rb | 4 ++-- spec/concerns/crud_leads_spec.rb | 8 ++++---- spec/errors_spec.rb | 4 ++-- 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/spec/concerns/authentication_spec.rb b/spec/concerns/authentication_spec.rb index d7ab800..454dc04 100644 --- a/spec/concerns/authentication_spec.rb +++ b/spec/concerns/authentication_spec.rb @@ -2,7 +2,7 @@ include_context 'initialized client' describe '#authenticate' do - subject { client.authenticate } + subject(:action) { client.authenticate } context 'on a successful response' do it { is_expected.to be_success } @@ -17,7 +17,7 @@ end it 'raises an Error' do - expect { subject }.to raise_error(Mrkt::Errors::Error, 'Bad client credentials') + expect { action }.to raise_error(Mrkt::Errors::Error, 'Bad client credentials') end end end diff --git a/spec/concerns/crud_asset_folders_spec.rb b/spec/concerns/crud_asset_folders_spec.rb index fdf298b..c895f22 100644 --- a/spec/concerns/crud_asset_folders_spec.rb +++ b/spec/concerns/crud_asset_folders_spec.rb @@ -65,7 +65,7 @@ end describe '#get_folder_by_id' do - subject { client.get_folder_by_id(id, type: type) } + subject(:action) { client.get_folder_by_id(id, type: type) } let(:id) { 77 } @@ -124,13 +124,13 @@ end it 'raises an Error' do - expect { subject }.to raise_error(Mrkt::Errors::TypeMismatch) + expect { action }.to raise_error(Mrkt::Errors::TypeMismatch) end end end describe '#get_folder_by_name' do - subject { client.get_folder_by_name(name, type: type, root: root, work_space: work_space) } + subject(:action) { client.get_folder_by_name(name, type: type, root: root, work_space: work_space) } let(:name) { 'Test Folder Name' } let(:type) { 'Folder' } @@ -197,7 +197,7 @@ end it 'raises an Error' do - expect { subject }.to raise_error(Mrkt::Errors::System) + expect { action }.to raise_error(Mrkt::Errors::System) end end @@ -217,13 +217,13 @@ end it 'raises an Error' do - expect { subject }.to raise_error(Mrkt::Errors::UnspecifiedAction) + expect { action }.to raise_error(Mrkt::Errors::UnspecifiedAction) end end end describe '#delete_folder' do - subject { client.delete_folder(id) } + subject(:action) { client.delete_folder(id) } let(:id) { 75 } @@ -266,7 +266,7 @@ end it 'raises an Error' do - expect { subject }.to raise_error(Mrkt::Errors::RecordNotFound) + expect { action }.to raise_error(Mrkt::Errors::RecordNotFound) end end end diff --git a/spec/concerns/crud_asset_static_lists_spec.rb b/spec/concerns/crud_asset_static_lists_spec.rb index 6ee42f5..195dbde 100644 --- a/spec/concerns/crud_asset_static_lists_spec.rb +++ b/spec/concerns/crud_asset_static_lists_spec.rb @@ -55,7 +55,7 @@ end describe '#get_static_list_by_id' do - subject { client.get_static_list_by_id(id) } + subject(:action) { client.get_static_list_by_id(id) } let(:id) { response_static_list_result[:id] } let(:response_stub) do @@ -107,7 +107,7 @@ end it 'raises an Error' do - expect { subject }.to raise_error(Mrkt::Errors::RecordNotFound) + expect { action }.to raise_error(Mrkt::Errors::RecordNotFound) end end end diff --git a/spec/concerns/crud_campaigns_spec.rb b/spec/concerns/crud_campaigns_spec.rb index b24683a..f9635ed 100644 --- a/spec/concerns/crud_campaigns_spec.rb +++ b/spec/concerns/crud_campaigns_spec.rb @@ -2,7 +2,7 @@ include_context 'initialized client' describe '#request_campaign' do - subject { client.request_campaign(id, lead_ids, tokens) } + subject(:action) { client.request_campaign(id, lead_ids, tokens) } let(:id) { 42 } let(:lead_ids) { [1234, 5678] } @@ -35,7 +35,7 @@ end it 'raises an Error' do - expect { subject }.to raise_error(Mrkt::Errors::ObjectNotFound) + expect { action }.to raise_error(Mrkt::Errors::ObjectNotFound) end end @@ -53,7 +53,7 @@ end it 'raises an Error' do - expect { subject }.to raise_error(Mrkt::Errors::LeadNotFound) + expect { action }.to raise_error(Mrkt::Errors::LeadNotFound) end end diff --git a/spec/concerns/crud_custom_objects_spec.rb b/spec/concerns/crud_custom_objects_spec.rb index 241a6b6..7792a00 100644 --- a/spec/concerns/crud_custom_objects_spec.rb +++ b/spec/concerns/crud_custom_objects_spec.rb @@ -70,7 +70,7 @@ end describe '#describe_custom_object' do - subject { client.describe_custom_object(object_name) } + subject(:action) { client.describe_custom_object(object_name) } let(:response_stub) do { @@ -141,7 +141,7 @@ let(:object_name) { nil } it 'raises an Error' do - expect { subject }.to raise_error(Mrkt::Errors::Unknown) + expect { action }.to raise_error(Mrkt::Errors::Unknown) end end end diff --git a/spec/concerns/crud_leads_spec.rb b/spec/concerns/crud_leads_spec.rb index 5cdbb6b..e8f28f9 100644 --- a/spec/concerns/crud_leads_spec.rb +++ b/spec/concerns/crud_leads_spec.rb @@ -162,7 +162,7 @@ end describe '#associate_lead' do - subject { client.associate_lead(id, cookie) } + subject(:action) { client.associate_lead(id, cookie) } let(:id) { 1 } let(:cookie) { 'id:561-HYG-937&token:_mch-marketo.com-1427205775289-40768' } @@ -201,13 +201,13 @@ end it 'raises an Error' do - expect { subject }.to raise_error(Mrkt::Errors::LeadNotFound) + expect { action }.to raise_error(Mrkt::Errors::LeadNotFound) end end end describe '#merge_leads' do - subject { client.merge_leads(id, losing_lead_ids) } + subject(:action) { client.merge_leads(id, losing_lead_ids) } let(:id) { 1 } let(:losing_lead_ids) { [2, 3, 4] } @@ -249,7 +249,7 @@ end it 'raises an Error' do - expect { subject }.to raise_error(Mrkt::Errors::LeadNotFound) + expect { action }.to raise_error(Mrkt::Errors::LeadNotFound) end end end diff --git a/spec/errors_spec.rb b/spec/errors_spec.rb index 7159a76..ad2373f 100644 --- a/spec/errors_spec.rb +++ b/spec/errors_spec.rb @@ -1,13 +1,13 @@ describe Mrkt::Errors do describe '.find_by_response_code' do - subject { described_class.find_by_response_code(code) } + subject(:actual) { described_class.find_by_response_code(code) } context 'when the code is' do context 'known' do let(:code) { 413 } it 'returns the mapped error class' do - expect(subject).to eq(Mrkt::Errors::RequestEntityTooLarge) + expect(actual).to eq(Mrkt::Errors::RequestEntityTooLarge) end end From e649ce87b3986fcf132afe5ace723c22a741ec70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?KARASZI=20Istv=C3=A1n?= Date: Tue, 14 Dec 2021 10:30:05 +0100 Subject: [PATCH 09/15] Rename contexts --- spec/concerns/authentication_spec.rb | 7 ++++--- spec/concerns/crud_activities_spec.rb | 8 ++++---- spec/concerns/crud_campaigns_spec.rb | 2 +- spec/concerns/crud_custom_activities_spec.rb | 2 +- spec/errors_spec.rb | 18 ++++++++---------- 5 files changed, 18 insertions(+), 19 deletions(-) diff --git a/spec/concerns/authentication_spec.rb b/spec/concerns/authentication_spec.rb index 454dc04..c67b4e0 100644 --- a/spec/concerns/authentication_spec.rb +++ b/spec/concerns/authentication_spec.rb @@ -4,7 +4,7 @@ describe '#authenticate' do subject(:action) { client.authenticate } - context 'on a successful response' do + context 'with on a successful response' do it { is_expected.to be_success } end @@ -25,6 +25,7 @@ describe '#authenticate!' do it 'authenticates and then be authenticated?' do expect(client.authenticated?).not_to be true + client.authenticate! expect(client.authenticated?).to be true end @@ -120,11 +121,11 @@ describe '#authenticated?' do subject { client.authenticated? } - context 'before authentication' do + context 'when authentication has not been done' do it { is_expected.to be_falsey } end - context 'after authentication' do + context 'when authentication has been done' do before { client.authenticate } it { is_expected.to be_truthy } diff --git a/spec/concerns/crud_activities_spec.rb b/spec/concerns/crud_activities_spec.rb index b680db4..485630e 100644 --- a/spec/concerns/crud_activities_spec.rb +++ b/spec/concerns/crud_activities_spec.rb @@ -119,7 +119,7 @@ it { is_expected.to eq(response_stub) } - context 'specifying activity type ids' do + context 'when specifying activity type ids' do subject { client.get_activities(token, activity_type_ids: activity_type_ids) } let(:response_stub) do @@ -165,7 +165,7 @@ it { is_expected.to eq(response_stub) } end - context 'specifying lead ids' do + context 'when specifying lead ids' do subject { client.get_activities(token, lead_ids: lead_ids) } let(:response_stub) do @@ -208,7 +208,7 @@ it { is_expected.to eq(response_stub) } end - context 'specifying arrays values as empty strings' do + context 'when specifying arrays values as empty strings' do subject do client.get_activities(token, activity_type_ids: activity_type_ids, lead_ids: lead_ids) end @@ -225,7 +225,7 @@ it { is_expected.to eq(response_stub) } end - context 'specifying all options' do + context 'when specifying all options' do subject do client.get_activities(token, activity_type_ids: activity_type_ids, lead_ids: lead_ids) end diff --git a/spec/concerns/crud_campaigns_spec.rb b/spec/concerns/crud_campaigns_spec.rb index f9635ed..dbc70c9 100644 --- a/spec/concerns/crud_campaigns_spec.rb +++ b/spec/concerns/crud_campaigns_spec.rb @@ -57,7 +57,7 @@ end end - context 'for valid lead ids' do + context 'with valid lead ids' do let(:response_stub) do { requestId: 'e42b#14272d07d78', diff --git a/spec/concerns/crud_custom_activities_spec.rb b/spec/concerns/crud_custom_activities_spec.rb index f960aa9..2e26d94 100644 --- a/spec/concerns/crud_custom_activities_spec.rb +++ b/spec/concerns/crud_custom_activities_spec.rb @@ -49,7 +49,7 @@ } end - context 'all activities' do + context 'with all activities' do subject { client.get_list_of_custom_activity_types } before do diff --git a/spec/errors_spec.rb b/spec/errors_spec.rb index ad2373f..c7b85c6 100644 --- a/spec/errors_spec.rb +++ b/spec/errors_spec.rb @@ -2,20 +2,18 @@ describe '.find_by_response_code' do subject(:actual) { described_class.find_by_response_code(code) } - context 'when the code is' do - context 'known' do - let(:code) { 413 } + context 'when the code is known' do + let(:code) { 413 } - it 'returns the mapped error class' do - expect(actual).to eq(Mrkt::Errors::RequestEntityTooLarge) - end + it 'returns the mapped error class' do + expect(actual).to eq(Mrkt::Errors::RequestEntityTooLarge) end + end - context 'unknown' do - let(:code) { 7331 } + context 'when the code is unknown' do + let(:code) { 7331 } - it { is_expected.to eq(Mrkt::Errors::Error) } - end + it { is_expected.to eq(Mrkt::Errors::Error) } end end end From ec8b7c9c4bd8af56623194ceddff9b239c34cf66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?KARASZI=20Istv=C3=A1n?= Date: Tue, 14 Dec 2021 10:33:12 +0100 Subject: [PATCH 10/15] Rephrase tests --- spec/concerns/authentication_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/concerns/authentication_spec.rb b/spec/concerns/authentication_spec.rb index c67b4e0..82e26c9 100644 --- a/spec/concerns/authentication_spec.rb +++ b/spec/concerns/authentication_spec.rb @@ -23,7 +23,7 @@ end describe '#authenticate!' do - it 'authenticates and then be authenticated?' do + it 'authenticates the client' do expect(client.authenticated?).not_to be true client.authenticate! @@ -61,7 +61,7 @@ } end - it 'authenticates and then be authenticated?' do + it 'authenticates the client' do expect(client.authenticated?).not_to be true client.authenticate! expect(client.authenticated?).to be true @@ -100,7 +100,7 @@ } end - it 'retries until getting valid token and then be authenticated?' do + it 'retries until it gets a valid token' do expect(client.authenticated?).not_to be true client.authenticate! expect(client.authenticated?).to be true @@ -109,7 +109,7 @@ context 'when retry_authentication_count is low' do let(:retry_count) { 2 } - it 'stops retrying after @retry_authentication_count tries and then raise an error' do + it 'stops retrying after a while' do expect(client.authenticated?).not_to be true expect { client.authenticate! }.to raise_error(Mrkt::Errors::Error, 'Client not authenticated') From bfc33307daa4d19a285767f713d0c12d03dbe755 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?KARASZI=20Istv=C3=A1n?= Date: Tue, 14 Dec 2021 10:36:59 +0100 Subject: [PATCH 11/15] Rename context --- spec/concerns/authentication_spec.rb | 2 +- spec/concerns/crud_activities_spec.rb | 2 +- spec/concerns/crud_asset_folders_spec.rb | 2 +- spec/concerns/crud_asset_static_lists_spec.rb | 2 +- spec/concerns/crud_campaigns_spec.rb | 2 +- spec/concerns/crud_custom_activities_spec.rb | 2 +- spec/concerns/crud_custom_objects_spec.rb | 2 +- spec/concerns/crud_leads_spec.rb | 2 +- spec/concerns/crud_lists_spec.rb | 2 +- spec/concerns/crud_program_members_spec.rb | 2 +- spec/concerns/crud_programs_spec.rb | 2 +- spec/concerns/import_custom_objects_spec.rb | 2 +- spec/concerns/import_leads_spec.rb | 2 +- spec/mkto_rest_spec.rb | 2 +- spec/support/initialized_client.rb | 2 +- 15 files changed, 15 insertions(+), 15 deletions(-) diff --git a/spec/concerns/authentication_spec.rb b/spec/concerns/authentication_spec.rb index 82e26c9..550adf5 100644 --- a/spec/concerns/authentication_spec.rb +++ b/spec/concerns/authentication_spec.rb @@ -1,5 +1,5 @@ describe Mrkt::Authentication do - include_context 'initialized client' + include_context 'with an initialized client' describe '#authenticate' do subject(:action) { client.authenticate } diff --git a/spec/concerns/crud_activities_spec.rb b/spec/concerns/crud_activities_spec.rb index 485630e..79897cb 100644 --- a/spec/concerns/crud_activities_spec.rb +++ b/spec/concerns/crud_activities_spec.rb @@ -1,5 +1,5 @@ describe Mrkt::CrudActivities do - include_context 'initialized client' + include_context 'with an initialized client' describe '#get_activity_types' do subject { client.get_activity_types } diff --git a/spec/concerns/crud_asset_folders_spec.rb b/spec/concerns/crud_asset_folders_spec.rb index c895f22..1d52166 100644 --- a/spec/concerns/crud_asset_folders_spec.rb +++ b/spec/concerns/crud_asset_folders_spec.rb @@ -1,5 +1,5 @@ describe Mrkt::CrudAssetFolders do - include_context 'initialized client' + include_context 'with an initialized client' let(:response_folder_result) do { diff --git a/spec/concerns/crud_asset_static_lists_spec.rb b/spec/concerns/crud_asset_static_lists_spec.rb index 195dbde..5b9d209 100644 --- a/spec/concerns/crud_asset_static_lists_spec.rb +++ b/spec/concerns/crud_asset_static_lists_spec.rb @@ -1,5 +1,5 @@ describe Mrkt::CrudAssetStaticLists do - include_context 'initialized client' + include_context 'with an initialized client' let(:response_static_list_result) do { diff --git a/spec/concerns/crud_campaigns_spec.rb b/spec/concerns/crud_campaigns_spec.rb index dbc70c9..9efb55f 100644 --- a/spec/concerns/crud_campaigns_spec.rb +++ b/spec/concerns/crud_campaigns_spec.rb @@ -1,5 +1,5 @@ describe Mrkt::CrudCampaigns do - include_context 'initialized client' + include_context 'with an initialized client' describe '#request_campaign' do subject(:action) { client.request_campaign(id, lead_ids, tokens) } diff --git a/spec/concerns/crud_custom_activities_spec.rb b/spec/concerns/crud_custom_activities_spec.rb index 2e26d94..bb044cd 100644 --- a/spec/concerns/crud_custom_activities_spec.rb +++ b/spec/concerns/crud_custom_activities_spec.rb @@ -1,5 +1,5 @@ describe Mrkt::CrudCustomObjects do - include_context 'initialized client' + include_context 'with an initialized client' describe '#get_list_of_custom_activity_types' do let(:response_stub) do diff --git a/spec/concerns/crud_custom_objects_spec.rb b/spec/concerns/crud_custom_objects_spec.rb index 7792a00..acae728 100644 --- a/spec/concerns/crud_custom_objects_spec.rb +++ b/spec/concerns/crud_custom_objects_spec.rb @@ -1,5 +1,5 @@ describe Mrkt::CrudCustomObjects do - include_context 'initialized client' + include_context 'with an initialized client' describe '#get_list_of_custom_objects' do let(:response_stub) do diff --git a/spec/concerns/crud_leads_spec.rb b/spec/concerns/crud_leads_spec.rb index e8f28f9..5a124ca 100644 --- a/spec/concerns/crud_leads_spec.rb +++ b/spec/concerns/crud_leads_spec.rb @@ -1,5 +1,5 @@ describe Mrkt::CrudLeads do - include_context 'initialized client' + include_context 'with an initialized client' describe 'get_lead_by_id' do subject { client.get_lead_by_id(id, fields: fields) } diff --git a/spec/concerns/crud_lists_spec.rb b/spec/concerns/crud_lists_spec.rb index 3296fdc..a64394a 100644 --- a/spec/concerns/crud_lists_spec.rb +++ b/spec/concerns/crud_lists_spec.rb @@ -1,5 +1,5 @@ describe Mrkt::CrudLists do - include_context 'initialized client' + include_context 'with an initialized client' describe '#get_leads_by_list' do subject { client.get_leads_by_list(list_id) } diff --git a/spec/concerns/crud_program_members_spec.rb b/spec/concerns/crud_program_members_spec.rb index 6c9f267..a86666f 100644 --- a/spec/concerns/crud_program_members_spec.rb +++ b/spec/concerns/crud_program_members_spec.rb @@ -1,5 +1,5 @@ describe Mrkt::CrudProgramMembers do - include_context 'initialized client' + include_context 'with an initialized client' describe '#describe_program_members' do subject { client.describe_program_members } diff --git a/spec/concerns/crud_programs_spec.rb b/spec/concerns/crud_programs_spec.rb index 52af631..3b06ce5 100644 --- a/spec/concerns/crud_programs_spec.rb +++ b/spec/concerns/crud_programs_spec.rb @@ -1,5 +1,5 @@ describe Mrkt::CrudPrograms do - include_context 'initialized client' + include_context 'with an initialized client' describe '#browse_programs' do subject { client.browse_programs } diff --git a/spec/concerns/import_custom_objects_spec.rb b/spec/concerns/import_custom_objects_spec.rb index 94d190e..7655796 100644 --- a/spec/concerns/import_custom_objects_spec.rb +++ b/spec/concerns/import_custom_objects_spec.rb @@ -1,7 +1,7 @@ require 'tempfile' describe Mrkt::ImportCustomObjects do - include_context 'initialized client' + include_context 'with an initialized client' let(:custom_object) { 'car_c' } describe '#import_custom_object' do diff --git a/spec/concerns/import_leads_spec.rb b/spec/concerns/import_leads_spec.rb index 0f9be33..91fe0f1 100644 --- a/spec/concerns/import_leads_spec.rb +++ b/spec/concerns/import_leads_spec.rb @@ -2,7 +2,7 @@ require 'tempfile' describe Mrkt::ImportLeads do - include_context 'initialized client' + include_context 'with an initialized client' describe '#import_lead' do subject { client.import_lead(tempfile) } diff --git a/spec/mkto_rest_spec.rb b/spec/mkto_rest_spec.rb index 4b7527a..7a4ca44 100644 --- a/spec/mkto_rest_spec.rb +++ b/spec/mkto_rest_spec.rb @@ -1,5 +1,5 @@ describe Mrkt do - include_context 'initialized client' + include_context 'with an initialized client' it { is_expected.to respond_to(:get, :post, :delete) } end diff --git a/spec/support/initialized_client.rb b/spec/support/initialized_client.rb index a6b00c1..891e0f8 100644 --- a/spec/support/initialized_client.rb +++ b/spec/support/initialized_client.rb @@ -1,7 +1,7 @@ require 'securerandom' require 'json' -shared_context 'initialized client' do +shared_context 'with an initialized client' do subject(:client) { Mrkt::Client.new(host: host, client_id: client_id, client_secret: client_secret) } let(:host) { '0-KBZ-0.mktorest.com' } From c958c527ae8fb7abd2e67b7e2005b51c79f7aa75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?KARASZI=20Istv=C3=A1n?= Date: Tue, 14 Dec 2021 10:37:06 +0100 Subject: [PATCH 12/15] Fix formatting --- spec/concerns/crud_campaigns_spec.rb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/spec/concerns/crud_campaigns_spec.rb b/spec/concerns/crud_campaigns_spec.rb index 9efb55f..63c909a 100644 --- a/spec/concerns/crud_campaigns_spec.rb +++ b/spec/concerns/crud_campaigns_spec.rb @@ -26,11 +26,11 @@ let(:response_stub) do { requestId: 'a9b#14eb6771358', - success: false, - errors: [{ - code: '1013', - message: 'Campaign not found' - }] + success: false, + errors: [{ + code: '1013', + message: 'Campaign not found' + }] } end @@ -44,11 +44,11 @@ let(:response_stub) do { requestId: '7cdc#14eb6ae8a86', - success: false, - errors: [{ - code: '1004', - message: 'Lead [1234] not found' - }] + success: false, + errors: [{ + code: '1004', + message: 'Lead [1234] not found' + }] } end From 0756e08433bf8680f7cf2b52e45c8d87c75fcac6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?KARASZI=20Istv=C3=A1n?= Date: Tue, 14 Dec 2021 10:37:13 +0100 Subject: [PATCH 13/15] Remove unnecessary stub removing --- spec/concerns/authentication_spec.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/spec/concerns/authentication_spec.rb b/spec/concerns/authentication_spec.rb index 550adf5..93cce07 100644 --- a/spec/concerns/authentication_spec.rb +++ b/spec/concerns/authentication_spec.rb @@ -34,8 +34,6 @@ subject(:client) { Mrkt::Client.new(client_options) } before do - remove_request_stub(@authentication_request_stub) - stub_request(:get, "https://#{host}/identity/oauth/token") .with(query: query) .to_return(json_stub(authentication_stub)) @@ -72,8 +70,6 @@ subject(:client) { Mrkt::Client.new(client_options) } before do - remove_request_stub(@authentication_request_stub) - stub_request(:get, "https://#{host}/identity/oauth/token") .with(query: { client_id: client_id, client_secret: client_secret, grant_type: 'client_credentials' }) .to_return(json_stub(expired_authentication_stub)).times(3).then From 365483e993f76bb9810d2be909bfa21fcc16f920 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?KARASZI=20Istv=C3=A1n?= Date: Tue, 14 Dec 2021 10:37:22 +0100 Subject: [PATCH 14/15] Add exclusions --- .rubocop.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index e5a8548..99a8963 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -35,6 +35,16 @@ Metrics/ParameterLists: Naming/AccessorMethodName: Enabled: false +RSpec/FilePath: + Enabled: false +RSpec/NestedGroups: + Enabled: false +RSpec/MultipleMemoizedHelpers: + Enabled: false +RSpec/MultipleExpectations: + Exclude: + - 'spec/concerns/authentication_spec.rb' + Style/ClassAndModuleChildren: Enabled: false Style/Documentation: From f6937f2821d2e1bce70fa69975a3627777cb4168 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?KARASZI=20Istv=C3=A1n?= Date: Tue, 14 Dec 2021 10:38:16 +0100 Subject: [PATCH 15/15] Update dependencies --- Gemfile.lock | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 9d87f31..37e4d28 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -16,7 +16,7 @@ GEM crack (0.4.5) rexml diff-lcs (1.4.4) - docile (1.3.5) + docile (1.4.0) faraday (1.8.0) faraday-em_http (~> 1.0) faraday-em_synchrony (~> 1.0) @@ -43,7 +43,7 @@ GEM method_source (1.0.0) multipart-post (2.1.1) parallel (1.21.0) - parser (3.0.2.0) + parser (3.0.3.2) ast (~> 2.4.1) pry (0.13.1) coderay (~> 1.1) @@ -54,7 +54,7 @@ GEM public_suffix (4.0.6) rainbow (3.0.0) rake (13.0.6) - regexp_parser (2.1.1) + regexp_parser (2.2.0) rexml (3.2.5) rspec (3.10.0) rspec-core (~> 3.10.0) @@ -68,7 +68,7 @@ GEM rspec-mocks (3.10.2) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.10.0) - rspec-support (3.10.2) + rspec-support (3.10.3) rubocop (1.23.0) parallel (~> 1.10) parser (>= 3.0.0.0) @@ -78,7 +78,7 @@ GEM rubocop-ast (>= 1.12.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 1.4.0, < 3.0) - rubocop-ast (1.13.0) + rubocop-ast (1.15.0) parser (>= 3.0.1.1) rubocop-rake (0.6.0) rubocop (~> 1.0)