Sha256: cab9d5cae4a3f7dbeddbc11ed8cc2f159cb338f7c594ba2860f2a1f77d1e80c2

Contents?: true

Size: 1.24 KB

Versions: 24

Compression:

Stored size: 1.24 KB

Contents

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

24 entries across 24 versions & 1 rubygems

Version Path
rubocop-rspec-1.18.0 spec/rubocop/cop/rspec/void_expect_spec.rb
rubocop-rspec-1.17.1 spec/rubocop/cop/rspec/void_expect_spec.rb
rubocop-rspec-1.17.0 spec/rubocop/cop/rspec/void_expect_spec.rb
rubocop-rspec-1.16.0 spec/rubocop/cop/rspec/void_expect_spec.rb