Sha256: ba6541053bd304e830c545938bacd6ec3042879f02e93ece31a05fb61dff344c

Contents?: true

Size: 1.39 KB

Versions: 7

Compression:

Stored size: 1.39 KB

Contents

RSpec.describe RuboCop::Cop::RSpec::BeforeAfterAll do
  subject(:cop) { described_class.new }

  def message(hook)
    "Beware of using `#{hook}` as it may cause state to leak between tests. "\
    'If you are using `rspec-rails`, and `use_transactional_fixtures` is '\
    "enabled, then records created in `#{hook}` are not automatically rolled "\
    'back.'
  end

  context 'when using before all' do
    it 'registers an offense' do
      expect_offense(<<-RUBY)
        before(:all) { do_something }
        ^^^^^^^^^^^^ #{message('before(:all)')}
        before(:context) { do_something }
        ^^^^^^^^^^^^^^^^ #{message('before(:context)')}
      RUBY
    end
  end

  context 'when using after all' do
    it 'registers an offense' do
      expect_offense(<<-RUBY)
        after(:all) { do_something }
        ^^^^^^^^^^^ #{message('after(:all)')}
        after(:context) { do_something }
        ^^^^^^^^^^^^^^^ #{message('after(:context)')}
      RUBY
    end
  end

  context 'when using before each' do
    it 'does not register an offense' do
      expect_no_offenses(<<-RUBY)
        before(:each) { do_something }
        before(:example) { do_something }
      RUBY
    end
  end

  context 'when using after each' do
    it 'does not register an offense' do
      expect_no_offenses(<<-RUBY)
        after(:each) { do_something }
        after(:example) { do_something }
      RUBY
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rubocop-rspec-1.32.0 spec/rubocop/cop/rspec/before_after_all_spec.rb
rubocop-rspec-1.31.0 spec/rubocop/cop/rspec/before_after_all_spec.rb
rubocop-rspec-1.30.1 spec/rubocop/cop/rspec/before_after_all_spec.rb
rubocop-rspec-1.30.0 spec/rubocop/cop/rspec/before_after_all_spec.rb
rubocop-rspec-1.29.1 spec/rubocop/cop/rspec/before_after_all_spec.rb
rubocop-rspec-1.29.0 spec/rubocop/cop/rspec/before_after_all_spec.rb
rubocop-rspec-1.28.0 spec/rubocop/cop/rspec/before_after_all_spec.rb