Sha256: a25fdeb7821297c9f0a6383f8651a365d3e783b71711e118a4aaac92e8d6a395

Contents?: true

Size: 1.71 KB

Versions: 20

Compression:

Stored size: 1.71 KB

Contents

RSpec.describe RuboCop::Cop::RSpec::VerifiedDoubles, :config do
  subject(:cop) { described_class.new(config) }

  it 'finds a `double` instead of an `instance_double`' do
    expect_offense(<<-RUBY)
      it do
        foo = double("Widget")
              ^^^^^^^^^^^^^^^^ Prefer using verifying doubles over normal doubles.
      end
    RUBY
  end

  context 'when configuration does not specify IgnoreSymbolicNames' do
    let(:cop_config) { {} }

    it 'find doubles whose name is a symbol' do
      expect_offense(<<-RUBY)
        it do
          foo = double(:widget)
                ^^^^^^^^^^^^^^^ Prefer using verifying doubles over normal doubles.
        end
      RUBY
    end

    it 'finds a `spy` instead of an `instance_spy`' do
      expect_offense(<<-RUBY)
        it do
          foo = spy("Widget")
                ^^^^^^^^^^^^^ Prefer using verifying doubles over normal doubles.
        end
      RUBY
    end
  end

  context 'when configured to ignore symbolic names' do
    let(:cop_config) { { 'IgnoreSymbolicNames' => true } }

    it 'ignores doubles whose name is a symbol' do
      expect_no_offenses(<<-RUBY)
        it do
          foo = double(:widget)
        end
      RUBY
    end

    it 'still flags doubles whose name is a string' do
      expect_offense(<<-RUBY)
        it do
          foo = double("widget")
                ^^^^^^^^^^^^^^^^ Prefer using verifying doubles over normal doubles.
        end
      RUBY
    end
  end

  it 'ignores doubles without a name' do
    expect_no_offenses(<<-RUBY)
      it do
        foo = double
      end
    RUBY
  end

  it 'ignores instance_doubles' do
    expect_no_offenses(<<-RUBY)
      it do
        foo = instance_double("Foo")
      end
    RUBY
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
rubocop-rspec-1.29.1 spec/rubocop/cop/rspec/verified_doubles_spec.rb
rubocop-rspec-1.29.0 spec/rubocop/cop/rspec/verified_doubles_spec.rb
rubocop-rspec-1.28.0 spec/rubocop/cop/rspec/verified_doubles_spec.rb
rubocop-rspec-1.27.0 spec/rubocop/cop/rspec/verified_doubles_spec.rb
rubocop-rspec-1.26.0 spec/rubocop/cop/rspec/verified_doubles_spec.rb
rubocop-rspec-1.25.1 spec/rubocop/cop/rspec/verified_doubles_spec.rb
rubocop-rspec-1.25.0 spec/rubocop/cop/rspec/verified_doubles_spec.rb
rubocop-rspec-1.24.0 spec/rubocop/cop/rspec/verified_doubles_spec.rb
rubocop-rspec-1.23.0 spec/rubocop/cop/rspec/verified_doubles_spec.rb
rubocop-rspec-1.22.2 spec/rubocop/cop/rspec/verified_doubles_spec.rb
rubocop-rspec-1.22.1 spec/rubocop/cop/rspec/verified_doubles_spec.rb
rubocop-rspec-1.22.0 spec/rubocop/cop/rspec/verified_doubles_spec.rb
rubocop-rspec-1.21.0 spec/rubocop/cop/rspec/verified_doubles_spec.rb
rubocop-rspec-1.20.1 spec/rubocop/cop/rspec/verified_doubles_spec.rb
rubocop-rspec-1.20.0 spec/rubocop/cop/rspec/verified_doubles_spec.rb
rubocop-rspec-1.19.0 spec/rubocop/cop/rspec/verified_doubles_spec.rb
rubocop-rspec-1.18.0 spec/rubocop/cop/rspec/verified_doubles_spec.rb
rubocop-rspec-1.17.1 spec/rubocop/cop/rspec/verified_doubles_spec.rb
rubocop-rspec-1.17.0 spec/rubocop/cop/rspec/verified_doubles_spec.rb
rubocop-rspec-1.16.0 spec/rubocop/cop/rspec/verified_doubles_spec.rb