Sha256: 155e00c307820ff5a79bebb34b949ab9618d421dc245d4cbadf7e03c4a27f8da

Contents?: true

Size: 1.75 KB

Versions: 1

Compression:

Stored size: 1.75 KB

Contents

require 'spec_helper'

describe 'leading_zero' do
  let(:msg) { 'unquoted number with leading zero' }

  context 'with fix disabled' do
    context 'no unquoted numbers with leading zero' do
      let(:code) do
        <<-EOS
        $foo = '010'
        $bar = 10
        $baz = 0
        EOS
      end

      it 'does not detect any problems' do
        expect(problems).to have(0).problems
      end
    end

    context 'unquoted numbers with leading zero' do
      let(:code) do
        <<-EOS
        $foo = 010
        EOS
      end

      it 'detects a single problem' do
        expect(problems).to have(1).problem
      end

      it 'creates a warning' do
        expect(problems).to contain_warning(msg).on_line(1).in_column(16)
      end
    end
  end

  context 'with fix enabled' do
    before do
      PuppetLint.configuration.fix = true
    end

    after do
      PuppetLint.configuration.fix = false
    end

    context 'no unquoted numbers with leading zero' do
      let(:code) do
        <<-EOS
        $foo = '010'
        $bar = 10
        $baz = 0
        EOS
      end

      it 'does not detect any problems' do
        expect(problems).to have(0).problems
      end

      it 'does not modify the manifest' do
        expect(manifest).to eq(code)
      end
    end

    context 'unquoted numbers with leading zero' do
      let(:code) do
        <<-EOS
        $foo = 010
        EOS
      end

      it 'detects a single problem' do
        expect(problems).to have(1).problem
      end

      it 'fixes the problem' do
        expect(problems).to contain_fixed(msg).on_line(1).in_column(16)
      end

      it 'shoulds use undef' do
        expect(manifest).to eq(
          <<-EOS,
        $foo = '010'
          EOS
        )
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
puppet-lint-leading_zero-check-2.0.0 spec/puppet-lint/plugins/check_leading_zero/check_leading_zero_spec.rb