Sha256: d566ff118b1db972cd1fa0790f8334ffef13c695abe7dd6aadb512a14597a717

Contents?: true

Size: 1.93 KB

Versions: 2

Compression:

Stored size: 1.93 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')

describe Roodi::Checks::AbcMetricMethodCheck do

  before(:each) do
    @roodi = Roodi::Core::ParseTreeRunner.new(Roodi::Checks::AbcMetricMethodCheck.new({'score' => 0}))
  end

  describe '#evaluate' do

    describe 'when processing assignments' do

      ['=', '*=', '/=', '%=', '+=', '<<=', '>>=', '&=', '|=', '^='].each do |assignment|

        it "should find #{assignment}" do
          content = <<-END
            def method_name
              foo #{assignment} 1
            end
          END

          verify_content_score(content, 1, 0, 0)
        end

      end

    end

    describe 'when processing branches' do

      it 'should find a virtual method call' do
        content = <<-END
          def method_name
            call_foo
          end
        END

        verify_content_score(content, 0, 1, 0)
      end

      it 'should find an explicit method call' do
        content = <<-END
          def method_name
            @object.call_foo
          end
        END

        verify_content_score(content, 0, 1, 0)
      end

      it 'should exclude a condition' do
        content = <<-END
          def method_name
            @object.call_foo < 10
          end
        END

        verify_content_score(content, 0, 1, 1)
      end

    end

    describe 'when processing conditions' do

      ['==', '!=', '<=', '>=', '<', '>', '<=>'].each do |conditional|

        it "should find #{conditional}" do
          content = <<-END
            def method_name
              2 #{conditional} 1
            end
          END

          verify_content_score(content, 0, 0, 1)
        end

      end 

    end

  end

  def verify_content_score(content, a, b, c)
    score = Math.sqrt(a*a + b*b + c*c)
    @roodi.check_content(content)
    errors = @roodi.errors

    errors.should_not be_empty
    errors[0].info.should == { :method => :method_name, :score => score }
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
marcoow-roodi-1.3.4 spec/roodi/checks/abc_metric_method_check_spec.rb
marcoow-roodi-1.3.5 spec/roodi/checks/abc_metric_method_check_spec.rb