debian-mirror-gitlab/spec/rubocop/cop/project_path_helper_spec.rb

44 lines
1.2 KiB
Ruby
Raw Normal View History

2019-12-26 22:10:19 +05:30
# frozen_string_literal: true
2020-07-28 23:09:34 +05:30
require 'fast_spec_helper'
2017-09-10 17:25:29 +05:30
require 'rubocop'
require 'rubocop/rspec/support'
require_relative '../../../rubocop/cop/project_path_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe RuboCop::Cop::ProjectPathHelper, type: :rubocop do
2017-09-10 17:25:29 +05:30
include CopHelper
subject(:cop) { described_class.new }
context "when using namespace_project with the project's namespace" do
let(:source) { 'edit_namespace_project_issue_path(@issue.project.namespace, @issue.project, @issue)' }
let(:correct_source) { 'edit_project_issue_path(@issue.project, @issue)' }
it 'registers an offense' do
2018-03-17 18:26:18 +05:30
inspect_source(source)
2017-09-10 17:25:29 +05:30
aggregate_failures do
expect(cop.offenses.size).to eq(1)
expect(cop.offenses.map(&:line)).to eq([1])
expect(cop.highlights).to eq(['edit_namespace_project_issue_path'])
end
end
it 'autocorrects to the right version' do
2018-03-17 18:26:18 +05:30
autocorrected = autocorrect_source(source)
2017-09-10 17:25:29 +05:30
expect(autocorrected).to eq(correct_source)
end
end
context 'when using namespace_project with a different namespace' do
it 'registers no offense' do
2018-03-17 18:26:18 +05:30
inspect_source('edit_namespace_project_issue_path(namespace, project)')
2017-09-10 17:25:29 +05:30
expect(cop.offenses.size).to eq(0)
end
end
end