Sha256: d35dcf7bb20e063adada3f9a325da4ad4b5545329ab4df326c7cb8f64032cc6a

Contents?: true

Size: 1.72 KB

Versions: 9

Compression:

Stored size: 1.72 KB

Contents

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

  it 'finds a `double` instead of an `instance_double`' do
    expect_violation(<<-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) { Hash.new }

    it 'find doubles whose name is a symbol' do
      expect_violation(<<-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_violation(<<-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_violations(<<-RUBY)
        it do
          foo = double(:widget)
        end
      RUBY
    end

    it 'still flags doubles whose name is a string' do
      expect_violation(<<-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_violations(<<-RUBY)
      it do
        foo = double
      end
    RUBY
  end

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

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rubocop-rspec-1.12.0 spec/rubocop/cop/rspec/verified_doubles_spec.rb
rubocop-rspec-1.11.0 spec/rubocop/cop/rspec/verified_doubles_spec.rb
rubocop-rspec-1.10.0 spec/rubocop/cop/rspec/verified_doubles_spec.rb
rubocop-rspec-1.9.1 spec/rubocop/cop/rspec/verified_doubles_spec.rb
rubocop-rspec-1.9.0 spec/rubocop/cop/rspec/verified_doubles_spec.rb
rubocop-rspec-1.8.0 spec/rubocop/cop/rspec/verified_doubles_spec.rb
rubocop-rspec-1.7.0 spec/rubocop/cop/rspec/verified_doubles_spec.rb
rubocop-rspec-1.6.0 spec/rubocop/cop/rspec/verified_doubles_spec.rb
rubocop-rspec-1.5.3 spec/rubocop/cop/rspec/verified_doubles_spec.rb