Sha256: 9a98b0ceaf2abd6cf279e81d3f0d8e638844a17840760dd535a13cfc6d0a627f
Contents?: true
Size: 1.94 KB
Versions: 2
Compression:
Stored size: 1.94 KB
Contents
require File.join(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__)))), 'spec_helper') require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'smells', 'control_couple') require File.join(File.dirname(File.expand_path(__FILE__)), 'smell_detector_shared') include Reek::Smells describe ControlCouple do before(:each) do @source_name = 'lets get married' @detector = ControlCouple.new(@source_name) end it_should_behave_like 'SmellDetector' context 'conditional on a parameter' do it 'should report a ternary check on a parameter' do src = 'def simple(arga) arga ? @ivar : 3 end' src.should smell_of(ControlCouple, ControlCouple::PARAMETER_KEY => 'arga') end it 'should not report a ternary check on an ivar' do src = 'def simple(arga) @ivar ? arga : 3 end' src.should_not smell_of(ControlCouple) end it 'should not report a ternary check on a lvar' do src = 'def simple(arga) lvar = 27; lvar ? arga : @ivar end' src.should_not smell_of(ControlCouple) end it 'should spot a couple inside a block' do src = 'def blocks(arg) @text.map { |blk| arg ? blk : "#{blk}" } end' src.should smell_of(ControlCouple, ControlCouple::PARAMETER_KEY => 'arg') end end context 'when a smell is reported' do before :each do src = <<EOS def things(arg) @text.map do |blk| arg ? blk : "blk" end puts "hello" if arg end EOS ctx = MethodContext.new(nil, src.to_reek_source.syntax_tree) smells = @detector.examine(ctx) smells.length.should == 1 @warning = smells[0] end it_should_behave_like 'common fields set correctly' it 'has the correct fields' do @warning.smell[ControlCouple::PARAMETER_KEY].should == 'arg' if RUBY_VERSION < "1.9.3" @warning.lines.should == [3,6] else @warning.lines.should == [3,5] end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
reek-1.2.13 | spec/reek/smells/control_couple_spec.rb |
reek-1.2.12 | spec/reek/smells/control_couple_spec.rb |