Merge branch 'add-cop-for-rspec-file-paths' into 'master'

Add RSpec/TopLevelDescribePath cop

See merge request gitlab-org/gitlab-ce!31241
This commit is contained in:
Ash McKenzie 2019-08-02 01:38:13 +00:00
commit 325c321c72
19 changed files with 150 additions and 66 deletions

View file

@ -53,7 +53,7 @@
- close_msg = group ? 'You may close the milestone now.' : 'Navigate to the project to close the milestone.'
%span All issues for this milestone are closed. #{close_msg}
= render_if_exists 'shared/milestones/burndown', milestone: @milestone, project: @project
= render_if_exists 'shared/milestones/burndown', milestone: milestone, project: @project
- if is_dynamic_milestone
.table-holder

View file

@ -0,0 +1,35 @@
# frozen_string_literal: true
require 'rubocop/rspec/top_level_describe'
module RuboCop
module Cop
module RSpec
class TopLevelDescribePath < RuboCop::Cop::Cop
include RuboCop::RSpec::TopLevelDescribe
MESSAGE = 'A file with a top-level `describe` must end in _spec.rb.'
SHARED_EXAMPLES = %i[shared_examples shared_examples_for].freeze
def on_top_level_describe(node, args)
return if acceptable_file_path?(processed_source.buffer.name)
return if shared_example?(node)
add_offense(node, message: MESSAGE)
end
private
def acceptable_file_path?(path)
File.fnmatch?('*_spec.rb', path) || File.fnmatch?('*/frontend/fixtures/*', path)
end
def shared_example?(node)
node.ancestors.any? do |node|
node.respond_to?(:method_name) && SHARED_EXAMPLES.include?(node.method_name)
end
end
end
end
end
end

View file

@ -32,6 +32,7 @@ require_relative 'cop/migration/update_large_table'
require_relative 'cop/project_path_helper'
require_relative 'cop/rspec/env_assignment'
require_relative 'cop/rspec/factories_in_migration_specs'
require_relative 'cop/rspec/top_level_describe_path'
require_relative 'cop/qa/element_with_pattern'
require_relative 'cop/sidekiq_options_queue'
require_relative 'cop/destroy_all'

View file

@ -11,7 +11,9 @@ describe 'Groups > Labels > User sees links to issuables' do
end
it 'shows links to MRs and issues' do
expect(page).to have_link('view merge requests')
expect(page).to have_link('view open issues')
page.within('.labels-container') do
expect(page).to have_link('Merge requests')
expect(page).to have_link('Issues')
end
end
end

View file

@ -3,7 +3,8 @@
require 'spec_helper'
# This is a regression test for https://gitlab.com/gitlab-org/gitlab-ce/issues/37569
describe 'Projects > Files > User browses a tree with a folder containing only a folder' do
# Quarantine: https://gitlab.com/gitlab-org/gitlab-ce/issues/65329
describe 'Projects > Files > User browses a tree with a folder containing only a folder', :quarantine do
let(:project) { create(:project, :empty_repo) }
let(:user) { project.owner }

View file

@ -19,8 +19,10 @@ describe 'Projects > Labels > User sees links to issuables' do
let(:project) { create(:project, :public) }
it 'shows links to MRs and issues' do
expect(page).to have_link('view merge requests')
expect(page).to have_link('view open issues')
page.within('.labels-container') do
expect(page).to have_link('Merge requests')
expect(page).to have_link('Issues')
end
end
end
@ -28,8 +30,10 @@ describe 'Projects > Labels > User sees links to issuables' do
let(:project) { create(:project, :public, issues_access_level: ProjectFeature::DISABLED) }
it 'shows links to MRs but not to issues' do
expect(page).to have_link('view merge requests')
expect(page).not_to have_link('view open issues')
page.within('.labels-container') do
expect(page).to have_link('Merge requests')
expect(page).not_to have_link('Issues')
end
end
end
@ -37,8 +41,10 @@ describe 'Projects > Labels > User sees links to issuables' do
let(:project) { create(:project, :public, merge_requests_access_level: ProjectFeature::DISABLED) }
it 'shows links to issues but not to MRs' do
expect(page).not_to have_link('view merge requests')
expect(page).to have_link('view open issues')
page.within('.labels-container') do
expect(page).not_to have_link('Merge requests')
expect(page).to have_link('Issues')
end
end
end
end
@ -51,8 +57,10 @@ describe 'Projects > Labels > User sees links to issuables' do
let(:project) { create(:project, :public, namespace: group) }
it 'shows links to MRs and issues' do
expect(page).to have_link('view merge requests')
expect(page).to have_link('view open issues')
page.within('.labels-container') do
expect(page).to have_link('Merge requests')
expect(page).to have_link('Issues')
end
end
end
@ -60,8 +68,10 @@ describe 'Projects > Labels > User sees links to issuables' do
let(:project) { create(:project, :public, namespace: group, issues_access_level: ProjectFeature::DISABLED) }
it 'shows links to MRs and issues' do
expect(page).to have_link('view merge requests')
expect(page).to have_link('view open issues')
page.within('.labels-container') do
expect(page).to have_link('Merge requests')
expect(page).to have_link('Issues')
end
end
end
@ -69,8 +79,10 @@ describe 'Projects > Labels > User sees links to issuables' do
let(:project) { create(:project, :public, namespace: group, merge_requests_access_level: ProjectFeature::DISABLED) }
it 'shows links to MRs and issues' do
expect(page).to have_link('view merge requests')
expect(page).to have_link('view open issues')
page.within('.labels-container') do
expect(page).to have_link('Merge requests')
expect(page).to have_link('Issues')
end
end
end
end

View file

@ -1,19 +0,0 @@
# frozen_string_literal: true
require 'rails_helper'
describe 'New user snippet breadcrumbs' do
let(:user) { create(:user) }
before do
sign_in(user)
visit new_snippet_path
end
it 'display a link to user snippets and new user snippet pages' do
page.within '.breadcrumbs' do
expect(find_link('Snippets')[:href]).to end_with(dashboard_snippets_path)
expect(find_link('New')[:href]).to end_with(new_snippet_path)
end
end
end

View file

@ -0,0 +1,67 @@
# frozen_string_literal: true
require 'fast_spec_helper'
require 'rubocop'
require 'rubocop/rspec/support'
require_relative '../../../../rubocop/cop/rspec/top_level_describe_path'
describe RuboCop::Cop::RSpec::TopLevelDescribePath do
include RuboCop::RSpec::ExpectOffense
include CopHelper
subject(:cop) { described_class.new }
context 'when the file ends in _spec.rb' do
it 'registers no offenses' do
expect_no_offenses(<<~SOURCE.strip_indent, 'spec/foo_spec.rb')
describe 'Foo' do
end
SOURCE
end
end
context 'when the file is a frontend fixture' do
it 'registers no offenses' do
expect_no_offenses(<<~SOURCE.strip_indent, 'spec/frontend/fixtures/foo.rb')
describe 'Foo' do
end
SOURCE
end
end
context 'when the describe is in a shared example' do
context 'with shared_examples' do
it 'registers no offenses' do
expect_no_offenses(<<~SOURCE.strip_indent, 'spec/foo.rb')
shared_examples 'Foo' do
describe '#bar' do
end
end
SOURCE
end
end
context 'with shared_examples_for' do
it 'registers no offenses' do
expect_no_offenses(<<~SOURCE.strip_indent, 'spec/foo.rb')
shared_examples_for 'Foo' do
describe '#bar' do
end
end
SOURCE
end
end
end
context 'when the describe is at the top level' do
it 'marks the describe as offending' do
expect_offense(<<~SOURCE.strip_indent, 'spec/foo.rb')
describe 'Foo' do
^^^^^^^^^^^^^^ #{described_class::MESSAGE}
end
SOURCE
end
end
end

View file

@ -1,27 +0,0 @@
require 'spec_helper'
require 'rake'
describe 'gitlab:mail_google_schema_whitelisting rake task' do
before :all do
Rake.application.rake_require "tasks/gitlab/helpers"
Rake.application.rake_require "tasks/gitlab/mail_google_schema_whitelisting"
# empty task as env is already loaded
Rake::Task.define_task :environment
end
describe 'call' do
before do
# avoid writing task output to spec progress
allow($stdout).to receive :write
end
let :run_rake_task do
Rake::Task["gitlab:mail_google_schema_whitelisting"].reenable
Rake.application.invoke_task "gitlab:mail_google_schema_whitelisting"
end
it 'runs the task without errors' do
expect { run_rake_task }.not_to raise_error
end
end
end

View file

@ -4,7 +4,7 @@ describe 'dashboard/projects/_nav.html.haml' do
it 'highlights All tab by default' do
render
expect(rendered).to have_css('li.active a', text: 'All')
expect(rendered).to have_css('a.active', text: 'All')
end
it 'highlights Personal tab personal param is present' do
@ -12,6 +12,6 @@ describe 'dashboard/projects/_nav.html.haml' do
render
expect(rendered).to have_css('li.active a', text: 'Personal')
expect(rendered).to have_css('a.active', text: 'Personal')
end
end

View file

@ -7,9 +7,20 @@ describe 'shared/_label_row.html.haml' do
}
label_types.each do |label_type, label_factory|
let!(:label) { create(label_factory) }
let!(:label) do
label_record = create(label_factory)
label_record.present(issuable_subject: label_record.subject)
end
context "for a #{label_type}" do
before do
if label.project_label?
@project = label.project
else
@group = label.group
end
end
it 'has a non-linked label title' do
render 'shared/label_row', label: label

View file

@ -6,7 +6,7 @@ describe 'shared/milestones/_issuables.html.haml' do
before do
allow(view).to receive_messages(title: nil, id: nil, show_project_name: nil,
show_full_project_name: nil, dom_class: '',
issuables: double(size: issuables_size).as_null_object)
issuables: double(length: issuables_size).as_null_object)
stub_template 'shared/milestones/_issuable.html.haml' => ''
end

View file

@ -7,6 +7,7 @@ describe 'shared/milestones/_top.html.haml' do
before do
allow(milestone).to receive(:milestones) { [] }
allow(milestone).to receive(:milestone) { milestone }
end
it 'renders a deprecation message for a legacy milestone' do