Sha256: 8e77e95bba432ef751ab1ac06fbe936302fcd7bc709d676deedca815aba4da2f

Contents?: true

Size: 1.65 KB

Versions: 36

Compression:

Stored size: 1.65 KB

Contents

require 'spec_helper'
require 'puppet/pops'

module Puppet::Pops::Types
describe 'the type asserter' do
  let!(:asserter) { TypeAsserter }

  context 'when deferring formatting of subject'
  it 'can use an array' do
    expect{ asserter.assert_instance_of(['The %s in the %s', 'gizmo', 'gadget'], PIntegerType::DEFAULT, 'lens') }.to(
    raise_error(TypeAssertionError, 'The gizmo in the gadget had wrong type, expected an Integer value, got String'))
  end

  it 'can use an array obtained from block' do
    expect do
      asserter.assert_instance_of('gizmo', PIntegerType::DEFAULT, 'lens') { |s| ['The %s in the %s', s, 'gadget'] }
    end.to(raise_error(TypeAssertionError, 'The gizmo in the gadget had wrong type, expected an Integer value, got String'))
  end

  it 'can use an subject obtained from zero argument block' do
    expect do
      asserter.assert_instance_of(nil, PIntegerType::DEFAULT, 'lens') { 'The gizmo in the gadget' }
    end.to(raise_error(TypeAssertionError, 'The gizmo in the gadget had wrong type, expected an Integer value, got String'))
  end

  it 'does not produce a string unless the assertion fails' do
    TypeAsserter.expects(:report_type_mismatch).never
    asserter.assert_instance_of(nil, PIntegerType::DEFAULT, 1)
  end

  it 'does not format string unless the assertion fails' do
    fmt_string = 'The %s in the %s'
    fmt_string.expects(:'%').never
    asserter.assert_instance_of([fmt_string, 'gizmo', 'gadget'], PIntegerType::DEFAULT, 1)
  end

  it 'does not call block unless the assertion fails' do
    expect do
      asserter.assert_instance_of(nil, PIntegerType::DEFAULT, 1) { |s| raise Error }
    end.not_to raise_error
  end
end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
puppet-4.7.1 spec/unit/pops/types/type_asserter_spec.rb
puppet-4.7.1-x86-mingw32 spec/unit/pops/types/type_asserter_spec.rb
puppet-4.7.1-x64-mingw32 spec/unit/pops/types/type_asserter_spec.rb
puppet-4.7.1-universal-darwin spec/unit/pops/types/type_asserter_spec.rb
puppet-4.7.0 spec/unit/pops/types/type_asserter_spec.rb
puppet-4.7.0-x86-mingw32 spec/unit/pops/types/type_asserter_spec.rb
puppet-4.7.0-x64-mingw32 spec/unit/pops/types/type_asserter_spec.rb
puppet-4.7.0-universal-darwin spec/unit/pops/types/type_asserter_spec.rb
puppet-4.6.2 spec/unit/pops/types/type_asserter_spec.rb
puppet-4.6.2-x86-mingw32 spec/unit/pops/types/type_asserter_spec.rb
puppet-4.6.2-x64-mingw32 spec/unit/pops/types/type_asserter_spec.rb
puppet-4.6.2-universal-darwin spec/unit/pops/types/type_asserter_spec.rb
puppet-4.6.1-x86-mingw32 spec/unit/pops/types/type_asserter_spec.rb
puppet-4.6.1 spec/unit/pops/types/type_asserter_spec.rb
puppet-4.6.1-x64-mingw32 spec/unit/pops/types/type_asserter_spec.rb
puppet-4.6.1-universal-darwin spec/unit/pops/types/type_asserter_spec.rb
puppet-4.5.3 spec/unit/pops/types/type_asserter_spec.rb
puppet-4.5.3-x86-mingw32 spec/unit/pops/types/type_asserter_spec.rb
puppet-4.5.3-x64-mingw32 spec/unit/pops/types/type_asserter_spec.rb
puppet-4.5.3-universal-darwin spec/unit/pops/types/type_asserter_spec.rb