Sha256: d30b69947faf9b92dfa464dc8d1d9254d2f211a4169c0b62a6c2d68236415d2a

Contents?: true

Size: 1.27 KB

Versions: 4

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true

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

  it 'registers offenses to void `expect`' do
    expect_offense(<<-RUBY)
      it 'something' do
        something = 1
        expect(something)
        ^^^^^^^^^^^^^^^^^ Do not use `expect()` without `.to` or `.not_to`. Chain the methods or remove it.
      end
    RUBY
  end

  it 'registers offenses to void `expect` when block has one expression' do
    expect_offense(<<-RUBY)
      it 'something' do
        expect(something)
        ^^^^^^^^^^^^^^^^^ Do not use `expect()` without `.to` or `.not_to`. Chain the methods or remove it.
      end
    RUBY
  end

  it 'registers offenses to void `expect` with block' do
    expect_offense(<<-RUBY)
      it 'something' do
        expect{something}
        ^^^^^^^^^^^^^^^^^ Do not use `expect()` without `.to` or `.not_to`. Chain the methods or remove it.
      end
    RUBY
  end

  it 'accepts non-void `expect`' do
    expect_no_offenses(<<-RUBY)
      it 'something' do
        expect(something).to be 1
      end
    RUBY
  end

  it 'accepts non-void `expect` with block' do
    expect_no_offenses(<<-RUBY)
      it 'something' do
        expect{something}.to raise_error(StandardError)
      end
    RUBY
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rubocop-rspec-1.35.0 spec/rubocop/cop/rspec/void_expect_spec.rb
rubocop-rspec-1.34.1 spec/rubocop/cop/rspec/void_expect_spec.rb
rubocop-rspec-1.34.0 spec/rubocop/cop/rspec/void_expect_spec.rb
rubocop-rspec-1.33.0 spec/rubocop/cop/rspec/void_expect_spec.rb