test/pelusa/lint/demeter_law_test.rb in pelusa-0.2.3 vs test/pelusa/lint/demeter_law_test.rb in pelusa-0.2.4

- old
+ new

@@ -8,99 +8,99 @@ end describe '#check' do describe 'when the class respects Demeter law' do it 'returns a SuccessAnalysis' do - klass = """ + klass = Pelusa.to_ast """ class Foo def initialize foo = 'hey'.upcase foo.downcase end - end""".to_ast + end""" analysis = @lint.check(klass) analysis.successful?.must_equal true end end describe 'when the class does not respect Demeter law' do it 'returns a FailureAnalysis' do - klass = """ + klass = Pelusa.to_ast """ class Foo def initialize foo = 'hey'.upcase.downcase end - end""".to_ast + end""" analysis = @lint.check(klass) analysis.failed?.must_equal true end end describe 'when instantiating a class' do it 'returns a SuccessAnalysis' do - klass = """ + klass = Pelusa.to_ast """ class Foo def execute Bar.new.execute end - end""".to_ast + end""" analysis = @lint.check(klass) analysis.successful?.must_equal true end end describe 'when chaining whitelisted operations' do it 'returns a SuccessAnalysis for chained operations from Enumerable' do - klass = """ + klass = Pelusa.to_ast """ class Foo def execute [1,2,3].map(&:object_id).each {|i| i} end - end""".to_ast + end""" analysis = @lint.check(klass) analysis.successful?.must_equal true end it 'returns a SuccessAnalysis when chaining methods from Fixnum' do - klass = """ + klass = Pelusa.to_ast """ class Foo def execute 1 + 2 + 3 + 4 end - end""".to_ast + end""" analysis = @lint.check(klass) analysis.successful?.must_equal true end it 'returns a SuccessAnalysis for chained operations from Object' do - klass = """ + klass = Pelusa.to_ast """ class Foo def execute Object.new.to_s.inspect end - end""".to_ast + end""" analysis = @lint.check(klass) analysis.successful?.must_equal true end it 'returns a SuccessAnalysis for chained operations from optional sources' do Pelusa.configuration.stubs(:[]).with("DemeterLaw").returns( {"whitelist" => "Object, Kernel, Hash, Enumerable"} ) - klass = """ + klass = Pelusa.to_ast """ class Foo def execute {'a' => 2}.merge.each_pair {|k, v|} end - end""".to_ast + end""" analysis = @lint.check(klass) analysis.successful?.must_equal true end end @@ -109,27 +109,27 @@ it 'returns a SuccessAnalysis for conversion operations if allowed' do Pelusa.configuration.stubs(:[]).with("DemeterLaw").returns( {"allow_conversions" => true} ) - klass = """ + klass = Pelusa.to_ast """ class Foo def execute {'a' => 2}.merge({}).to_hash.as_json end - end""".to_ast + end""" analysis = @lint.check(klass) analysis.successful?.must_equal true end it 'returns a FailureAnalysis for conversions if not allowed' do - klass = """ + klass = Pelusa.to_ast """ class Foo def execute {'a' => 2}.merge({}).to_hash end - end""".to_ast + end""" analysis = @lint.check(klass) analysis.successful?.must_equal false end end