Sha256: b4463f21df7a4f16ecc03b2198ca3c2b6b6715856e3e4a90c93296d6a9e5cba1

Contents?: true

Size: 1.41 KB

Versions: 17

Compression:

Stored size: 1.41 KB

Contents

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

  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

17 entries across 17 versions & 1 rubygems

Version Path
rubocop-rspec-1.27.0 spec/rubocop/cop/rspec/before_after_all_spec.rb
rubocop-rspec-1.26.0 spec/rubocop/cop/rspec/before_after_all_spec.rb
rubocop-rspec-1.25.1 spec/rubocop/cop/rspec/before_after_all_spec.rb
rubocop-rspec-1.25.0 spec/rubocop/cop/rspec/before_after_all_spec.rb
rubocop-rspec-1.24.0 spec/rubocop/cop/rspec/before_after_all_spec.rb
rubocop-rspec-1.23.0 spec/rubocop/cop/rspec/before_after_all_spec.rb
rubocop-rspec-1.22.2 spec/rubocop/cop/rspec/before_after_all_spec.rb
rubocop-rspec-1.22.1 spec/rubocop/cop/rspec/before_after_all_spec.rb
rubocop-rspec-1.22.0 spec/rubocop/cop/rspec/before_after_all_spec.rb
rubocop-rspec-1.21.0 spec/rubocop/cop/rspec/before_after_all_spec.rb
rubocop-rspec-1.20.1 spec/rubocop/cop/rspec/before_after_all_spec.rb
rubocop-rspec-1.20.0 spec/rubocop/cop/rspec/before_after_all_spec.rb
rubocop-rspec-1.19.0 spec/rubocop/cop/rspec/before_after_all_spec.rb
rubocop-rspec-1.18.0 spec/rubocop/cop/rspec/before_after_all_spec.rb
rubocop-rspec-1.17.1 spec/rubocop/cop/rspec/before_after_all_spec.rb
rubocop-rspec-1.17.0 spec/rubocop/cop/rspec/before_after_all_spec.rb
rubocop-rspec-1.16.0 spec/rubocop/cop/rspec/before_after_all_spec.rb