Sha256: 7c72ec0e26b1c106cf44c87eb615304c5a1101f4eb2553b3f3263223d89f3780

Contents?: true

Size: 1.35 KB

Versions: 8

Compression:

Stored size: 1.35 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

	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

8 entries across 8 versions & 1 rubygems

Version Path
httpimagestore-1.6.0 spec/ruby_string_template_spec.rb
httpimagestore-1.5.0 spec/ruby_string_template_spec.rb
httpimagestore-1.4.1 spec/ruby_string_template_spec.rb
httpimagestore-1.4.0 spec/ruby_string_template_spec.rb
httpimagestore-1.3.0 spec/ruby_string_template_spec.rb
httpimagestore-1.2.0 spec/ruby_string_template_spec.rb
httpimagestore-1.1.0 spec/ruby_string_template_spec.rb
httpimagestore-1.0.0 spec/ruby_string_template_spec.rb