Sha256: c64cbf702f99a007da94a9d70ffff2899b51efec08db767fc7e55889d4c11db0

Contents?: true

Size: 1.61 KB

Versions: 1

Compression:

Stored size: 1.61 KB

Contents

# encoding: utf-8

require 'spec_helper'

module Rubocop
  module Cop
    describe NumericLiterals do
      let (:num) { NumericLiterals.new }

      it "registers an offence for a long integer without underscores" do
        inspect_source(num, 'file.rb', ['a = 123456'])
        num.offences.map(&:message).should ==
          ['Add underscores to large numeric literals to improve their ' +
           'readability.']
      end

      it "registers an offence for an integer with not enough underscores" do
        inspect_source(num, 'file.rb', ['a = 123456_789000'])
        num.offences.map(&:message).should ==
          ['Add underscores to large numeric literals to improve their ' +
           'readability.']
      end

      it "registers an offence for a long float without underscores" do
        inspect_source(num, 'file.rb', ['a = 1.234567'])
        num.offences.map(&:message).should ==
          ['Add underscores to large numeric literals to improve their ' +
           'readability.']
      end

      it "accepts long numbers with underscore" do
        inspect_source(num, 'file.rb', ['a = 123_456',
                                       'b = 1.234_56'])
        num.offences.map(&:message).should == []
      end

      it "accepts a short integer without underscore" do
        inspect_source(num, 'file.rb', ['a = 123'])
        num.offences.map(&:message).should == []
      end

      it "accepts short numbers without underscore" do
        inspect_source(num, 'file.rb', ['a = 123',
                                       'b = 123.456'])
        num.offences.map(&:message).should == []
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rubocop-0.2.0 spec/rubocop/cops/numeric_literals_spec.rb