diff options
author | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-06-22 15:05:52 +0200 |
---|---|---|
committer | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-06-22 15:05:52 +0200 |
commit | 97c42df3b804a37e659c3cda6bd8a52570f31366 (patch) | |
tree | 97c38db7f71a93a7b0db5ca2c682d6d17479cbdb /spec/support | |
parent | 3833f1dd84dfec844443a5b1d9ba2bd2b911c0bc (diff) | |
parent | 11716f310dcc495600f5a17e08456a1abb296482 (diff) | |
download | gitlab-ce-97c42df3b804a37e659c3cda6bd8a52570f31366.tar.gz |
Merge remote-tracking branch 'upstream/master' into 28717-additional-metrics-review-branch28717-additional-metrics-review-branch
Diffstat (limited to 'spec/support')
21 files changed, 181 insertions, 168 deletions
diff --git a/spec/support/capybara.rb b/spec/support/capybara.rb index c34e76fa72f..3e5d6cf1364 100644 --- a/spec/support/capybara.rb +++ b/spec/support/capybara.rb @@ -35,4 +35,14 @@ RSpec.configure do |config| TestEnv.eager_load_driver_server $capybara_server_already_started = true end + + config.after(:each, :js) do |example| + # capybara/rspec already calls Capybara.reset_sessions! in an `after` hook, + # but `block_and_wait_for_requests_complete` is called before it so by + # calling it explicitely here, we prevent any new requests from being fired + # See https://github.com/teamcapybara/capybara/blob/ffb41cfad620de1961bb49b1562a9fa9b28c0903/lib/capybara/rspec.rb#L20-L25 + # We don't reset the session when the example failed, because we need capybara-screenshot to have access to it. + Capybara.reset_sessions! unless example.exception + block_and_wait_for_requests_complete + end end diff --git a/spec/support/chat_slash_commands_shared_examples.rb b/spec/support/chat_slash_commands_shared_examples.rb index 4dfa29849ee..978b0b9cc30 100644 --- a/spec/support/chat_slash_commands_shared_examples.rb +++ b/spec/support/chat_slash_commands_shared_examples.rb @@ -87,7 +87,7 @@ RSpec.shared_examples 'chat slash commands service' do end it 'triggers the command' do - expect_any_instance_of(Gitlab::ChatCommands::Command).to receive(:execute) + expect_any_instance_of(Gitlab::SlashCommands::Command).to receive(:execute) subject.trigger(params) end diff --git a/spec/support/controllers/githubish_import_controller_shared_examples.rb b/spec/support/controllers/githubish_import_controller_shared_examples.rb index d6b40db09ce..a8d9566b4e4 100644 --- a/spec/support/controllers/githubish_import_controller_shared_examples.rb +++ b/spec/support/controllers/githubish_import_controller_shared_examples.rb @@ -14,8 +14,8 @@ shared_examples 'a GitHub-ish import controller: POST personal_access_token' do it "updates access token" do token = 'asdfasdf9876' - allow_any_instance_of(Gitlab::GithubImport::Client). - to receive(:user).and_return(true) + allow_any_instance_of(Gitlab::GithubImport::Client) + .to receive(:user).and_return(true) post :personal_access_token, personal_access_token: token @@ -79,8 +79,8 @@ shared_examples 'a GitHub-ish import controller: GET status' do end it "handles an invalid access token" do - allow_any_instance_of(Gitlab::GithubImport::Client). - to receive(:repos).and_raise(Octokit::Unauthorized) + allow_any_instance_of(Gitlab::GithubImport::Client) + .to receive(:repos).and_raise(Octokit::Unauthorized) get :status @@ -110,9 +110,9 @@ shared_examples 'a GitHub-ish import controller: POST create' do context "when the repository owner is the provider user" do context "when the provider user and GitLab user's usernames match" do it "takes the current user's namespace" do - expect(Gitlab::GithubImport::ProjectCreator). - to receive(:new).with(provider_repo, provider_repo.name, user.namespace, user, access_params, type: provider). - and_return(double(execute: true)) + expect(Gitlab::GithubImport::ProjectCreator) + .to receive(:new).with(provider_repo, provider_repo.name, user.namespace, user, access_params, type: provider) + .and_return(double(execute: true)) post :create, format: :js end @@ -122,9 +122,9 @@ shared_examples 'a GitHub-ish import controller: POST create' do let(:provider_username) { "someone_else" } it "takes the current user's namespace" do - expect(Gitlab::GithubImport::ProjectCreator). - to receive(:new).with(provider_repo, provider_repo.name, user.namespace, user, access_params, type: provider). - and_return(double(execute: true)) + expect(Gitlab::GithubImport::ProjectCreator) + .to receive(:new).with(provider_repo, provider_repo.name, user.namespace, user, access_params, type: provider) + .and_return(double(execute: true)) post :create, format: :js end @@ -144,9 +144,9 @@ shared_examples 'a GitHub-ish import controller: POST create' do context "when the namespace is owned by the GitLab user" do it "takes the existing namespace" do - expect(Gitlab::GithubImport::ProjectCreator). - to receive(:new).with(provider_repo, provider_repo.name, existing_namespace, user, access_params, type: provider). - and_return(double(execute: true)) + expect(Gitlab::GithubImport::ProjectCreator) + .to receive(:new).with(provider_repo, provider_repo.name, existing_namespace, user, access_params, type: provider) + .and_return(double(execute: true)) post :create, format: :js end @@ -159,9 +159,9 @@ shared_examples 'a GitHub-ish import controller: POST create' do end it "creates a project using user's namespace" do - expect(Gitlab::GithubImport::ProjectCreator). - to receive(:new).with(provider_repo, provider_repo.name, user.namespace, user, access_params, type: provider). - and_return(double(execute: true)) + expect(Gitlab::GithubImport::ProjectCreator) + .to receive(:new).with(provider_repo, provider_repo.name, user.namespace, user, access_params, type: provider) + .and_return(double(execute: true)) post :create, format: :js end @@ -171,16 +171,16 @@ shared_examples 'a GitHub-ish import controller: POST create' do context "when a namespace with the provider user's username doesn't exist" do context "when current user can create namespaces" do it "creates the namespace" do - expect(Gitlab::GithubImport::ProjectCreator). - to receive(:new).and_return(double(execute: true)) + expect(Gitlab::GithubImport::ProjectCreator) + .to receive(:new).and_return(double(execute: true)) expect { post :create, target_namespace: provider_repo.name, format: :js }.to change(Namespace, :count).by(1) end it "takes the new namespace" do - expect(Gitlab::GithubImport::ProjectCreator). - to receive(:new).with(provider_repo, provider_repo.name, an_instance_of(Group), user, access_params, type: provider). - and_return(double(execute: true)) + expect(Gitlab::GithubImport::ProjectCreator) + .to receive(:new).with(provider_repo, provider_repo.name, an_instance_of(Group), user, access_params, type: provider) + .and_return(double(execute: true)) post :create, target_namespace: provider_repo.name, format: :js end @@ -192,16 +192,16 @@ shared_examples 'a GitHub-ish import controller: POST create' do end it "doesn't create the namespace" do - expect(Gitlab::GithubImport::ProjectCreator). - to receive(:new).and_return(double(execute: true)) + expect(Gitlab::GithubImport::ProjectCreator) + .to receive(:new).and_return(double(execute: true)) expect { post :create, format: :js }.not_to change(Namespace, :count) end it "takes the current user's namespace" do - expect(Gitlab::GithubImport::ProjectCreator). - to receive(:new).with(provider_repo, provider_repo.name, user.namespace, user, access_params, type: provider). - and_return(double(execute: true)) + expect(Gitlab::GithubImport::ProjectCreator) + .to receive(:new).with(provider_repo, provider_repo.name, user.namespace, user, access_params, type: provider) + .and_return(double(execute: true)) post :create, format: :js end @@ -217,17 +217,17 @@ shared_examples 'a GitHub-ish import controller: POST create' do end it 'takes the selected namespace and name' do - expect(Gitlab::GithubImport::ProjectCreator). - to receive(:new).with(provider_repo, test_name, test_namespace, user, access_params, type: provider). - and_return(double(execute: true)) + expect(Gitlab::GithubImport::ProjectCreator) + .to receive(:new).with(provider_repo, test_name, test_namespace, user, access_params, type: provider) + .and_return(double(execute: true)) post :create, { target_namespace: test_namespace.name, new_name: test_name, format: :js } end it 'takes the selected name and default namespace' do - expect(Gitlab::GithubImport::ProjectCreator). - to receive(:new).with(provider_repo, test_name, user.namespace, user, access_params, type: provider). - and_return(double(execute: true)) + expect(Gitlab::GithubImport::ProjectCreator) + .to receive(:new).with(provider_repo, test_name, user.namespace, user, access_params, type: provider) + .and_return(double(execute: true)) post :create, { new_name: test_name, format: :js } end @@ -243,9 +243,9 @@ shared_examples 'a GitHub-ish import controller: POST create' do end it 'takes the selected namespace and name' do - expect(Gitlab::GithubImport::ProjectCreator). - to receive(:new).with(provider_repo, test_name, nested_namespace, user, access_params, type: provider). - and_return(double(execute: true)) + expect(Gitlab::GithubImport::ProjectCreator) + .to receive(:new).with(provider_repo, test_name, nested_namespace, user, access_params, type: provider) + .and_return(double(execute: true)) post :create, { target_namespace: nested_namespace.full_path, new_name: test_name, format: :js } end @@ -255,26 +255,26 @@ shared_examples 'a GitHub-ish import controller: POST create' do let(:test_name) { 'test_name' } it 'takes the selected namespace and name' do - expect(Gitlab::GithubImport::ProjectCreator). - to receive(:new).with(provider_repo, test_name, kind_of(Namespace), user, access_params, type: provider). - and_return(double(execute: true)) + expect(Gitlab::GithubImport::ProjectCreator) + .to receive(:new).with(provider_repo, test_name, kind_of(Namespace), user, access_params, type: provider) + .and_return(double(execute: true)) post :create, { target_namespace: 'foo/bar', new_name: test_name, format: :js } end it 'creates the namespaces' do - allow(Gitlab::GithubImport::ProjectCreator). - to receive(:new).with(provider_repo, test_name, kind_of(Namespace), user, access_params, type: provider). - and_return(double(execute: true)) + allow(Gitlab::GithubImport::ProjectCreator) + .to receive(:new).with(provider_repo, test_name, kind_of(Namespace), user, access_params, type: provider) + .and_return(double(execute: true)) expect { post :create, { target_namespace: 'foo/bar', new_name: test_name, format: :js } } .to change { Namespace.count }.by(2) end it 'new namespace has the right parent' do - allow(Gitlab::GithubImport::ProjectCreator). - to receive(:new).with(provider_repo, test_name, kind_of(Namespace), user, access_params, type: provider). - and_return(double(execute: true)) + allow(Gitlab::GithubImport::ProjectCreator) + .to receive(:new).with(provider_repo, test_name, kind_of(Namespace), user, access_params, type: provider) + .and_return(double(execute: true)) post :create, { target_namespace: 'foo/bar', new_name: test_name, format: :js } @@ -287,17 +287,17 @@ shared_examples 'a GitHub-ish import controller: POST create' do let!(:parent_namespace) { create(:group, name: 'foo', owner: user) } it 'takes the selected namespace and name' do - expect(Gitlab::GithubImport::ProjectCreator). - to receive(:new).with(provider_repo, test_name, kind_of(Namespace), user, access_params, type: provider). - and_return(double(execute: true)) + expect(Gitlab::GithubImport::ProjectCreator) + .to receive(:new).with(provider_repo, test_name, kind_of(Namespace), user, access_params, type: provider) + .and_return(double(execute: true)) post :create, { target_namespace: 'foo/foobar/bar', new_name: test_name, format: :js } end it 'creates the namespaces' do - allow(Gitlab::GithubImport::ProjectCreator). - to receive(:new).with(provider_repo, test_name, kind_of(Namespace), user, access_params, type: provider). - and_return(double(execute: true)) + allow(Gitlab::GithubImport::ProjectCreator) + .to receive(:new).with(provider_repo, test_name, kind_of(Namespace), user, access_params, type: provider) + .and_return(double(execute: true)) expect { post :create, { target_namespace: 'foo/foobar/bar', new_name: test_name, format: :js } } .to change { Namespace.count }.by(2) diff --git a/spec/support/features/issuable_slash_commands_shared_examples.rb b/spec/support/features/issuable_slash_commands_shared_examples.rb index fa82dc5e9f9..50869099bb7 100644 --- a/spec/support/features/issuable_slash_commands_shared_examples.rb +++ b/spec/support/features/issuable_slash_commands_shared_examples.rb @@ -1,8 +1,8 @@ # Specifications for behavior common to all objects with executable attributes. # It takes a `issuable_type`, and expect an `issuable`. -shared_examples 'issuable record that supports slash commands in its description and notes' do |issuable_type| - include SlashCommandsHelpers +shared_examples 'issuable record that supports quick actions in its description and notes' do |issuable_type| + include QuickActionsHelpers let(:master) { create(:user) } let(:assignee) { create(:user, username: 'bob') } @@ -17,7 +17,7 @@ shared_examples 'issuable record that supports slash commands in its description project.team << [master, :master] project.team << [assignee, :developer] project.team << [guest, :guest] - login_with(master) + gitlab_sign_in(master) end after do @@ -105,8 +105,8 @@ shared_examples 'issuable record that supports slash commands in its description context "when current user cannot close #{issuable_type}" do before do - logout - login_with(guest) + gitlab_sign_out + gitlab_sign_in(guest) visit public_send("namespace_project_#{issuable_type}_path", project.namespace, project, issuable) end @@ -140,8 +140,8 @@ shared_examples 'issuable record that supports slash commands in its description context "when current user cannot reopen #{issuable_type}" do before do - logout - login_with(guest) + gitlab_sign_out + gitlab_sign_in(guest) visit public_send("namespace_project_#{issuable_type}_path", project.namespace, project, issuable) end @@ -170,8 +170,8 @@ shared_examples 'issuable record that supports slash commands in its description context "when current user cannot change title of #{issuable_type}" do before do - logout - login_with(guest) + gitlab_sign_out + gitlab_sign_in(guest) visit public_send("namespace_project_#{issuable_type}_path", project.namespace, project, issuable) end @@ -260,7 +260,7 @@ shared_examples 'issuable record that supports slash commands in its description end describe "preview of note on #{issuable_type}" do - it 'removes slash commands from note and explains them' do + it 'removes quick actions from note and explains them' do visit public_send("namespace_project_#{issuable_type}_path", project.namespace, project, issuable) page.within('.js-main-target-form') do diff --git a/spec/support/features/reportable_note_shared_examples.rb b/spec/support/features/reportable_note_shared_examples.rb index 0d80c95e826..27e079c01dd 100644 --- a/spec/support/features/reportable_note_shared_examples.rb +++ b/spec/support/features/reportable_note_shared_examples.rb @@ -13,9 +13,7 @@ shared_examples 'reportable note' do it 'dropdown has Edit, Report and Delete links' do dropdown = comment.find(more_actions_selector) - - dropdown.click - dropdown.find('.dropdown-menu li', match: :first) + open_dropdown(dropdown) expect(dropdown).to have_button('Edit comment') expect(dropdown).to have_link('Report as abuse', href: abuse_report_path) @@ -24,13 +22,16 @@ shared_examples 'reportable note' do it 'Report button links to a report page' do dropdown = comment.find(more_actions_selector) - - dropdown.click - dropdown.find('.dropdown-menu li', match: :first) + open_dropdown(dropdown) dropdown.click_link('Report as abuse') expect(find('#user_name')['value']).to match(note.author.username) expect(find('#abuse_report_message')['value']).to match(noteable_note_url(note)) end + + def open_dropdown(dropdown) + dropdown.click + dropdown.find('.dropdown-menu li', match: :first) + end end diff --git a/spec/support/filtered_search_helpers.rb b/spec/support/filtered_search_helpers.rb index 37cc308e613..d21c4324d9e 100644 --- a/spec/support/filtered_search_helpers.rb +++ b/spec/support/filtered_search_helpers.rb @@ -14,6 +14,9 @@ module FilteredSearchHelpers filtered_search.set(search) if submit + # Wait for the lazy author/assignee tokens that + # swap out the username with an avatar and name + wait_for_requests filtered_search.send_keys(:enter) end end diff --git a/spec/support/login_helpers.rb b/spec/support/login_helpers.rb index e6da852e728..879386b5437 100644 --- a/spec/support/login_helpers.rb +++ b/spec/support/login_helpers.rb @@ -6,15 +6,15 @@ module LoginHelpers # Examples: # # # Create a user automatically - # login_as(:user) + # gitlab_sign_in(:user) # # # Create an admin automatically - # login_as(:admin) + # gitlab_sign_in(:admin) # # # Provide an existing User record # user = create(:user) - # login_as(user) - def login_as(user_or_role) + # gitlab_sign_in(user) + def gitlab_sign_in(user_or_role, **kwargs) @user = if user_or_role.is_a?(User) user_or_role @@ -22,26 +22,44 @@ module LoginHelpers create(user_or_role) end - login_with(@user) + gitlab_sign_in_with(@user, **kwargs) end - # Internal: Login as the specified user + def gitlab_sign_in_via(provider, user, uid) + mock_auth_hash(provider, uid, user.email) + visit new_user_session_path + click_link provider + end + + # Requires Javascript driver. + def gitlab_sign_out + find(".header-user-dropdown-toggle").click + click_link "Sign out" + # check the sign_in button + expect(page).to have_button('Sign in') + end + + # Logout without JavaScript driver + def gitlab_sign_out_direct + page.driver.submit :delete, '/users/sign_out', {} + end + + private + + # Private: Login as the specified user # # user - User instance to login with # remember - Whether or not to check "Remember me" (default: false) - def login_with(user, remember: false) + def gitlab_sign_in_with(user, remember: false) visit new_user_session_path + fill_in "user_login", with: user.email fill_in "user_password", with: "12345678" check 'user_remember_me' if remember + click_button "Sign in" - Thread.current[:current_user] = user - end - def login_via(provider, user, uid) - mock_auth_hash(provider, uid, user.email) - visit new_user_session_path - click_link provider + Thread.current[:current_user] = user end def mock_auth_hash(provider, uid, email) @@ -71,17 +89,4 @@ module LoginHelpers }) Rails.application.env_config['omniauth.auth'] = OmniAuth.config.mock_auth[:saml] end - - # Requires Javascript driver. - def logout - find(".header-user-dropdown-toggle").click - click_link "Sign out" - # check the sign_in button - expect(page).to have_button('Sign in') - end - - # Logout without JavaScript driver - def logout_direct - page.driver.submit :delete, '/users/sign_out', {} - end end diff --git a/spec/support/mentionable_shared_examples.rb b/spec/support/mentionable_shared_examples.rb index 87936bb4859..3ac201f1fb1 100644 --- a/spec/support/mentionable_shared_examples.rb +++ b/spec/support/mentionable_shared_examples.rb @@ -81,8 +81,8 @@ shared_examples 'a mentionable' do ext_issue, ext_mr, ext_commit] mentioned_objects.each do |referenced| - expect(SystemNoteService).to receive(:cross_reference). - with(referenced, subject.local_reference, author) + expect(SystemNoteService).to receive(:cross_reference) + .with(referenced, subject.local_reference, author) end subject.create_cross_references! @@ -127,15 +127,15 @@ shared_examples 'an editable mentionable' do # These three objects were already referenced, and should not receive new # notes [mentioned_issue, mentioned_commit, ext_issue].each do |oldref| - expect(SystemNoteService).not_to receive(:cross_reference). - with(oldref, any_args) + expect(SystemNoteService).not_to receive(:cross_reference) + .with(oldref, any_args) end # These two issues are new and should receive reference notes # In the case of MergeRequests remember that cannot mention commits included in the MergeRequest new_issues.each do |newref| - expect(SystemNoteService).to receive(:cross_reference). - with(newref, subject.local_reference, author) + expect(SystemNoteService).to receive(:cross_reference) + .with(newref, subject.local_reference, author) end set_mentionable_text.call(new_text) diff --git a/spec/support/project_features_apply_to_issuables_shared_examples.rb b/spec/support/project_features_apply_to_issuables_shared_examples.rb index f8b7d0527ba..81b51509e0b 100644 --- a/spec/support/project_features_apply_to_issuables_shared_examples.rb +++ b/spec/support/project_features_apply_to_issuables_shared_examples.rb @@ -18,7 +18,7 @@ shared_examples 'project features apply to issuables' do |klass| before do _ = issuable - login_as(user) if user + gitlab_sign_in(user) if user visit path end diff --git a/spec/support/slash_commands_helpers.rb b/spec/support/quick_actions_helpers.rb index 4bfe481115f..d2aaae7518f 100644 --- a/spec/support/slash_commands_helpers.rb +++ b/spec/support/quick_actions_helpers.rb @@ -1,4 +1,4 @@ -module SlashCommandsHelpers +module QuickActionsHelpers def write_note(text) Sidekiq::Testing.fake! do page.within('.js-main-target-form') do diff --git a/spec/support/reactive_caching_helpers.rb b/spec/support/reactive_caching_helpers.rb index 98eb57f8b54..34124f02133 100644 --- a/spec/support/reactive_caching_helpers.rb +++ b/spec/support/reactive_caching_helpers.rb @@ -35,8 +35,8 @@ module ReactiveCachingHelpers end def expect_reactive_cache_update_queued(subject) - expect(ReactiveCachingWorker). - to receive(:perform_in). - with(subject.class.reactive_cache_refresh_interval, subject.class, subject.id) + expect(ReactiveCachingWorker) + .to receive(:perform_in) + .with(subject.class.reactive_cache_refresh_interval, subject.class, subject.id) end end diff --git a/spec/support/services/issuable_create_service_slash_commands_shared_examples.rb b/spec/support/services/issuable_create_service_slash_commands_shared_examples.rb index 5e6f9f323a1..9399745f900 100644 --- a/spec/support/services/issuable_create_service_slash_commands_shared_examples.rb +++ b/spec/support/services/issuable_create_service_slash_commands_shared_examples.rb @@ -1,7 +1,7 @@ # Specifications for behavior common to all objects with executable attributes. # It can take a `default_params`. -shared_examples 'new issuable record that supports slash commands' do +shared_examples 'new issuable record that supports quick actions' do let!(:project) { create(:project, :repository) } let(:user) { create(:user).tap { |u| project.team << [u, :master] } } let(:assignee) { create(:user) } diff --git a/spec/support/services_shared_context.rb b/spec/support/services_shared_context.rb index 66c93890e31..7457484a932 100644 --- a/spec/support/services_shared_context.rb +++ b/spec/support/services_shared_context.rb @@ -6,9 +6,9 @@ Service.available_services_names.each do |service| let(:service_fields) { service_klass.new.fields } let(:service_attrs_list) { service_fields.inject([]) {|arr, hash| arr << hash[:name].to_sym } } let(:service_attrs_list_without_passwords) do - service_fields. - select { |field| field[:type] != 'password' }. - map { |field| field[:name].to_sym} + service_fields + .select { |field| field[:type] != 'password' } + .map { |field| field[:name].to_sym} end let(:service_attrs) do service_attrs_list.inject({}) do |hash, k| diff --git a/spec/support/slack_mattermost_notifications_shared_examples.rb b/spec/support/slack_mattermost_notifications_shared_examples.rb index a7deb038703..044c09d5fde 100644 --- a/spec/support/slack_mattermost_notifications_shared_examples.rb +++ b/spec/support/slack_mattermost_notifications_shared_examples.rb @@ -108,9 +108,9 @@ RSpec.shared_examples 'slack or mattermost notifications' do it 'uses the username as an option for slack when configured' do allow(chat_service).to receive(:username).and_return(username) - expect(Slack::Notifier).to receive(:new). - with(webhook_url, username: username). - and_return( + expect(Slack::Notifier).to receive(:new) + .with(webhook_url, username: username) + .and_return( double(:slack_service).as_null_object ) @@ -119,9 +119,9 @@ RSpec.shared_examples 'slack or mattermost notifications' do it 'uses the channel as an option when it is configured' do allow(chat_service).to receive(:channel).and_return(channel) - expect(Slack::Notifier).to receive(:new). - with(webhook_url, channel: channel). - and_return( + expect(Slack::Notifier).to receive(:new) + .with(webhook_url, channel: channel) + .and_return( double(:slack_service).as_null_object ) chat_service.execute(push_sample_data) @@ -131,9 +131,9 @@ RSpec.shared_examples 'slack or mattermost notifications' do it "uses the right channel for push event" do chat_service.update_attributes(push_channel: "random") - expect(Slack::Notifier).to receive(:new). - with(webhook_url, channel: "random"). - and_return( + expect(Slack::Notifier).to receive(:new) + .with(webhook_url, channel: "random") + .and_return( double(:slack_service).as_null_object ) @@ -143,9 +143,9 @@ RSpec.shared_examples 'slack or mattermost notifications' do it "uses the right channel for merge request event" do chat_service.update_attributes(merge_request_channel: "random") - expect(Slack::Notifier).to receive(:new). - with(webhook_url, channel: "random"). - and_return( + expect(Slack::Notifier).to receive(:new) + .with(webhook_url, channel: "random") + .and_return( double(:slack_service).as_null_object ) @@ -155,9 +155,9 @@ RSpec.shared_examples 'slack or mattermost notifications' do it "uses the right channel for issue event" do chat_service.update_attributes(issue_channel: "random") - expect(Slack::Notifier).to receive(:new). - with(webhook_url, channel: "random"). - and_return( + expect(Slack::Notifier).to receive(:new) + .with(webhook_url, channel: "random") + .and_return( double(:slack_service).as_null_object ) @@ -167,9 +167,9 @@ RSpec.shared_examples 'slack or mattermost notifications' do it "uses the right channel for wiki event" do chat_service.update_attributes(wiki_page_channel: "random") - expect(Slack::Notifier).to receive(:new). - with(webhook_url, channel: "random"). - and_return( + expect(Slack::Notifier).to receive(:new) + .with(webhook_url, channel: "random") + .and_return( double(:slack_service).as_null_object ) @@ -186,9 +186,9 @@ RSpec.shared_examples 'slack or mattermost notifications' do note_data = Gitlab::DataBuilder::Note.build(issue_note, user) - expect(Slack::Notifier).to receive(:new). - with(webhook_url, channel: "random"). - and_return( + expect(Slack::Notifier).to receive(:new) + .with(webhook_url, channel: "random") + .and_return( double(:slack_service).as_null_object ) diff --git a/spec/support/stub_configuration.rb b/spec/support/stub_configuration.rb index b39a23bd18a..48f454c7187 100644 --- a/spec/support/stub_configuration.rb +++ b/spec/support/stub_configuration.rb @@ -5,8 +5,8 @@ module StubConfiguration # Stubbing both of these because we're not yet consistent with how we access # current application settings allow_any_instance_of(ApplicationSetting).to receive_messages(messages) - allow(Gitlab::CurrentSettings.current_application_settings). - to receive_messages(messages) + allow(Gitlab::CurrentSettings.current_application_settings) + .to receive_messages(messages) end def stub_config_setting(messages) diff --git a/spec/support/stub_gitlab_calls.rb b/spec/support/stub_gitlab_calls.rb index ded2d593059..78a2ff73746 100644 --- a/spec/support/stub_gitlab_calls.rb +++ b/spec/support/stub_gitlab_calls.rb @@ -68,22 +68,22 @@ module StubGitlabCalls def stub_session f = File.read(Rails.root.join('spec/support/gitlab_stubs/session.json')) - stub_request(:post, "#{gitlab_url}api/v3/session.json"). - with(body: "{\"email\":\"test@test.com\",\"password\":\"123456\"}", - headers: { 'Content-Type' => 'application/json' }). - to_return(status: 201, body: f, headers: { 'Content-Type' => 'application/json' }) + stub_request(:post, "#{gitlab_url}api/v3/session.json") + .with(body: "{\"email\":\"test@test.com\",\"password\":\"123456\"}", + headers: { 'Content-Type' => 'application/json' }) + .to_return(status: 201, body: f, headers: { 'Content-Type' => 'application/json' }) end def stub_user f = File.read(Rails.root.join('spec/support/gitlab_stubs/user.json')) - stub_request(:get, "#{gitlab_url}api/v3/user?private_token=Wvjy2Krpb7y8xi93owUz"). - with(headers: { 'Content-Type' => 'application/json' }). - to_return(status: 200, body: f, headers: { 'Content-Type' => 'application/json' }) + stub_request(:get, "#{gitlab_url}api/v3/user?private_token=Wvjy2Krpb7y8xi93owUz") + .with(headers: { 'Content-Type' => 'application/json' }) + .to_return(status: 200, body: f, headers: { 'Content-Type' => 'application/json' }) - stub_request(:get, "#{gitlab_url}api/v3/user?access_token=some_token"). - with(headers: { 'Content-Type' => 'application/json' }). - to_return(status: 200, body: f, headers: { 'Content-Type' => 'application/json' }) + stub_request(:get, "#{gitlab_url}api/v3/user?access_token=some_token") + .with(headers: { 'Content-Type' => 'application/json' }) + .to_return(status: 200, body: f, headers: { 'Content-Type' => 'application/json' }) end def stub_project_8 @@ -99,21 +99,21 @@ module StubGitlabCalls def stub_projects f = File.read(Rails.root.join('spec/support/gitlab_stubs/projects.json')) - stub_request(:get, "#{gitlab_url}api/v3/projects.json?archived=false&ci_enabled_first=true&private_token=Wvjy2Krpb7y8xi93owUz"). - with(headers: { 'Content-Type' => 'application/json' }). - to_return(status: 200, body: f, headers: { 'Content-Type' => 'application/json' }) + stub_request(:get, "#{gitlab_url}api/v3/projects.json?archived=false&ci_enabled_first=true&private_token=Wvjy2Krpb7y8xi93owUz") + .with(headers: { 'Content-Type' => 'application/json' }) + .to_return(status: 200, body: f, headers: { 'Content-Type' => 'application/json' }) end def stub_projects_owned - stub_request(:get, "#{gitlab_url}api/v3/projects/owned.json?archived=false&ci_enabled_first=true&private_token=Wvjy2Krpb7y8xi93owUz"). - with(headers: { 'Content-Type' => 'application/json' }). - to_return(status: 200, body: "", headers: {}) + stub_request(:get, "#{gitlab_url}api/v3/projects/owned.json?archived=false&ci_enabled_first=true&private_token=Wvjy2Krpb7y8xi93owUz") + .with(headers: { 'Content-Type' => 'application/json' }) + .to_return(status: 200, body: "", headers: {}) end def stub_ci_enable - stub_request(:put, "#{gitlab_url}api/v3/projects/2/services/gitlab-ci.json?private_token=Wvjy2Krpb7y8xi93owUz"). - with(headers: { 'Content-Type' => 'application/json' }). - to_return(status: 200, body: "", headers: {}) + stub_request(:put, "#{gitlab_url}api/v3/projects/2/services/gitlab-ci.json?private_token=Wvjy2Krpb7y8xi93owUz") + .with(headers: { 'Content-Type' => 'application/json' }) + .to_return(status: 200, body: "", headers: {}) end def project_hash_array diff --git a/spec/support/test_env.rb b/spec/support/test_env.rb index 3f472e59c49..1c5267c290b 100644 --- a/spec/support/test_env.rb +++ b/spec/support/test_env.rb @@ -83,13 +83,13 @@ module TestEnv end def disable_mailer - allow_any_instance_of(NotificationService).to receive(:mailer). - and_return(double.as_null_object) + allow_any_instance_of(NotificationService).to receive(:mailer) + .and_return(double.as_null_object) end def enable_mailer - allow_any_instance_of(NotificationService).to receive(:mailer). - and_call_original + allow_any_instance_of(NotificationService).to receive(:mailer) + .and_call_original end def disable_pre_receive diff --git a/spec/support/time_tracking_shared_examples.rb b/spec/support/time_tracking_shared_examples.rb index b407b8097d2..0fa74f911f6 100644 --- a/spec/support/time_tracking_shared_examples.rb +++ b/spec/support/time_tracking_shared_examples.rb @@ -54,7 +54,7 @@ shared_examples 'issuable time tracker' do it 'shows the help state when icon is clicked' do page.within '.time-tracking-component-wrap' do find('.help-button').click - expect(page).to have_content 'Track time with slash commands' + expect(page).to have_content 'Track time with quick actions' expect(page).to have_content 'Learn more' end end @@ -64,7 +64,7 @@ shared_examples 'issuable time tracker' do find('.help-button').click find('.close-help-button').click - expect(page).not_to have_content 'Track time with slash commands' + expect(page).not_to have_content 'Track time with quick actions' expect(page).not_to have_content 'Learn more' end end @@ -78,8 +78,8 @@ shared_examples 'issuable time tracker' do end end -def submit_time(slash_command) - fill_in 'note[note]', with: slash_command +def submit_time(quick_action) + fill_in 'note[note]', with: quick_action find('.js-comment-submit-button').trigger('click') wait_for_requests end diff --git a/spec/support/update_invalid_issuable.rb b/spec/support/update_invalid_issuable.rb index 365c34448ac..1490287681b 100644 --- a/spec/support/update_invalid_issuable.rb +++ b/spec/support/update_invalid_issuable.rb @@ -21,8 +21,8 @@ shared_examples 'update invalid issuable' do |klass| context 'when updating causes conflicts' do before do - allow_any_instance_of(issuable.class).to receive(:save). - and_raise(ActiveRecord::StaleObjectError.new(issuable, :save)) + allow_any_instance_of(issuable.class).to receive(:save) + .and_raise(ActiveRecord::StaleObjectError.new(issuable, :save)) end it 'renders edit when format is html' do diff --git a/spec/support/user_activities_helpers.rb b/spec/support/user_activities_helpers.rb index f7ca9a31edd..44feb104644 100644 --- a/spec/support/user_activities_helpers.rb +++ b/spec/support/user_activities_helpers.rb @@ -1,7 +1,7 @@ module UserActivitiesHelpers def user_activity(user) - Gitlab::UserActivities.new. - find { |k, _| k == user.id.to_s }&. + Gitlab::UserActivities.new + .find { |k, _| k == user.id.to_s }&. second end end diff --git a/spec/support/wait_for_requests.rb b/spec/support/wait_for_requests.rb index 1cbe609c0e0..b5c3c0f55b8 100644 --- a/spec/support/wait_for_requests.rb +++ b/spec/support/wait_for_requests.rb @@ -53,9 +53,3 @@ module WaitForRequests Capybara.current_driver == Capybara.javascript_driver end end - -RSpec.configure do |config| - config.after(:each, :js) do - block_and_wait_for_requests_complete - end -end |