Sha256: 8d1d29382b6bb13167d4827a863908b5fbe6df40fcf7def93ddcd9cb75db210b

Contents?: true

Size: 1.69 KB

Versions: 6

Compression:

Stored size: 1.69 KB

Contents

# encoding: utf-8

require 'spec_helper'

describe Rubocop::Cop::Style::MethodCalledOnDoEndBlock do
  subject(:cop) { described_class.new }

  context 'with a multi-line do..end block' do
    it 'registers an offense for a chained call' do
      inspect_source(cop, ['a do',
                           '  b',
                           'end.c'])
      expect(cop.offenses.size).to eq(1)
      expect(cop.highlights).to eq(['end.c'])
    end

    it 'accepts it if there is no chained call' do
      inspect_source(cop, ['a do',
                           '  b',
                           'end'])
      expect(cop.offenses).to be_empty
    end

    it 'accepts a chained block' do
      inspect_source(cop, ['a do',
                           '  b',
                           'end.c do',
                           '  d',
                           'end'])
      expect(cop.offenses).to be_empty
    end
  end

  context 'with a single-line do..end block' do
    it 'registers an offense for a chained call' do
      inspect_source(cop, ['a do b end.c'])
      expect(cop.offenses.size).to eq(1)
      expect(cop.highlights).to eq(['end.c'])
    end

    it 'accepts a single-line do..end block with a chained block' do
      inspect_source(cop, ['a do b end.c do d end'])
      expect(cop.offenses).to be_empty
    end
  end

  context 'with a {} block' do
    it 'accepts a multi-line block with a chained call' do
      inspect_source(cop, ['a {',
                           '  b',
                           '}.c'])
      expect(cop.offenses).to be_empty
    end

    it 'accepts a single-line block with a chained call' do
      inspect_source(cop, ['a { b }.c'])
      expect(cop.offenses).to be_empty
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rubocop-0.22.0 spec/rubocop/cop/style/method_called_on_do_end_block_spec.rb
rubocop-0.21.0 spec/rubocop/cop/style/method_called_on_do_end_block_spec.rb
rubocop-0.20.1 spec/rubocop/cop/style/method_called_on_do_end_block_spec.rb
rubocop-0.20.0 spec/rubocop/cop/style/method_called_on_do_end_block_spec.rb
rubocop-0.19.1 spec/rubocop/cop/style/method_called_on_do_end_block_spec.rb
rubocop-0.19.0 spec/rubocop/cop/style/method_called_on_do_end_block_spec.rb