Sha256: 854c94a24b12abdd1611b9062e88254a6fed8ead1425efc60e0b77222a7f4295

Contents?: true

Size: 1.91 KB

Versions: 3

Compression:

Stored size: 1.91 KB

Contents

# frozen_string_literal: true

RSpec.describe ExpectViolation::Expectation do
  subject(:expectation) { described_class.new(string) }

  context 'when given a single assertion on class end' do
    let(:string) do
      <<-SRC
        class Foo
        end
        ^^^ The end of `Foo` should be annotated.
      SRC
    end

    let(:assertion) { expectation.assertions.first }

    it 'has one assertion' do
      expect(expectation.assertions.size).to be(1)
    end

    it 'has an assertion on line 2' do
      expect(assertion.line_number).to be(2)
    end

    it 'has an assertion on column range 1-3' do
      expect(assertion.column_range).to eql(8...11)
    end

    it 'has an assertion with correct violation message' do
      expect(assertion.message).to eql('The end of `Foo` should be annotated.')
    end

    it 'recreates source' do
      expect(expectation.source).to eql(<<-RUBY)
        class Foo
        end
      RUBY
    end
  end

  context 'when given many assertions on two lines' do
    let(:string) do
      <<-SRC
        foo bar
            ^ Charlie
           ^^ Charlie
            ^^ Bronco
            ^^ Alpha
        baz
        ^ Delta
      SRC
    end

    let(:assertions) { expectation.assertions.sort }

    it 'has two assertions' do
      expect(expectation.assertions.size).to be(5)
    end

    it 'has assertions on lines 1 and 2' do
      expect(assertions.map(&:line_number)).to eql(
        [1, 1, 1, 1, 2]
      )
    end

    it 'has assertions on column range 1-3' do
      expect(assertions.map(&:column_range)).to eql(
        [11...13, 12...13, 12...14, 12...14, 8...9]
      )
    end

    it 'has an assertion with correct violation message' do
      expect(assertions.map(&:message)).to eql(
        %w(Charlie Charlie Alpha Bronco Delta)
      )
    end

    it 'recreates source' do
      expect(expectation.source).to eql(<<-RUBY)
        foo bar
        baz
      RUBY
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rubocop-rspec-1.15.0 spec/expect_violation/expectation_spec.rb
rubocop-rspec-1.14.0 spec/expect_violation/expectation_spec.rb
rubocop-rspec-1.13.0 spec/expect_violation/expectation_spec.rb