Sha256: 3b78ed390bb08b2b2da9b79dab043c222a4e57cc3cab2ff26f2e9e8cea8668c8

Contents?: true

Size: 1.67 KB

Versions: 35

Compression:

Stored size: 1.67 KB

Contents

# frozen_string_literal: true

RSpec.describe RuboCop::RSpec::Hook do
  include RuboCop::AST::Sexp

  def hook(source)
    described_class.new(parse_source(source).ast)
  end

  it 'extracts name' do
    expect(hook('around(:each) { }').name).to be(:around)
  end

  it 'does not break if a hook is not given a symbol literal' do
    expect(hook('before(scope) { example_setup }').knowable_scope?).to be(false)
  end

  it 'knows the scope of a hook with a symbol literal' do
    expect(hook('before { example_setup }').knowable_scope?).to be(true)
  end

  it 'ignores other arguments to hooks' do
    expect(hook('before(:each, :metadata) { example_setup }').scope)
      .to be(:each)
  end

  it 'classifies nonstandard hook arguments as invalid' do
    expect(hook('before(:nothing) { example_setup }').valid_scope?).to be(false)
  end

  it 'classifies :each as a valid hook argument' do
    expect(hook('before(:each) { example_setup }').valid_scope?).to be(true)
  end

  it 'classifies :each as an example hook' do
    expect(hook('before(:each) { }').example?).to be(true)
  end

  shared_examples 'standardizes scope' do |source, scope|
    it "interprets #{source} as having scope #{scope}" do
      expect(hook(source).scope).to equal(scope)
    end
  end

  include_examples 'standardizes scope', 'before(:each) { }',    :each
  include_examples 'standardizes scope', 'around(:example) { }', :each
  include_examples 'standardizes scope', 'after { }',            :each

  include_examples 'standardizes scope', 'before(:all) { }',     :context
  include_examples 'standardizes scope', 'around(:context) { }', :context

  include_examples 'standardizes scope', 'after(:suite) { }', :suite
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
rubocop-rspec-1.35.0 spec/rubocop/rspec/hook_spec.rb
rubocop-rspec-1.34.1 spec/rubocop/rspec/hook_spec.rb
rubocop-rspec-1.34.0 spec/rubocop/rspec/hook_spec.rb
rubocop-rspec-1.33.0 spec/rubocop/rspec/hook_spec.rb
rubocop-rspec-1.32.0 spec/rubocop/rspec/hook_spec.rb
rubocop-rspec-1.31.0 spec/rubocop/rspec/hook_spec.rb
rubocop-rspec-1.30.1 spec/rubocop/rspec/hook_spec.rb
rubocop-rspec-1.30.0 spec/rubocop/rspec/hook_spec.rb
rubocop-rspec-1.29.1 spec/rubocop/rspec/hook_spec.rb
rubocop-rspec-1.29.0 spec/rubocop/rspec/hook_spec.rb
rubocop-rspec-1.28.0 spec/rubocop/rspec/hook_spec.rb
rubocop-rspec-1.27.0 spec/rubocop/rspec/hook_spec.rb
rubocop-rspec-1.26.0 spec/rubocop/rspec/hook_spec.rb
rubocop-rspec-1.25.1 spec/rubocop/rspec/hook_spec.rb
rubocop-rspec-1.25.0 spec/rubocop/rspec/hook_spec.rb
rubocop-rspec-1.24.0 spec/rubocop/rspec/hook_spec.rb
rubocop-rspec-1.23.0 spec/rubocop/rspec/hook_spec.rb
rubocop-rspec-1.22.2 spec/rubocop/rspec/hook_spec.rb
rubocop-rspec-1.22.1 spec/rubocop/rspec/hook_spec.rb
rubocop-rspec-1.22.0 spec/rubocop/rspec/hook_spec.rb