Sha256: 88dab67791e80ec41edb5de2af518f16ceac458744b5c9a5636e03df646a2c37

Contents?: true

Size: 893 Bytes

Versions: 4

Compression:

Stored size: 893 Bytes

Contents

# encoding: utf-8

require 'spec_helper'

describe Rubocop::Cop::Lint::AmbiguousRegexpLiteral do
  subject(:cop) { described_class.new }

  before do
    inspect_source(cop, source)
  end

  context 'with a regexp literal in the first argument' do
    context 'without parentheses' do
      let(:source) { 'p /pattern/' }

      it 'registers an offense' do
        expect(cop.offenses.size).to eq(1)
        expect(cop.offenses.first.message).to eq(
          'Ambiguous regexp literal. Parenthesize the method arguments ' \
          "if it's surely a regexp literal, or add a whitespace to the " \
          'right of the / if it should be a division.'
        )
        expect(cop.highlights).to eq(['/'])
      end
    end

    context 'with parentheses' do
      let(:source) { 'p(/pattern/)' }

      it 'accepts' do
        expect(cop.offenses).to be_empty
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rubocop-0.20.1 spec/rubocop/cop/lint/ambiguous_regexp_literal_spec.rb
rubocop-0.20.0 spec/rubocop/cop/lint/ambiguous_regexp_literal_spec.rb
rubocop-0.19.1 spec/rubocop/cop/lint/ambiguous_regexp_literal_spec.rb
rubocop-0.19.0 spec/rubocop/cop/lint/ambiguous_regexp_literal_spec.rb