Skip to content
Snippets Groups Projects
Commit 68752e8f authored by Arturo Herrero's avatar Arturo Herrero
Browse files

Update RSpec helper methods to *_next_instance_of

Auto-correct some references in RSpec as:
- expect_any_instance_of -> expect_next_instance_of
- allow_any_instance_of -> allow_next_instance_of

Related to https://gitlab.com/gitlab-org/gitlab/issues/34997
parent aac77781
No related branches found
No related tags found
No related merge requests found
Showing
with 109 additions and 47 deletions
Loading
Loading
@@ -227,16 +227,17 @@ def post_create_gcp
 
describe 'security' do
before do
allow_any_instance_of(described_class)
.to receive(:token_in_session).and_return('token')
allow_any_instance_of(described_class)
.to receive(:expires_at_in_session).and_return(1.hour.since.to_i.to_s)
allow_any_instance_of(GoogleApi::CloudPlatform::Client)
.to receive(:projects_zones_clusters_create) do
OpenStruct.new(
self_link: 'projects/gcp-project-12345/zones/us-central1-a/operations/ope-123',
status: 'RUNNING'
)
allow_next_instance_of(described_class) do |instance|
allow(instance).to receive(:token_in_session).and_return('token')
allow(instance).to receive(:expires_at_in_session).and_return(1.hour.since.to_i.to_s)
end
allow_next_instance_of(GoogleApi::CloudPlatform::Client) do |instance|
allow(instance).to receive(:projects_zones_clusters_create) do
OpenStruct.new(
self_link: 'projects/gcp-project-12345/zones/us-central1-a/operations/ope-123',
status: 'RUNNING'
)
end
end
 
allow(WaitForClusterCreationWorker).to receive(:perform_in).and_return(nil)
Loading
Loading
@@ -383,7 +384,9 @@ def get_cluster_status
end
 
it 'invokes schedule_status_update on each application' do
expect_any_instance_of(Clusters::Applications::Ingress).to receive(:schedule_status_update)
expect_next_instance_of(Clusters::Applications::Ingress) do |instance|
expect(instance).to receive(:schedule_status_update)
end
 
get_cluster_status
end
Loading
Loading
Loading
Loading
@@ -13,7 +13,9 @@
let(:user) { create(:omniauth_user, provider: 'ldapmain', extern_uid: 'uid=myuser,ou=people,dc=example,dc=com') }
 
it 'repairs ldap blocks' do
expect_any_instance_of(RepairLdapBlockedUserService).to receive(:execute)
expect_next_instance_of(RepairLdapBlockedUserService) do |instance|
expect(instance).to receive(:execute)
end
 
put :update, params: { user_id: user.username, id: user.ldap_identity.id, identity: { provider: 'twitter' } }
end
Loading
Loading
@@ -23,7 +25,9 @@
let(:user) { create(:omniauth_user, provider: 'ldapmain', extern_uid: 'uid=myuser,ou=people,dc=example,dc=com') }
 
it 'repairs ldap blocks' do
expect_any_instance_of(RepairLdapBlockedUserService).to receive(:execute)
expect_next_instance_of(RepairLdapBlockedUserService) do |instance|
expect(instance).to receive(:execute)
end
 
delete :destroy, params: { user_id: user.username, id: user.ldap_identity.id }
end
Loading
Loading
Loading
Loading
@@ -39,7 +39,9 @@
 
describe '#mark_as_ham' do
before do
allow_any_instance_of(AkismetService).to receive(:submit_ham).and_return(true)
allow_next_instance_of(AkismetService) do |instance|
allow(instance).to receive(:submit_ham).and_return(true)
end
end
it 'submits the log as ham' do
post :mark_as_ham, params: { id: first_spam.id }
Loading
Loading
Loading
Loading
@@ -20,8 +20,9 @@ def assign_session_token
 
describe "GET callback" do
it "updates access token" do
allow_any_instance_of(Gitlab::GitlabImport::Client)
.to receive(:get_token).and_return(token)
allow_next_instance_of(Gitlab::GitlabImport::Client) do |instance|
allow(instance).to receive(:get_token).and_return(token)
end
stub_omniauth_provider('gitlab')
 
get :callback
Loading
Loading
Loading
Loading
@@ -104,7 +104,9 @@
end
 
it "sends notifications if all discussions are resolved" do
expect_any_instance_of(MergeRequests::ResolvedDiscussionNotificationService).to receive(:execute).with(merge_request)
expect_next_instance_of(MergeRequests::ResolvedDiscussionNotificationService) do |instance|
expect(instance).to receive(:execute).with(merge_request)
end
 
post :resolve, params: request_params
end
Loading
Loading
@@ -122,8 +124,10 @@
end
 
it "renders discussion with serializer" do
expect_any_instance_of(DiscussionSerializer).to receive(:represent)
.with(instance_of(Discussion), { context: instance_of(described_class), render_truncated_diff_lines: true })
expect_next_instance_of(DiscussionSerializer) do |instance|
expect(instance).to receive(:represent)
.with(instance_of(Discussion), { context: instance_of(described_class), render_truncated_diff_lines: true })
end
 
post :resolve, params: request_params
end
Loading
Loading
@@ -193,8 +197,10 @@
end
 
it "renders discussion with serializer" do
expect_any_instance_of(DiscussionSerializer).to receive(:represent)
.with(instance_of(Discussion), { context: instance_of(described_class), render_truncated_diff_lines: true })
expect_next_instance_of(DiscussionSerializer) do |instance|
expect(instance).to receive(:represent)
.with(instance_of(Discussion), { context: instance_of(described_class), render_truncated_diff_lines: true })
end
 
delete :unresolve, params: request_params
end
Loading
Loading
Loading
Loading
@@ -13,8 +13,9 @@
 
describe 'GET #new' do
before do
allow_any_instance_of(MattermostSlashCommandsService)
.to receive(:list_teams).and_return([])
allow_next_instance_of(MattermostSlashCommandsService) do |instance|
allow(instance).to receive(:list_teams).and_return([])
end
end
 
it 'accepts the request' do
Loading
Loading
@@ -42,7 +43,9 @@
 
context 'no request can be made to mattermost' do
it 'shows the error' do
allow_any_instance_of(MattermostSlashCommandsService).to receive(:configure).and_return([false, "error message"])
allow_next_instance_of(MattermostSlashCommandsService) do |instance|
allow(instance).to receive(:configure).and_return([false, "error message"])
end
 
expect(subject).to redirect_to(new_project_mattermost_url(project))
end
Loading
Loading
@@ -50,7 +53,9 @@
 
context 'the request is succesull' do
before do
allow_any_instance_of(Mattermost::Command).to receive(:create).and_return('token')
allow_next_instance_of(Mattermost::Command) do |instance|
allow(instance).to receive(:create).and_return('token')
end
end
 
it 'redirects to the new page' do
Loading
Loading
Loading
Loading
@@ -85,7 +85,9 @@
describe 'GET diffs' do
context 'when merge request cannot be created' do
it 'does not assign diffs var' do
allow_any_instance_of(MergeRequest).to receive(:can_be_created).and_return(false)
allow_next_instance_of(MergeRequest) do |instance|
allow(instance).to receive(:can_be_created).and_return(false)
end
 
get :diffs, params: get_diff_params.merge(format: 'json')
 
Loading
Loading
Loading
Loading
@@ -86,7 +86,9 @@ def go(extra_params = {})
end
 
it 'serializes merge request diff collection' do
expect_any_instance_of(DiffsSerializer).to receive(:represent).with(an_instance_of(Gitlab::Diff::FileCollection::MergeRequestDiff), an_instance_of(Hash))
expect_next_instance_of(DiffsSerializer) do |instance|
expect(instance).to receive(:represent).with(an_instance_of(Gitlab::Diff::FileCollection::MergeRequestDiff), an_instance_of(Hash))
end
 
go
end
Loading
Loading
@@ -98,7 +100,9 @@ def go(extra_params = {})
end
 
it 'serializes merge request diff collection' do
expect_any_instance_of(DiffsSerializer).to receive(:represent).with(an_instance_of(Gitlab::Diff::FileCollection::MergeRequestDiff), an_instance_of(Hash))
expect_next_instance_of(DiffsSerializer) do |instance|
expect(instance).to receive(:represent).with(an_instance_of(Gitlab::Diff::FileCollection::MergeRequestDiff), an_instance_of(Hash))
end
 
go
end
Loading
Loading
Loading
Loading
@@ -785,7 +785,9 @@ def create!
end
 
it "sends notifications if all discussions are resolved" do
expect_any_instance_of(MergeRequests::ResolvedDiscussionNotificationService).to receive(:execute).with(merge_request)
expect_next_instance_of(MergeRequests::ResolvedDiscussionNotificationService) do |instance|
expect(instance).to receive(:execute).with(merge_request)
end
 
post :resolve, params: request_params
end
Loading
Loading
Loading
Loading
@@ -45,7 +45,9 @@
end
 
it 'adds user to members' do
expect_any_instance_of(Members::CreateService).to receive(:execute).and_return(status: :success)
expect_next_instance_of(Members::CreateService) do |instance|
expect(instance).to receive(:execute).and_return(status: :success)
end
 
post :create, params: {
namespace_id: project.namespace,
Loading
Loading
@@ -59,7 +61,9 @@
end
 
it 'adds no user to members' do
expect_any_instance_of(Members::CreateService).to receive(:execute).and_return(status: :failure, message: 'Message')
expect_next_instance_of(Members::CreateService) do |instance|
expect(instance).to receive(:execute).and_return(status: :failure, message: 'Message')
end
 
post :create, params: {
namespace_id: project.namespace,
Loading
Loading
Loading
Loading
@@ -85,7 +85,9 @@
end
 
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.__send__(:prometheus_adapter)
end
Loading
Loading
Loading
Loading
@@ -125,7 +125,9 @@
 
context 'when run_auto_devops_pipeline is true' do
before do
expect_any_instance_of(Projects::UpdateService).to receive(:run_auto_devops_pipeline?).and_return(true)
expect_next_instance_of(Projects::UpdateService) do |instance|
expect(instance).to receive(:run_auto_devops_pipeline?).and_return(true)
end
end
 
context 'when the project repository is empty' do
Loading
Loading
@@ -159,7 +161,9 @@
 
context 'when run_auto_devops_pipeline is not true' do
before do
expect_any_instance_of(Projects::UpdateService).to receive(:run_auto_devops_pipeline?).and_return(false)
expect_next_instance_of(Projects::UpdateService) do |instance|
expect(instance).to receive(:run_auto_devops_pipeline?).and_return(false)
end
end
 
it 'does not queue a CreatePipelineWorker' do
Loading
Loading
Loading
Loading
@@ -92,7 +92,9 @@ def create_snippet(project, snippet_params = {}, additional_params = {})
 
context 'when the snippet is spam' do
before do
allow_any_instance_of(AkismetService).to receive(:spam?).and_return(true)
allow_next_instance_of(AkismetService) do |instance|
allow(instance).to receive(:spam?).and_return(true)
end
end
 
context 'when the snippet is private' do
Loading
Loading
@@ -170,7 +172,9 @@ def update_snippet(snippet_params = {}, additional_params = {})
 
context 'when the snippet is spam' do
before do
allow_any_instance_of(AkismetService).to receive(:spam?).and_return(true)
allow_next_instance_of(AkismetService) do |instance|
allow(instance).to receive(:spam?).and_return(true)
end
end
 
context 'when the snippet is private' do
Loading
Loading
@@ -278,7 +282,9 @@ def update_snippet(snippet_params = {}, additional_params = {})
let(:snippet) { create(:project_snippet, :private, project: project, author: user) }
 
before do
allow_any_instance_of(AkismetService).to receive_messages(submit_spam: true)
allow_next_instance_of(AkismetService) do |instance|
allow(instance).to receive_messages(submit_spam: true)
end
stub_application_setting(akismet_enabled: true)
end
 
Loading
Loading
Loading
Loading
@@ -174,7 +174,9 @@
let(:user) { create(:user) }
 
before do
allow_any_instance_of(User).to receive(:contributed_projects_ids).and_return([project.id])
allow_next_instance_of(User) do |instance|
allow(instance).to receive(:contributed_projects_ids).and_return([project.id])
end
 
sign_in(user)
project.add_developer(user)
Loading
Loading
Loading
Loading
@@ -73,8 +73,9 @@
before do
create(:group, name: 'Web')
 
allow_any_instance_of(Projects::TransferService)
.to receive(:move_uploads_to_new_namespace).and_return(true)
allow_next_instance_of(Projects::TransferService) do |instance|
allow(instance).to receive(:move_uploads_to_new_namespace).and_return(true)
end
end
 
it 'transfers project to group web', :js do
Loading
Loading
Loading
Loading
@@ -179,7 +179,9 @@
end
 
it "calls send mail" do
expect_any_instance_of(NotificationService).to receive(:new_user)
expect_next_instance_of(NotificationService) do |instance|
expect(instance).to receive(:new_user)
end
 
click_button "Create user"
end
Loading
Loading
Loading
Loading
@@ -40,7 +40,9 @@
 
context "when there's cycle analytics data" 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
project.add_maintainer(user)
 
@build = create_cycle(user, project, issue, mr, milestone, pipeline)
Loading
Loading
@@ -99,7 +101,9 @@
project.add_developer(user)
project.add_guest(guest)
 
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)
 
Loading
Loading
Loading
Loading
@@ -21,7 +21,9 @@
 
describe 'I search through the issues and I see pagination' do
before do
allow_any_instance_of(Gitlab::SearchResults).to receive(:per_page).and_return(1)
allow_next_instance_of(Gitlab::SearchResults) do |instance|
allow(instance).to receive(:per_page).and_return(1)
end
create_list(:issue, 2, project: project, title: 'initial')
end
 
Loading
Loading
Loading
Loading
@@ -13,8 +13,12 @@
gitlab_sign_in(user)
 
allow(Groups::ClustersController).to receive(:STATUS_POLLING_INTERVAL) { 100 }
allow_any_instance_of(Clusters::Kubernetes::CreateOrUpdateNamespaceService).to receive(:execute)
allow_any_instance_of(Clusters::Cluster).to receive(:retrieve_connection_status).and_return(:connected)
allow_next_instance_of(Clusters::Kubernetes::CreateOrUpdateNamespaceService) do |instance|
allow(instance).to receive(:execute)
end
allow_next_instance_of(Clusters::Cluster) do |instance|
allow(instance).to receive(:retrieve_connection_status).and_return(:connected)
end
end
 
context 'when user does not have a cluster and visits cluster index page' do
Loading
Loading
Loading
Loading
@@ -17,7 +17,9 @@
 
stub_request(:get, "https://jira.example.com/rest/api/2/issue/JIRA-5")
stub_request(:post, "https://jira.example.com/rest/api/2/issue/JIRA-5/comment")
allow_any_instance_of(JIRA::Resource::Issue).to receive(:remotelink).and_return(remotelink)
allow_next_instance_of(JIRA::Resource::Issue) do |instance|
allow(instance).to receive(:remotelink).and_return(remotelink)
end
 
sign_in(user)
 
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment