Sha256: 8ff68abfb1d3c3b03ce9c05a3635fae0858551876e543ea6ac050013a7e2da87

Contents?: true

Size: 1.41 KB

Versions: 4

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_violation(<<-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_violation(<<-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_violations(<<-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_violations(<<-RUBY)
        after(:each) { do_something }
        after(:example) { do_something }
      RUBY
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rubocop-rspec-1.15.1 spec/rubocop/cop/rspec/before_after_all_spec.rb
rubocop-rspec-1.15.0 spec/rubocop/cop/rspec/before_after_all_spec.rb
rubocop-rspec-1.14.0 spec/rubocop/cop/rspec/before_after_all_spec.rb
rubocop-rspec-1.13.0 spec/rubocop/cop/rspec/before_after_all_spec.rb