Sha256: 50f3b907c6d46dfb352eddc1052764bb06242e0275eb31dcce9536d059b5a74c

Contents?: true

Size: 1.71 KB

Versions: 3

Compression:

Stored size: 1.71 KB

Contents

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

describe Roodi::Checks::ParameterNumberCheck do

  before(:each) do
    @roodi = Roodi::Core::ParseTreeRunner.new(Roodi::Checks::ParameterNumberCheck.new({'parameter_count' => 1}))
  end

  describe '#evaluate' do

    it 'should accept methods with less lines than the threshold' do
      content = <<-END
        def zero_parameter_method
        end
      END
      @roodi.check_content(content)

      @roodi.errors.should be_empty
    end

    it 'should accept methods with the same number of parameters as the threshold' do
      content = <<-END
        def one_parameter_method(first_parameter)
        end
      END
      @roodi.check_content(content)

      @roodi.errors.should be_empty
    end

    it 'should reject methods with more parameters than the threshold' do
      content = <<-END
        def two_parameter_method(first_parameter, second_parameter)
        end
      END
      @roodi.check_content(content)
      errors = @roodi.errors

      errors.should_not be_empty
      errors[0].info.should        == { :method => :two_parameter_method, :parameters => 2 }
      errors[0].filename.should    == 'dummy-file.rb'
      errors[0].line_number.should == 1
    end

    it 'should cope with default values on parameters' do
      content = <<-END
        def two_parameter_method(first_parameter = 1, second_parameter = 2)
        end
      END
      @roodi.check_content(content)
      errors = @roodi.errors

      errors.should_not be_empty
      errors[0].info.should        == { :method => :two_parameter_method, :parameters => 2 }
      errors[0].filename.should    == 'dummy-file.rb'
      errors[0].line_number.should == 1
    end

  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

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