Sha256: c2ec1b9579e6281799f06e636198ce968b5919289b66d69709a279d6e9493ba9

Contents?: true

Size: 1.65 KB

Versions: 204

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 has wrong type, expects 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 has wrong type, expects 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 has wrong type, expects 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

204 entries across 204 versions & 1 rubygems

Version Path
puppet-5.5.6 spec/unit/pops/types/type_asserter_spec.rb
puppet-5.5.6-x86-mingw32 spec/unit/pops/types/type_asserter_spec.rb
puppet-5.5.6-x64-mingw32 spec/unit/pops/types/type_asserter_spec.rb
puppet-5.5.6-universal-darwin spec/unit/pops/types/type_asserter_spec.rb
puppet-5.5.3 spec/unit/pops/types/type_asserter_spec.rb
puppet-5.5.3-x86-mingw32 spec/unit/pops/types/type_asserter_spec.rb
puppet-5.5.3-x64-mingw32 spec/unit/pops/types/type_asserter_spec.rb
puppet-5.5.3-universal-darwin spec/unit/pops/types/type_asserter_spec.rb
puppet-5.5.2 spec/unit/pops/types/type_asserter_spec.rb
puppet-5.5.2-x86-mingw32 spec/unit/pops/types/type_asserter_spec.rb
puppet-5.5.2-x64-mingw32 spec/unit/pops/types/type_asserter_spec.rb
puppet-5.5.2-universal-darwin spec/unit/pops/types/type_asserter_spec.rb
puppet-5.3.7 spec/unit/pops/types/type_asserter_spec.rb
puppet-5.3.7-x86-mingw32 spec/unit/pops/types/type_asserter_spec.rb
puppet-5.3.7-x64-mingw32 spec/unit/pops/types/type_asserter_spec.rb
puppet-5.3.7-universal-darwin spec/unit/pops/types/type_asserter_spec.rb
puppet-4.10.12 spec/unit/pops/types/type_asserter_spec.rb
puppet-4.10.12-x86-mingw32 spec/unit/pops/types/type_asserter_spec.rb
puppet-4.10.12-x64-mingw32 spec/unit/pops/types/type_asserter_spec.rb
puppet-4.10.12-universal-darwin spec/unit/pops/types/type_asserter_spec.rb