require File.dirname(__FILE__) + '/../../spec_helper.rb' require 'ostruct' require 'reek/core_extras' require 'reek/method_context' require 'reek/smells/uncommunicative_name' include Reek include Reek::Smells describe UncommunicativeName, "method name" do it 'should not report one-word method name' do 'def help(fred) basics(17) end'.should_not reek end it 'should report one-letter method name' do 'def x(fred) basics(17) end'.should reek_only_of(:UncommunicativeName, /x/) end it 'should report name of the form "x2"' do 'def x2(fred) basics(17) end'.should reek_only_of(:UncommunicativeName, /x2/) end end describe UncommunicativeName, "field name" do it 'should not report one-word field name' do 'class Thing; def help(fred) @simple end end'.should_not reek end it 'should report one-letter fieldname' do 'class Thing; def simple(fred) @x end end'.should reek_only_of(:UncommunicativeName, /@x/, /Thing/, /variable name/) end it 'should report name of the form "x2"' do 'class Thing; def simple(fred) @x2 end end'.should reek_only_of(:UncommunicativeName, /@x2/, /Thing/, /variable name/) end it 'should report one-letter fieldname in assignment' do 'class Thing; def simple(fred) @x = fred end end'.should reek_only_of(:UncommunicativeName, /@x/, /Thing/, /variable name/) end end describe UncommunicativeName, "local variable name" do it 'should not report one-word variable name' do 'def help(fred) simple = jim(45) end'.should_not reek end it 'should report one-letter variable name' do 'def simple(fred) x = jim(45) end'.should reek_only_of(:UncommunicativeName, /x/, /variable name/) end it 'should report name of the form "x2"' do 'def simple(fred) x2 = jim(45) end'.should reek_only_of(:UncommunicativeName, /x2/, /variable name/) end it 'should report variable name only once' do 'def simple(fred) x = jim(45); x = y end'.should reek_only_of(:UncommunicativeName, /x/) end it 'should report a bad name inside a block' do src = 'def clean(text) text.each { q2 = 3 } end' src.should reek_of(:UncommunicativeName, /q2/) end end describe UncommunicativeName, "parameter name" do it 'should not recognise *' do 'def help(xray, *) basics(17) end'.should_not reek end it "should report parameter's name" do 'def help(x) basics(17) end'.should reek_only_of(:UncommunicativeName, /x/, /variable name/) end it 'should report name of the form "x2"' do 'def help(x2) basics(17) end'.should reek_only_of(:UncommunicativeName, /x2/, /variable name/) end end describe UncommunicativeName, "block parameter name" do it "should report parameter's name" do 'def help() @stuff.each {|x|} end'.should reek_only_of(:UncommunicativeName, /x/, /block/, /variable name/) end it "should report method name via if context" do src = <