From 02c47f2f73ac2d5a33b9a6c971668a38397b4910 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Thu, 11 Oct 2018 19:10:42 +0200 Subject: Add a new QA::ElementWithPattern cop MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This cop forbids the use of `element :foo, 'pattern'` and `element :bar, /pattern/` in QA files. Signed-off-by: Rémy Coutable --- spec/rubocop/qa_helpers_spec.rb | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 spec/rubocop/qa_helpers_spec.rb (limited to 'spec/rubocop/qa_helpers_spec.rb') diff --git a/spec/rubocop/qa_helpers_spec.rb b/spec/rubocop/qa_helpers_spec.rb new file mode 100644 index 00000000000..26e4c1ca6f0 --- /dev/null +++ b/spec/rubocop/qa_helpers_spec.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +require 'spec_helper' +require 'rubocop' +require_relative '../../rubocop/qa_helpers' + +describe RuboCop::QAHelpers do + def parse_source(source, path = 'foo.rb') + 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 + node = parse_source('10', Rails.root.join('qa', 'qa', 'page', 'dashboard', 'groups.rb')) + + expect(cop.in_qa_file?(node)).to eq(true) + end + + it 'returns false for a node outside the qa/ directory' do + node = parse_source('10', Rails.root.join('app', 'foo', 'foo.rb')) + + expect(cop.in_qa_file?(node)).to eq(false) + end + end +end -- cgit v1.2.3