spec/project/project_requires_spec.rb in rubocop-rspec-1.27.0 vs spec/project/project_requires_spec.rb in rubocop-rspec-1.28.0
- old
+ new
@@ -1,8 +1,18 @@
RSpec.describe 'Project requires' do
it 'alphabetizes cop requires' do
- source = SpecHelper::ROOT.join('lib', 'rubocop-rspec.rb').read
- requires = source.split("\n").grep(%r{rubocop/cop/rspec/[^(?:cop)]})
+ source = SpecHelper::ROOT.join('lib', 'rubocop', 'cop', 'rspec_cops.rb')
+ captures = source.read.scan(%r{^(require_relative 'rspec/(.*?/)?(.*?)')$})
- expect(requires.join("\n")).to eql(requires.sort.join("\n"))
+ require_statements = captures.map(&:first)
+ sorted_require_statements =
+ captures.sort_by do |_require_statement, cop_category, name|
+ [cop_category || 'rspec', name]
+ end.map(&:first)
+
+ aggregate_failures do
+ # Sanity check that we actually discovered require statements.
+ expect(captures).not_to be_empty
+ expect(require_statements).to eql(sorted_require_statements)
+ end
end
end