From 471a49445686415d0f22b5356b347c42ad11da93 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Sat, 9 Apr 2016 16:20:09 -0400 Subject: [PATCH 01/11] Enable verify_partial_doubles for rspec-mocks See http://wegowise.github.io/blog/2014/09/03/rspec-verifying-doubles/ --- spec/spec_helper.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 606da1b7605b..be14c9df08a0 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -23,7 +23,9 @@ RSpec.configure do |config| config.use_transactional_fixtures = false config.use_instantiated_fixtures = false - config.mock_with :rspec + config.mock_with :rspec do |mocks| + mocks.verify_partial_doubles = true + end config.verbose_retry = true config.display_try_failure_messages = true -- GitLab From 7851b887e7b5d1c68e956b0410de81579d3de0fc Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Fri, 20 May 2016 15:38:17 -0500 Subject: [PATCH 02/11] Remove stub of non-existent `Project#branches` method --- spec/features/security/project/internal_access_spec.rb | 5 ----- spec/features/security/project/private_access_spec.rb | 5 ----- spec/features/security/project/public_access_spec.rb | 5 ----- 3 files changed, 15 deletions(-) diff --git a/spec/features/security/project/internal_access_spec.rb b/spec/features/security/project/internal_access_spec.rb index 13d980a326f5..b9c8d41b53ea 100644 --- a/spec/features/security/project/internal_access_spec.rb +++ b/spec/features/security/project/internal_access_spec.rb @@ -240,11 +240,6 @@ describe "GET /:project_path/branches" do subject { namespace_project_branches_path(project.namespace, project) } - before do - # Speed increase - allow_any_instance_of(Project).to receive(:branches).and_return([]) - end - it { is_expected.to be_allowed_for :admin } it { is_expected.to be_allowed_for owner } it { is_expected.to be_allowed_for master } diff --git a/spec/features/security/project/private_access_spec.rb b/spec/features/security/project/private_access_spec.rb index ac9690cc1279..343be686493b 100644 --- a/spec/features/security/project/private_access_spec.rb +++ b/spec/features/security/project/private_access_spec.rb @@ -212,11 +212,6 @@ describe "GET /:project_path/branches" do subject { namespace_project_branches_path(project.namespace, project) } - before do - # Speed increase - allow_any_instance_of(Project).to receive(:branches).and_return([]) - end - it { is_expected.to be_allowed_for :admin } it { is_expected.to be_allowed_for owner } it { is_expected.to be_allowed_for master } diff --git a/spec/features/security/project/public_access_spec.rb b/spec/features/security/project/public_access_spec.rb index 737897de52b6..01f7e7c1f3b1 100644 --- a/spec/features/security/project/public_access_spec.rb +++ b/spec/features/security/project/public_access_spec.rb @@ -378,11 +378,6 @@ describe "GET /:project_path/branches" do subject { namespace_project_branches_path(project.namespace, project) } - before do - # Speed increase - allow_any_instance_of(Project).to receive(:branches).and_return([]) - end - it { is_expected.to be_allowed_for :admin } it { is_expected.to be_allowed_for owner } it { is_expected.to be_allowed_for master } -- GitLab From edee30017b8eb015823c93df61dfa80cd5830f4e Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Fri, 20 May 2016 15:50:43 -0500 Subject: [PATCH 03/11] Correctly stub `Gitlab::AkismetHelper` methods in API specs --- spec/requests/api/issues_spec.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/spec/requests/api/issues_spec.rb b/spec/requests/api/issues_spec.rb index 6adccb4ebae9..edc28dec947d 100644 --- a/spec/requests/api/issues_spec.rb +++ b/spec/requests/api/issues_spec.rb @@ -517,10 +517,8 @@ describe 'POST /projects/:id/issues with spam filtering' do before do - Grape::Endpoint.before_each do |endpoint| - allow(endpoint).to receive(:check_for_spam?).and_return(true) - allow(endpoint).to receive(:is_spam?).and_return(true) - end + allow_any_instance_of(Gitlab::AkismetHelper).to receive(:check_for_spam?).and_return(true) + allow_any_instance_of(Gitlab::AkismetHelper).to receive(:is_spam?).and_return(true) end let(:params) do -- GitLab From 22ddb9c243812500b7f7645bb91cd746b55513d1 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Fri, 20 May 2016 15:55:39 -0500 Subject: [PATCH 04/11] Remove unused stubs from UploadLinkFilter spec --- spec/lib/banzai/filter/upload_link_filter_spec.rb | 6 ------ 1 file changed, 6 deletions(-) diff --git a/spec/lib/banzai/filter/upload_link_filter_spec.rb b/spec/lib/banzai/filter/upload_link_filter_spec.rb index 273d2ed709ad..f3bde2757ec9 100644 --- a/spec/lib/banzai/filter/upload_link_filter_spec.rb +++ b/spec/lib/banzai/filter/upload_link_filter_spec.rb @@ -80,12 +80,6 @@ def nested_link(path) path = '/uploads/한글.png' escaped = Addressable::URI.escape(path) - # Stub these methods so the file doesn't actually need to be in the repo - allow_any_instance_of(described_class). - to receive(:file_exists?).and_return(true) - allow_any_instance_of(described_class). - to receive(:image?).with(path).and_return(true) - doc = filter(image(escaped)) expect(doc.at_css('img')['src']).to match "#{Gitlab.config.gitlab.url}/#{project.path_with_namespace}/uploads/%ED%95%9C%EA%B8%80.png" end -- GitLab From f2483d64658448953167c5c1128df98ef3ff59a7 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Fri, 20 May 2016 15:55:50 -0500 Subject: [PATCH 05/11] Remove unused stubs from `Sherlock::LineProfiler` spec --- spec/lib/gitlab/sherlock/line_profiler_spec.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/spec/lib/gitlab/sherlock/line_profiler_spec.rb b/spec/lib/gitlab/sherlock/line_profiler_spec.rb index d57627bba2b4..a906cc63a579 100644 --- a/spec/lib/gitlab/sherlock/line_profiler_spec.rb +++ b/spec/lib/gitlab/sherlock/line_profiler_spec.rb @@ -20,10 +20,6 @@ describe '#profile_mri' do it 'returns an Array containing the return value and profiling samples' do - allow(profiler).to receive(:lineprof). - and_yield. - and_return({ __FILE__ => [[0, 0, 0, 0]] }) - retval, samples = profiler.profile_mri { 42 } expect(retval).to eq(42) -- GitLab From c38b6b7b020d6b11ca2ea57bdf034680a713a25e Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Fri, 20 May 2016 15:56:52 -0500 Subject: [PATCH 06/11] Fix mis-stubbed `instrument?` call for `Sherlock::Middleware` spec --- spec/lib/gitlab/sherlock/middleware_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/lib/gitlab/sherlock/middleware_spec.rb b/spec/lib/gitlab/sherlock/middleware_spec.rb index 2bbeb25ce983..c8719ab70d48 100644 --- a/spec/lib/gitlab/sherlock/middleware_spec.rb +++ b/spec/lib/gitlab/sherlock/middleware_spec.rb @@ -16,7 +16,7 @@ describe 'when instrumentation is disabled' do it "doesn't instrument a request" do - allow(middleware).to receive(:instrument).and_return(false) + allow(middleware).to receive(:instrument?).and_return(false) allow(app).to receive(:call) middleware.call({}) -- GitLab From 8844e68fc7bdef866c7fe71aaa6d21964f935278 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Fri, 20 May 2016 15:58:36 -0500 Subject: [PATCH 07/11] Fix Blob spec for `verify_partial_doubles` --- spec/models/blob_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/models/blob_spec.rb b/spec/models/blob_spec.rb index 78e95c8fac51..f5ff0dcde3f0 100644 --- a/spec/models/blob_spec.rb +++ b/spec/models/blob_spec.rb @@ -43,7 +43,7 @@ def stubbed_blob(overrides = {}) text?: false ) - described_class.decorate(double).tap do |blob| + described_class.decorate(spy).tap do |blob| allow(blob).to receive_messages(overrides) end end -- GitLab From 81086bf91bbb4e12488230b93ae370c6bd6427cd Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Tue, 24 May 2016 17:25:47 -0400 Subject: [PATCH 08/11] Remove unused stubs from GitPushService spec --- spec/services/git_push_service_spec.rb | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/spec/services/git_push_service_spec.rb b/spec/services/git_push_service_spec.rb index afabeed4a80f..d6f2852c83ae 100644 --- a/spec/services/git_push_service_spec.rb +++ b/spec/services/git_push_service_spec.rb @@ -264,7 +264,6 @@ allow(commit).to receive_messages( safe_message: "this commit \n mentions #{issue.to_reference}", - references: [issue], author_name: commit_author.name, author_email: commit_author.email ) @@ -314,7 +313,6 @@ before do allow(closing_commit).to receive_messages( - issue_closing_regex: /^([Cc]loses|[Ff]ixes) #\d+/, safe_message: "this is some work.\n\ncloses ##{issue.iid}", author_name: commit_author.name, author_email: commit_author.email @@ -386,11 +384,10 @@ WebMock.stub_request(:get, jira_api_test_url) allow(closing_commit).to receive_messages({ - issue_closing_regex: Regexp.new(Gitlab.config.gitlab.issue_closing_pattern), - safe_message: message, - author_name: commit_author.name, - author_email: commit_author.email - }) + safe_message: message, + author_name: commit_author.name, + author_email: commit_author.email + }) allow(project.repository).to receive_messages(commits_between: [closing_commit]) end -- GitLab From 085fec11084a08545dff71d69b1553cfecda830d Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Tue, 24 May 2016 17:39:02 -0400 Subject: [PATCH 09/11] Update CaseSensitivity spec to support verified doubles --- spec/models/concerns/case_sensitivity_spec.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/spec/models/concerns/case_sensitivity_spec.rb b/spec/models/concerns/case_sensitivity_spec.rb index 92fdc5cd65da..76634219b147 100644 --- a/spec/models/concerns/case_sensitivity_spec.rb +++ b/spec/models/concerns/case_sensitivity_spec.rb @@ -3,7 +3,15 @@ describe CaseSensitivity, models: true do describe '.iwhere' do let(:connection) { ActiveRecord::Base.connection } - let(:model) { Class.new { include CaseSensitivity } } + let(:model) do + Class.new do + include CaseSensitivity + + # This method needs to exist for verified doubles + def self.where(*_) + end + end + end describe 'using PostgreSQL' do before do -- GitLab From 1c0b0def50bbb10c12e7b4db7d9891a6c4333b47 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Tue, 24 May 2016 17:58:49 -0400 Subject: [PATCH 10/11] Remove invalid stub from ForkedProjectLink spec --- spec/models/forked_project_link_spec.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/spec/models/forked_project_link_spec.rb b/spec/models/forked_project_link_spec.rb index fa1a0d4e0c77..5d69a103625d 100644 --- a/spec/models/forked_project_link_spec.rb +++ b/spec/models/forked_project_link_spec.rb @@ -44,10 +44,6 @@ end def fork_project(from_project, user) - shell = double('gitlab_shell', fork_repository: true) - service = Projects::ForkService.new(from_project, user) - allow(service).to receive(:gitlab_shell).and_return(shell) - service.execute end -- GitLab From 033ee4ec58ca55b1915c3f870b3caaa71358d472 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Tue, 24 May 2016 18:13:23 -0400 Subject: [PATCH 11/11] Remove invalid stubs from Projects::BranchesController spec --- spec/controllers/projects/branches_controller_spec.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/spec/controllers/projects/branches_controller_spec.rb b/spec/controllers/projects/branches_controller_spec.rb index 644de308c644..f6970383d862 100644 --- a/spec/controllers/projects/branches_controller_spec.rb +++ b/spec/controllers/projects/branches_controller_spec.rb @@ -9,8 +9,6 @@ project.team << [user, :master] - allow(project).to receive(:branches).and_return(['master', 'foo/bar/baz']) - allow(project).to receive(:tags).and_return(['v1.0.0', 'v2.0.0']) controller.instance_variable_set(:@project, project) end -- GitLab