Fix license_template_spec to not modify String

Revamp how spec verifies proc#call called only once
This commit is contained in:
Thong Kuah 2019-04-01 13:25:54 +13:00
parent 5cd63ace04
commit 32a1277d28

View file

@ -5,14 +5,15 @@ require 'spec_helper'
describe LicenseTemplate do
describe '#content' do
it 'calls a proc exactly once if provided' do
lazy = build_template(-> { 'bar' })
content = lazy.content
content_proc = -> { 'bar' }
expect(content_proc).to receive(:call).once.and_call_original
expect(content).to eq('bar')
expect(content.object_id).to eq(lazy.content.object_id)
lazy = build_template(content_proc)
content.replace('foo')
expect(lazy.content).to eq('foo')
expect(lazy.content).to eq('bar')
# Subsequent calls should not call proc again
expect(lazy.content).to eq('bar')
end
it 'returns a string if provided' do