diff options
Diffstat (limited to 'spec/rubocop/cop/rspec/before_all_spec.rb')
-rw-r--r-- | spec/rubocop/cop/rspec/before_all_spec.rb | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/spec/rubocop/cop/rspec/before_all_spec.rb b/spec/rubocop/cop/rspec/before_all_spec.rb new file mode 100644 index 00000000000..5cf22bc4093 --- /dev/null +++ b/spec/rubocop/cop/rspec/before_all_spec.rb @@ -0,0 +1,74 @@ +# frozen_string_literal: true + +require 'rubocop_spec_helper' + +require_relative '../../../../rubocop/cop/rspec/before_all' + +RSpec.describe Rubocop::Cop::RSpec::BeforeAll, feature_category: :tooling do + context 'when using before(:all)' do + let(:source) do + <<~SRC + before(:all) do + ^^^^^^^^^^^^ Prefer using `before_all` over `before(:all)`. [...] + create_table_structure + end + SRC + end + + let(:corrected_source) do + <<~SRC + before_all do + create_table_structure + end + SRC + end + + it 'registers an offense and corrects', :aggregate_failures do + expect_offense(source) + + expect_correction(corrected_source) + end + end + + context 'when using before_all' do + let(:source) do + <<~SRC + before_all do + create_table_structure + end + SRC + end + + it 'does not register an offense' do + expect_no_offenses(source) + end + end + + context 'when using before(:each)' do + let(:source) do + <<~SRC + before(:each) do + create_table_structure + end + SRC + end + + it 'does not register an offense' do + expect_no_offenses(source) + end + end + + context 'when using before' do + let(:source) do + <<~SRC + before do + create_table_structure + end + SRC + end + + it 'does not register an offense' do + expect_no_offenses(source) + end + end +end |