Sha256: 82e9534cd36f411b1c68b1c377d4e7f1fbd5953eed0dd82f662691bbddd83bf7

Contents?: true

Size: 1.51 KB

Versions: 2

Compression:

Stored size: 1.51 KB

Contents

require_relative 'spec_helper'
require 'httpimagestore/ruby_string_template'

describe RubyStringTemplate do
	subject do
		RubyStringTemplate.new('>#{hello}-#{world}#{test}<')
	end

	it 'should replace holders with given values' do
		subject.render(hello: 'hello', world: 'world', test: 123).should == '>hello-world123<'
	end

	it 'should raise NoValueForTemplatePlaceholderError if template value was not provided' do
		expect {
			subject.render(hello: 'hello', test: 123)
		}.to raise_error RubyStringTemplate::NoValueForTemplatePlaceholderError, %q{no value for '#{world}' in template '>#{hello}-#{world}#{test}<'}
	end

	it 'should not process nested placeholders' do
		subject.render(hello: '#{nested}', world: 'world', test: 123, nested: 'xxx').should == '>#{nested}-world123<'
	end

	describe 'with custom resolver' do
		subject do
			RubyStringTemplate.new('>#{hello}-#{world}#{test}<') do |locals, name|
				case name
				when :test
					321
				else
					locals[name]
				end
			end
		end

		it 'should ask for values using provided resolver' do
			subject.render(hello: 'hello', world: 'world').should == '>hello-world321<'
			subject.render(hello: 'hello', world: 'world', test: 123).should == '>hello-world321<'
		end

		it 'should raise NoValueForTemplatePlaceholderError if template value was not provided' do
			expect {
				subject.render(hello: 'hello', test: 123)
			}.to raise_error RubyStringTemplate::NoValueForTemplatePlaceholderError, %q{no value for '#{world}' in template '>#{hello}-#{world}#{test}<'}
		end
	end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
httpimagestore-1.8.0 spec/ruby_string_template_spec.rb
httpimagestore-1.7.0 spec/ruby_string_template_spec.rb