Sha256: f322228f5610b93f71451104eced607c579b55588b29ceb3ddf316f6220deed7

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.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.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.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.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 & 2 rubygems

Version Path
ridecharge-rubocop-0.0.1 spec/rubocop/cop/style/method_called_on_do_end_block_spec.rb
rubocop-0.18.1 spec/rubocop/cop/style/method_called_on_do_end_block_spec.rb
rubocop-0.18.0 spec/rubocop/cop/style/method_called_on_do_end_block_spec.rb
rubocop-0.17.0 spec/rubocop/cop/style/method_called_on_do_end_block_spec.rb