Sha256: 574127c7fb8350073ff2691479771502cad7e70fa20ab496f5352b046dd5ee7c

Contents?: true

Size: 1.91 KB

Versions: 3

Compression:

Stored size: 1.91 KB

Contents

require 'spec_helper'

describe 'variable_contains_upcase' do
  let(:msg) { 'variable contains a capital letter' }

  context 'a variable containing a capital' do
    let(:code) { '$fOobar' }

    it 'should only detect a single problem' do
      expect(problems).to have(1).problem
    end

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

  context 'variable containing a capital' do
    let(:code) { '" $fOobar"' }

    it 'should only detect a single problem' do
      expect(problems).to have(1).problem
    end

    it 'should create a warning' do
      expect(problems).to contain_warning(msg).on_line(1).in_column(3)
    end
  end

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

    after do
      PuppetLint.configuration.fix = false
    end

    context 'fix variable containing a capital' do
      let(:code) { '" $fOobar"' }

      it 'should only detect a single problem' do
        expect(problems).to have(1).problem
      end

      it 'should fix the manifest' do
        expect(problems).to contain_fixed(msg).on_line(1).in_column(3)
      end

      it 'should downcase the variable name' do
        expect(manifest).to eq('" $foobar"')
      end
    end

    context 'a hash with an upcase key should not fail' do
      let(:code) { ' $myhash["Foo"]' }

      it 'should not detect a single problem' do
        expect(problems).to have(0).problem
      end
    end
    context 'a hash with an upcase key should not fail' do
      let(:code) { ' $myhash["Foo"]["bAr"]' }

      it 'should not detect a single problem' do
        expect(problems).to have(0).problem
      end
    end
    context 'a hash variable with an upcase key should fail' do
      let(:code) { ' $myHash["foo"]["bar"]' }

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
puppet-lint-variable_contains_upcase-1.4.0 spec/puppet-lint/plugins/variable_contains_upcase_spec.rb
puppet-lint-variable_contains_upcase-1.3.0 spec/puppet-lint/plugins/variable_contains_upcase_spec.rb
puppet-lint-variable_contains_upcase-1.2.0 spec/puppet-lint/plugins/variable_contains_upcase_spec.rb