Sha256: 5b9a5e9193b8b3bdfc9edb1a46cda5601dc067021709652423db0cbb9e890d16

Contents?: true

Size: 1.81 KB

Versions: 3

Compression:

Stored size: 1.81 KB

Contents

require 'spec_helper'

describe 'empty_string_assignment' do
  let (:msg) { 'variable assigned to the empty string' }

  context 'with fix disabled' do
    context 'class definition without empty strings' do
      let (:code) {
        <<-EOS
        class foo ( $bar = 'baz' ) { }
        EOS
      }

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

    context 'class definition with empty strings' do
      let (:code) {
        <<-EOS
        class foo ( $bar = '' ) { }
        EOS
      }

      it 'should 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(28)
      end
    end
  end

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

    after do
      PuppetLint.configuration.fix = false
    end

    context 'class definition without empty string' do
      let (:code) {
        <<-EOS
        class foo ( $bar = 'baz' ) { }
        EOS
      }

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

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

    context 'class definition with empty strings' do
      let (:code) {
        <<-EOS
        class foo ( $bar = '' ) { }
        EOS
      }

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

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

      it 'should should use undef' do
        expect(manifest).to eq(
          <<-EOS
        class foo ( $bar = undef ) { }
          EOS
        )
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
puppet-lint-empty_string-check-1.0.0 spec/puppet-lint/plugins/check_empty_string_assignment/check_empty_string_assignment_spec.rb
puppet-lint-empty_string-check-0.2.2 spec/puppet-lint/plugins/check_empty_string_assignment/check_empty_string_assignment_spec.rb
puppet-lint-empty_string-check-0.2.1 spec/puppet-lint/plugins/check_empty_string_assignment/check_empty_string_assignment_spec.rb