Commit b83380f3 authored by Thong Kuah's avatar Thong Kuah

Merge branch 'next-instance-of' into 'master'

Update RSpec helper methods to *_next_instance_of

See merge request gitlab-org/gitlab!20236
parents 558040b1 44002f46
......@@ -12,7 +12,9 @@ describe Backup::Repository do
allow(progress).to receive(:print)
allow(FileUtils).to receive(:mv).and_return(true)
allow_any_instance_of(described_class).to receive(:progress).and_return(progress)
allow_next_instance_of(described_class) do |instance|
allow(instance).to receive(:progress).and_return(progress)
end
end
describe '#dump' do
......@@ -47,7 +49,9 @@ describe Backup::Repository do
describe 'command failure' do
before do
allow_any_instance_of(Gitlab::Shell).to receive(:create_repository).and_return(false)
allow_next_instance_of(Gitlab::Shell) do |instance|
allow(instance).to receive(:create_repository).and_return(false)
end
end
context 'hashed storage' do
......
......@@ -60,7 +60,9 @@ describe Banzai::Filter::CommitReferenceFilter do
end
it 'escapes the title attribute' do
allow_any_instance_of(Commit).to receive(:title).and_return(%{"></a>whatever<a title="})
allow_next_instance_of(Commit) do |instance|
allow(instance).to receive(:title).and_return(%{"></a>whatever<a title="})
end
doc = reference_filter("See #{reference}")
expect(doc.text).to eq "See #{commit.short_id}"
......
......@@ -7,13 +7,17 @@ describe Banzai::Filter::MarkdownFilter do
describe 'markdown engine from context' do
it 'defaults to CommonMark' do
expect_any_instance_of(Banzai::Filter::MarkdownEngines::CommonMark).to receive(:render).and_return('test')
expect_next_instance_of(Banzai::Filter::MarkdownEngines::CommonMark) do |instance|
expect(instance).to receive(:render).and_return('test')
end
filter('test')
end
it 'uses CommonMark' do
expect_any_instance_of(Banzai::Filter::MarkdownEngines::CommonMark).to receive(:render).and_return('test')
expect_next_instance_of(Banzai::Filter::MarkdownEngines::CommonMark) do |instance|
expect(instance).to receive(:render).and_return('test')
end
filter('test', { markdown_engine: :common_mark })
end
......
......@@ -214,7 +214,9 @@ describe Banzai::Filter::MilestoneReferenceFilter do
end
it 'escapes the name attribute' do
allow_any_instance_of(Milestone).to receive(:title).and_return(%{"></a>whatever<a title="})
allow_next_instance_of(Milestone) do |instance|
allow(instance).to receive(:title).and_return(%{"></a>whatever<a title="})
end
doc = reference_filter("See #{reference}")
......@@ -251,7 +253,9 @@ describe Banzai::Filter::MilestoneReferenceFilter do
end
it 'escapes the name attribute' do
allow_any_instance_of(Milestone).to receive(:title).and_return(%{"></a>whatever<a title="})
allow_next_instance_of(Milestone) do |instance|
allow(instance).to receive(:title).and_return(%{"></a>whatever<a title="})
end
doc = reference_filter("See #{reference}")
......@@ -288,7 +292,9 @@ describe Banzai::Filter::MilestoneReferenceFilter do
end
it 'escapes the name attribute' do
allow_any_instance_of(Milestone).to receive(:title).and_return(%{"></a>whatever<a title="})
allow_next_instance_of(Milestone) do |instance|
allow(instance).to receive(:title).and_return(%{"></a>whatever<a title="})
end
doc = reference_filter("See #{reference}")
......
......@@ -42,7 +42,9 @@ describe Banzai::Filter::ReferenceRedactorFilter do
context 'valid projects' do
before do
allow_any_instance_of(Banzai::ReferenceParser::BaseParser).to receive(:can_read_reference?).and_return(true)
allow_next_instance_of(Banzai::ReferenceParser::BaseParser) do |instance|
allow(instance).to receive(:can_read_reference?).and_return(true)
end
end
it 'allows permitted Project references' do
......@@ -59,7 +61,9 @@ describe Banzai::Filter::ReferenceRedactorFilter do
context 'invalid projects' do
before do
allow_any_instance_of(Banzai::ReferenceParser::BaseParser).to receive(:can_read_reference?).and_return(false)
allow_next_instance_of(Banzai::ReferenceParser::BaseParser) do |instance|
allow(instance).to receive(:can_read_reference?).and_return(false)
end
end
it 'removes unpermitted references' do
......
......@@ -92,7 +92,9 @@ describe Banzai::Filter::SyntaxHighlightFilter do
context "when Rouge lexing fails" do
before do
allow_any_instance_of(Rouge::Lexers::Ruby).to receive(:stream_tokens).and_raise(StandardError)
allow_next_instance_of(Rouge::Lexers::Ruby) do |instance|
allow(instance).to receive(:stream_tokens).and_raise(StandardError)
end
end
it "highlights as plaintext" do
......@@ -106,7 +108,9 @@ describe Banzai::Filter::SyntaxHighlightFilter do
context "when Rouge lexing fails after a retry" do
before do
allow_any_instance_of(Rouge::Lexers::PlainText).to receive(:stream_tokens).and_raise(StandardError)
allow_next_instance_of(Rouge::Lexers::PlainText) do |instance|
allow(instance).to receive(:stream_tokens).and_raise(StandardError)
end
end
it "does not add highlighting classes" do
......
......@@ -25,7 +25,9 @@ describe Banzai::ObjectRenderer do
end
it 'calls Banzai::ReferenceRedactor to perform redaction' do
expect_any_instance_of(Banzai::ReferenceRedactor).to receive(:redact).and_call_original
expect_next_instance_of(Banzai::ReferenceRedactor) do |instance|
expect(instance).to receive(:redact).and_call_original
end
renderer.render([object], :note)
end
......@@ -85,7 +87,9 @@ describe Banzai::ObjectRenderer do
end
it 'calls Banzai::ReferenceRedactor to perform redaction' do
expect_any_instance_of(Banzai::ReferenceRedactor).to receive(:redact).and_call_original
expect_next_instance_of(Banzai::ReferenceRedactor) do |instance|
expect(instance).to receive(:redact).and_call_original
end
renderer.render([cacheless_thing], :title)
end
......
......@@ -35,8 +35,9 @@ describe Banzai::ReferenceParser::CommitParser do
it 'returns an Array of commits' do
commit = double(:commit)
allow_any_instance_of(Project).to receive(:valid_repo?)
.and_return(true)
allow_next_instance_of(Project) do |instance|
allow(instance).to receive(:valid_repo?).and_return(true)
end
expect(subject).to receive(:find_commits)
.with(project, ['123'])
......@@ -46,8 +47,9 @@ describe Banzai::ReferenceParser::CommitParser do
end
it 'returns an empty Array when the commit could not be found' do
allow_any_instance_of(Project).to receive(:valid_repo?)
.and_return(true)
allow_next_instance_of(Project) do |instance|
allow(instance).to receive(:valid_repo?).and_return(true)
end
expect(subject).to receive(:find_commits)
.with(project, ['123'])
......@@ -57,8 +59,9 @@ describe Banzai::ReferenceParser::CommitParser do
end
it 'skips projects without valid repositories' do
allow_any_instance_of(Project).to receive(:valid_repo?)
.and_return(false)
allow_next_instance_of(Project) do |instance|
allow(instance).to receive(:valid_repo?).and_return(false)
end
expect(subject.referenced_by([link])).to eq([])
end
......@@ -66,8 +69,9 @@ describe Banzai::ReferenceParser::CommitParser do
context 'when the link does not have a data-commit attribute' do
it 'returns an empty Array' do
allow_any_instance_of(Project).to receive(:valid_repo?)
.and_return(true)
allow_next_instance_of(Project) do |instance|
allow(instance).to receive(:valid_repo?).and_return(true)
end
expect(subject.referenced_by([link])).to eq([])
end
......@@ -76,8 +80,9 @@ describe Banzai::ReferenceParser::CommitParser do
context 'when the link does not have a data-project attribute' do
it 'returns an empty Array' do
allow_any_instance_of(Project).to receive(:valid_repo?)
.and_return(true)
allow_next_instance_of(Project) do |instance|
allow(instance).to receive(:valid_repo?).and_return(true)
end
expect(subject.referenced_by([link])).to eq([])
end
......
......@@ -173,10 +173,11 @@ describe Banzai::ReferenceRedactor do
doc = Nokogiri::HTML.fragment('<a data-reference-type="issue"></a>')
node = doc.children[0]
expect_any_instance_of(Banzai::ReferenceParser::IssueParser)
.to receive(:nodes_visible_to_user)
expect_next_instance_of(Banzai::ReferenceParser::IssueParser) do |instance|
expect(instance).to receive(:nodes_visible_to_user)
.with(user, [node])
.and_return([node])
end
expect(redactor.nodes_visible_to_user([node])).to eq(Set.new([node]))
end
......
......@@ -4,12 +4,16 @@ require 'spec_helper'
describe Bitbucket::Connection do
before do
allow_any_instance_of(described_class).to receive(:provider).and_return(double(app_id: '', app_secret: ''))
allow_next_instance_of(described_class) do |instance|
allow(instance).to receive(:provider).and_return(double(app_id: '', app_secret: ''))
end
end
describe '#get' do
it 'calls OAuth2::AccessToken::get' do
expect_any_instance_of(OAuth2::AccessToken).to receive(:get).and_return(double(parsed: true))
expect_next_instance_of(OAuth2::AccessToken) do |instance|
expect(instance).to receive(:get).and_return(double(parsed: true))
end
connection = described_class.new({})
......@@ -19,7 +23,9 @@ describe Bitbucket::Connection do
describe '#expired?' do
it 'calls connection.expired?' do
expect_any_instance_of(OAuth2::AccessToken).to receive(:expired?).and_return(true)
expect_next_instance_of(OAuth2::AccessToken) do |instance|
expect(instance).to receive(:expired?).and_return(true)
end
expect(described_class.new({}).expired?).to be_truthy
end
......@@ -29,7 +35,9 @@ describe Bitbucket::Connection do
it 'calls connection.refresh!' do
response = double(token: nil, expires_at: nil, expires_in: nil, refresh_token: nil)
expect_any_instance_of(OAuth2::AccessToken).to receive(:refresh!).and_return(response)
expect_next_instance_of(OAuth2::AccessToken) do |instance|
expect(instance).to receive(:refresh!).and_return(response)
end
described_class.new({}).refresh!
end
......
......@@ -88,7 +88,9 @@ describe ExtractsPath do
context 'subclass overrides get_id' do
it 'uses ref returned by get_id' do
allow_any_instance_of(self.class).to receive(:get_id) { '38008cb17ce1466d8fec2dfa6f6ab8dcfe5cf49e' }
allow_next_instance_of(self.class) do |instance|
allow(instance).to receive(:get_id) { '38008cb17ce1466d8fec2dfa6f6ab8dcfe5cf49e' }
end
assign_ref_vars
......
......@@ -30,8 +30,9 @@ describe GoogleApi::Auth do
end
before do
allow_any_instance_of(OAuth2::Strategy::AuthCode)
.to receive(:get_token).and_return(token)
allow_next_instance_of(OAuth2::Strategy::AuthCode) do |instance|
allow(instance).to receive(:get_token).and_return(token)
end
end
it 'returns token and expires_at' do
......
......@@ -15,7 +15,9 @@ describe OmniAuth::Strategies::SAML, type: :strategy do
it 'stores request ID during request phase' do
request_id = double
allow_any_instance_of(OneLogin::RubySaml::Authrequest).to receive(:uuid).and_return(request_id)
allow_next_instance_of(OneLogin::RubySaml::Authrequest) do |instance|
allow(instance).to receive(:uuid).and_return(request_id)
end
post '/users/auth/saml'
expect(session['last_authn_request_id']).to eq(request_id)
......
......@@ -1095,7 +1095,9 @@ describe Notify do
context 'when note is not on text' do
before do
allow_any_instance_of(DiffDiscussion).to receive(:on_text?).and_return(false)
allow_next_instance_of(DiffDiscussion) do |instance|
allow(instance).to receive(:on_text?).and_return(false)
end
end
it 'does not include diffs with character-level highlighting' do
......
......@@ -2474,7 +2474,9 @@ describe Ci::Pipeline, :mailer do
let(:pipeline) { create(:ci_empty_pipeline, status: 'created', project: project, ref: 'master', sha: 'a288a022a53a5a944fae87bcec6efc87b7061808') }
it "returns merge requests whose `diff_head_sha` matches the pipeline's SHA" do
allow_any_instance_of(MergeRequest).to receive(:diff_head_sha) { 'a288a022a53a5a944fae87bcec6efc87b7061808' }
allow_next_instance_of(MergeRequest) do |instance|
allow(instance).to receive(:diff_head_sha) { 'a288a022a53a5a944fae87bcec6efc87b7061808' }
end
merge_request = create(:merge_request, source_project: project, head_pipeline: pipeline, source_branch: pipeline.ref)
expect(pipeline.merge_requests_as_head_pipeline).to eq([merge_request])
......@@ -2488,7 +2490,9 @@ describe Ci::Pipeline, :mailer do
it "doesn't return merge requests whose `diff_head_sha` doesn't match the pipeline's SHA" do
create(:merge_request, source_project: project, source_branch: pipeline.ref)
allow_any_instance_of(MergeRequest).to receive(:diff_head_sha) { '97de212e80737a608d939f648d959671fb0a0142b' }
allow_next_instance_of(MergeRequest) do |instance|
allow(instance).to receive(:diff_head_sha) { '97de212e80737a608d939f648d959671fb0a0142b' }
end
expect(pipeline.merge_requests_as_head_pipeline).to be_empty
end
......
......@@ -174,7 +174,9 @@ describe Clusters::Applications::Runner do
subject { create(:clusters_applications_runner, :scheduled, runner: ci_runner) }
it 'calls prepare_uninstall' do
expect_any_instance_of(described_class).to receive(:prepare_uninstall).and_call_original
expect_next_instance_of(described_class) do |instance|
expect(instance).to receive(:prepare_uninstall).and_call_original
end
subject.make_uninstalling!
end
......
......@@ -22,7 +22,9 @@ describe CycleAnalytics::GroupLevel do
describe '#stats' do
before do
allow_any_instance_of(Gitlab::ReferenceExtractor).to receive(:issues).and_return([issue])
allow_next_instance_of(Gitlab::ReferenceExtractor) do |instance|
allow(instance).to receive(:issues).and_return([issue])
end
create_cycle(user, project, issue, mr, milestone, pipeline)
deploy_master(user, project)
......
......@@ -15,7 +15,9 @@ describe CycleAnalytics::ProjectLevel do
describe '#all_medians_by_stage' do
before do
allow_any_instance_of(Gitlab::ReferenceExtractor).to receive(:issues).and_return([issue])
allow_next_instance_of(Gitlab::ReferenceExtractor) do |instance|
allow(instance).to receive(:issues).and_return([issue])
end
create_cycle(user, project, issue, mr, milestone, pipeline)
deploy_master(user, project)
......
......@@ -32,8 +32,9 @@ describe Deployment do
let(:deployment) { create(:deployment, deployable: build) }
it 'delegates to other_scheduled_actions' do
expect_any_instance_of(Ci::Build)
.to receive(:other_scheduled_actions)
expect_next_instance_of(Ci::Build) do |instance|
expect(instance).to receive(:other_scheduled_actions)
end
subject
end
......
......@@ -343,7 +343,9 @@ describe DiffNote do
context 'when line is not suggestible' do
it 'returns false' do
allow_any_instance_of(Gitlab::Diff::Line).to receive(:suggestible?) { false }
allow_next_instance_of(Gitlab::Diff::Line) do |instance|
allow(instance).to receive(:suggestible?) { false }
end
expect(subject.supports_suggestion?).to be(false)
end
......
......@@ -60,7 +60,9 @@ describe DiffViewer::Base do
context 'when the binaryness does not match' do
before do
allow_any_instance_of(Blob).to receive(:binary_in_repo?).and_return(true)
allow_next_instance_of(Blob) do |instance|
allow(instance).to receive(:binary_in_repo?).and_return(true)
end
end
it 'returns false' do
......
......@@ -484,7 +484,9 @@ describe Environment, :use_clean_rails_memory_store_caching do
subject { environment.last_deployment }
before do
allow_any_instance_of(Deployment).to receive(:create_ref)
allow_next_instance_of(Deployment) do |instance|
allow(instance).to receive(:create_ref)
end
end
context 'when there is an old deployment record' do
......@@ -1031,7 +1033,9 @@ describe Environment, :use_clean_rails_memory_store_caching do
describe '#prometheus_adapter' do
it 'calls prometheus adapter service' do
expect_any_instance_of(Prometheus::AdapterService).to receive(:prometheus_adapter)
expect_next_instance_of(Prometheus::AdapterService) do |instance|
expect(instance).to receive(:prometheus_adapter)
end
subject.prometheus_adapter
end
......
......@@ -20,7 +20,9 @@ describe Event do
describe 'after_create :reset_project_activity' do
it 'calls the reset_project_activity method' do
expect_any_instance_of(described_class).to receive(:reset_project_activity)
expect_next_instance_of(described_class) do |instance|
expect(instance).to receive(:reset_project_activity)
end
create_push_event(project, project.owner)
end
......
......@@ -75,7 +75,9 @@ RSpec.describe GpgSignature do
describe '#commit' do
it 'fetches the commit through the project' do
expect_any_instance_of(Project).to receive(:commit).with(commit_sha).and_return(commit)
expect_next_instance_of(Project) do |instance|
expect(instance).to receive(:commit).with(commit_sha).and_return(commit)
end
gpg_signature.commit
end
......
......@@ -49,10 +49,11 @@ RSpec.describe ResourceLabelEvent, type: :model do
describe '#expire_etag_cache' do
def expect_expiration(issue)
expect_any_instance_of(Gitlab::EtagCaching::Store)
.to receive(:touch)
expect_next_instance_of(Gitlab::EtagCaching::Store) do |instance|
expect(instance).to receive(:touch)
.with("/#{issue.project.namespace.to_param}/#{issue.project.to_param}/noteable/issue/#{issue.id}/notes")
end
end
it 'expires resource note etag cache on event save' do
expect_expiration(subject.issuable)
......
......@@ -151,7 +151,9 @@ describe ObjectStorage do
describe 'fails' do
it 'is handled gracefully' do
store = uploader.object_store
expect_any_instance_of(Upload).to receive(:save!).and_raise("An error")
expect_next_instance_of(Upload) do |instance|
expect(instance).to receive(:save!).and_raise("An error")
end
expect { subject }.to raise_error("An error")
expect(uploader.exists?).to be_truthy
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment