debian-mirror-gitlab/spec/rubocop/qa_helpers_spec.rb

39 lines
977 B
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# frozen_string_literal: true
2020-07-28 23:09:34 +05:30
require 'fast_spec_helper'
2018-12-13 13:39:08 +05:30
require 'rubocop'
2020-07-28 23:09:34 +05:30
require 'parser/current'
2018-12-13 13:39:08 +05:30
require_relative '../../rubocop/qa_helpers'
2021-03-08 18:12:59 +05:30
RSpec.describe RuboCop::QAHelpers do
2021-03-11 19:13:27 +05:30
def build_and_parse_source(source, path = 'foo.rb')
2018-12-13 13:39:08 +05:30
buffer = Parser::Source::Buffer.new(path)
buffer.source = source
builder = RuboCop::AST::Builder.new
parser = Parser::CurrentRuby.new(builder)
parser.parse(buffer)
end
let(:cop) do
Class.new do
include RuboCop::QAHelpers
end.new
end
describe '#in_qa_file?' do
it 'returns true for a node in the qa/ directory' do
2021-03-11 19:13:27 +05:30
node = build_and_parse_source('10', rails_root_join('qa', 'qa', 'page', 'dashboard', 'groups.rb'))
2018-12-13 13:39:08 +05:30
expect(cop.in_qa_file?(node)).to eq(true)
end
it 'returns false for a node outside the qa/ directory' do
2021-03-11 19:13:27 +05:30
node = build_and_parse_source('10', rails_root_join('app', 'foo', 'foo.rb'))
2018-12-13 13:39:08 +05:30
expect(cop.in_qa_file?(node)).to eq(false)
end
end
end