Sha256: d219bdb131d5662a55a2d47cd8a3c2e7fdd81c06b5113286845b9445d3b13922

Contents?: true

Size: 1.08 KB

Versions: 15

Compression:

Stored size: 1.08 KB

Contents

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

describe Simplabs::Excellent::Checks::ForLoopCheck do

  before do
    @excellent = Simplabs::Excellent::Runner.new(Simplabs::Excellent::Checks::ForLoopCheck.new)
  end

  describe '#evaluate' do

    it 'should accept iterators' do
      code = <<-END
        [:sym1, :sym2].each do |sym|
        end
      END
      @excellent.check_code(code)
      warnings = @excellent.warnings

      warnings.should be_empty
    end

    it 'should reject for loops on ranges' do
      code = <<-END
        for i in 1..2
        end
      END

      verify_warning_found(code)
    end

    it 'should reject for loops on enumerations' do
      code = <<-END
        for symbol in [:sym1, :sym2]
        end
      END

      verify_warning_found(code)
    end

  end

  def verify_warning_found(code)
    @excellent.check_code(code)
    warnings = @excellent.warnings

    warnings.should_not be_empty
    warnings[0].info.should        == {}
    warnings[0].line_number.should == 1
    warnings[0].message.should     == 'For loop used.'
  end

end

Version data entries

15 entries across 15 versions & 2 rubygems

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