Sha256: 63c3b4162afb51c36924fd54fae75a0e4a9634f8c759e066aebf416085de5461
Contents?: true
Size: 1.93 KB
Versions: 2
Compression:
Stored size: 1.93 KB
Contents
# encoding: utf-8 require 'spec_helper' module Rubocop module Cop module Style describe SingleLineMethods, :config do subject(:slm) { SingleLineMethods.new(config) } let(:cop_config) { { 'AllowIfMethodIsEmpty' => true } } it 'registers an offence for a single-line method' do inspect_source(slm, ['def some_method; body end', 'def link_to(name, url); {:name => name}; end', 'def @table.columns; super; end']) expect(slm.messages).to eq( [SingleLineMethods::MSG] * 3) end context 'when AllowIfMethodIsEmpty is disabled' do let(:cop_config) { { 'AllowIfMethodIsEmpty' => false } } it 'registers an offence for an empty method' do inspect_source(slm, ['def no_op; end', 'def self.resource_class=(klass); end', 'def @table.columns; end']) expect(slm.offences.size).to eq(3) end end context 'when AllowIfMethodIsEmpty is enabled' do let(:cop_config) { { 'AllowIfMethodIsEmpty' => true } } it 'accepts a single-line empty method' do inspect_source(slm, ['def no_op; end', 'def self.resource_class=(klass); end', 'def @table.columns; end']) expect(slm.offences).to be_empty end end it 'accepts a multi-line method' do inspect_source(slm, ['def some_method', ' body', 'end']) expect(slm.offences).to be_empty end it 'does not crash on an method with a capitalized name' do inspect_source(slm, ['def NoSnakeCase', 'end']) expect(slm.offences).to be_empty end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rubocop-0.13.1 | spec/rubocop/cop/style/single_line_methods_spec.rb |
rubocop-0.13.0 | spec/rubocop/cop/style/single_line_methods_spec.rb |