view modules/stdlib/spec/functions/sprintf_hash_spec.rb @ 320:99e3ca448d55

Fix Remi PHP on CentOS 8 It uses the new "modules" approach, so we need to use a new package provider They also use different signing keys
author IBBoard <dev@ibboard.co.uk>
date Sun, 01 Mar 2020 10:58:00 +0000
parents c42fb28cff86
children
line wrap: on
line source

require 'spec_helper'

describe 'sprintf_hash' do
  it 'exists' do
    is_expected.not_to eq(nil)
  end

  context 'with param count' do
    it 'fails with no arguments' do
      is_expected.to run.with_params.and_raise_error(ArgumentError, %r{expects 2 arguments}i)
    end
    it 'fails with 1 argument' do
      is_expected.to run.with_params('').and_raise_error(ArgumentError, %r{expects 2 arguments}i)
    end
    it 'fails with too many arguments' do
      is_expected.to run.with_params('', '', '').and_raise_error(ArgumentError, %r{expects 2 arguments}i)
    end
  end

  context 'with param type' do
    it 'fails with wrong format type' do
      is_expected.to run.with_params(false, {}).and_raise_error(ArgumentError, %r{parameter 'format' expects a String value}i)
    end
    it 'fails with wrong arguments type' do
      is_expected.to run.with_params('', false).and_raise_error(ArgumentError, %r{parameter 'arguments' expects a Hash value}i)
    end
  end

  it 'prints formats with name placeholders' do
    is_expected.to run.with_params('string %<foo>s and integer %<bar>b', 'foo' => '_foo_', 'bar' => 5) # rubocop:disable Style/FormatStringToken : Template tokens needed for purposes of test
                      .and_return('string _foo_ and integer 101')
  end
end