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.21.0 spec/rubocop/rspec/hook_spec.rb
rubocop-rspec-1.20.1 spec/rubocop/rspec/hook_spec.rb
rubocop-rspec-1.20.0 spec/rubocop/rspec/hook_spec.rb
rubocop-rspec-1.19.0 spec/rubocop/rspec/hook_spec.rb
rubocop-rspec-1.18.0 spec/rubocop/rspec/hook_spec.rb
rubocop-rspec-1.17.1 spec/rubocop/rspec/hook_spec.rb
rubocop-rspec-1.17.0 spec/rubocop/rspec/hook_spec.rb
rubocop-rspec-1.16.0 spec/rubocop/rspec/hook_spec.rb
rubocop-rspec-1.15.1 spec/rubocop/rspec/hook_spec.rb
rubocop-rspec-1.15.0 spec/rubocop/rspec/hook_spec.rb
rubocop-rspec-1.14.0 spec/rubocop/rspec/hook_spec.rb
rubocop-rspec-1.13.0 spec/rubocop/rspec/hook_spec.rb
rubocop-rspec-1.12.0 spec/rubocop/rspec/hook_spec.rb
rubocop-rspec-1.11.0 spec/rubocop/rspec/hook_spec.rb
rubocop-rspec-1.10.0 spec/rubocop/rspec/hook_spec.rb