Sha256: 1271275c61d2a8d419d8cb7eff5a2963ac67f4d1963cb11a00988cfbea41dcce

Contents?: true

Size: 1.14 KB

Versions: 15

Compression:

Stored size: 1.14 KB

Contents

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

describe Simplabs::Excellent::Checks::CyclomaticComplexityBlockCheck do

  before(:each) do
    @excellent = Simplabs::Excellent::Runner.new(Simplabs::Excellent::Checks::CyclomaticComplexityBlockCheck.new({ :threshold => 0 }))
  end

  describe '#evaluate' do

    it 'should find a simple block' do
      code = <<-END
        it 'should be a simple block' do
          call_foo
        end
      END

      verify_code_complexity(code, 1)
    end

    it 'should find a block with multiple paths' do
      code = <<-END
        it 'should be a complex block' do
          if some_condition
            call_foo
          else
            call_bar
          end
        end
      END

      verify_code_complexity(code, 2)
    end

  end

  def verify_code_complexity(code, score)
    @excellent.check_code(code)
    warnings = @excellent.warnings

    warnings.should_not be_empty
    warnings[0].info.should        == { :block => 'block', :score => score }
    warnings[0].line_number.should == 1
    warnings[0].message.should     == "block has cyclomatic complexity of #{score}."
  end

end

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
simplabs-excellent-1.2.2 spec/checks/cyclomatic_complexity_block_check_spec.rb
simplabs-excellent-1.3.0 spec/checks/cyclomatic_complexity_block_check_spec.rb
simplabs-excellent-1.3.1 spec/checks/cyclomatic_complexity_block_check_spec.rb
simplabs-excellent-1.4.0 spec/checks/cyclomatic_complexity_block_check_spec.rb
simplabs-excellent-1.4.1 spec/checks/cyclomatic_complexity_block_check_spec.rb
simplabs-excellent-1.4.2 spec/checks/cyclomatic_complexity_block_check_spec.rb
simplabs-excellent-1.5.0 spec/checks/cyclomatic_complexity_block_check_spec.rb
simplabs-excellent-1.5.1 spec/checks/cyclomatic_complexity_block_check_spec.rb
simplabs-excellent-1.5.2 spec/checks/cyclomatic_complexity_block_check_spec.rb
simplabs-excellent-1.5.3 spec/checks/cyclomatic_complexity_block_check_spec.rb
excellent-1.7.2 spec/checks/cyclomatic_complexity_block_check_spec.rb
excellent-1.7.1 spec/checks/cyclomatic_complexity_block_check_spec.rb
excellent-1.7.0 spec/checks/cyclomatic_complexity_block_check_spec.rb
excellent-1.6.0 spec/checks/cyclomatic_complexity_block_check_spec.rb
excellent-1.5.4 spec/checks/cyclomatic_complexity_block_check_spec.rb