sprintf_hash_spec.rb 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. require 'spec_helper'
  2. describe 'sprintf_hash' do
  3. it 'exists' do
  4. is_expected.not_to eq(nil)
  5. end
  6. context 'with param count' do
  7. it 'fails with no arguments' do
  8. is_expected.to run.with_params.and_raise_error(ArgumentError, %r{expects 2 arguments}i)
  9. end
  10. it 'fails with 1 argument' do
  11. is_expected.to run.with_params('').and_raise_error(ArgumentError, %r{expects 2 arguments}i)
  12. end
  13. it 'fails with too many arguments' do
  14. is_expected.to run.with_params('', '', '').and_raise_error(ArgumentError, %r{expects 2 arguments}i)
  15. end
  16. end
  17. context 'with param type' do
  18. it 'fails with wrong format type' do
  19. is_expected.to run.with_params(false, {}).and_raise_error(ArgumentError, %r{parameter 'format' expects a String value}i)
  20. end
  21. it 'fails with wrong arguments type' do
  22. is_expected.to run.with_params('', false).and_raise_error(ArgumentError, %r{parameter 'arguments' expects a Hash value}i)
  23. end
  24. end
  25. it 'prints formats with name placeholders' do
  26. 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
  27. .and_return('string _foo_ and integer 101')
  28. end
  29. end