Sha256: 77b922541da6fab8325ae809b8bf8ce0effd7b1bf675ec203b8058525c72db4e

Contents?: true

Size: 1.69 KB

Versions: 4

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 offence for a chained call' do
      inspect_source(cop, ['a do',
                           '  b',
                           'end.c'])
      expect(cop.offences).to have(1).item
      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.offences).to be_empty
    end

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

  context 'with a single-line do..end block' do
    it 'registers an offence for a chained call' do
      inspect_source(cop, ['a do b end.c'])
      expect(cop.offences).to have(1).item
      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.offences).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.offences).to be_empty
    end

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rubocop-0.16.0 spec/rubocop/cop/style/method_called_on_do_end_block_spec.rb
rubocop-0.15.0 spec/rubocop/cop/style/method_called_on_do_end_block_spec.rb
rubocop-0.14.1 spec/rubocop/cop/style/method_called_on_do_end_block_spec.rb
rubocop-0.14.0 spec/rubocop/cop/style/method_called_on_do_end_block_spec.rb