2019-03-30 03:23:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-08-14 17:29:59 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe LicenseTemplate do
|
|
|
|
describe '#content' do
|
|
|
|
it 'calls a proc exactly once if provided' do
|
2019-03-31 20:25:54 -04:00
|
|
|
content_proc = -> { 'bar' }
|
|
|
|
expect(content_proc).to receive(:call).once.and_call_original
|
2018-08-14 17:29:59 -04:00
|
|
|
|
2019-03-31 20:25:54 -04:00
|
|
|
lazy = build_template(content_proc)
|
2018-08-14 17:29:59 -04:00
|
|
|
|
2019-03-31 20:25:54 -04:00
|
|
|
expect(lazy.content).to eq('bar')
|
|
|
|
|
|
|
|
# Subsequent calls should not call proc again
|
|
|
|
expect(lazy.content).to eq('bar')
|
2018-08-14 17:29:59 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a string if provided' do
|
|
|
|
lazy = build_template('bar')
|
|
|
|
|
|
|
|
expect(lazy.content).to eq('bar')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#resolve!' do
|
|
|
|
let(:content) do
|
|
|
|
<<~TEXT
|
|
|
|
Pretend License
|
|
|
|
|
|
|
|
[project]
|
|
|
|
|
|
|
|
Copyright (c) [year] [fullname]
|
|
|
|
TEXT
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:expected) do
|
|
|
|
<<~TEXT
|
|
|
|
Pretend License
|
|
|
|
|
|
|
|
Foo Project
|
|
|
|
|
|
|
|
Copyright (c) 1985 Nick Thomas
|
|
|
|
TEXT
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:template) { build_template(content) }
|
|
|
|
|
|
|
|
it 'updates placeholders in a copy of the template content' do
|
|
|
|
expect(template.content.object_id).to eq(content.object_id)
|
|
|
|
|
|
|
|
template.resolve!(project_name: "Foo Project", fullname: "Nick Thomas", year: "1985")
|
|
|
|
|
|
|
|
expect(template.content).to eq(expected)
|
|
|
|
expect(template.content.object_id).not_to eq(content.object_id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def build_template(content)
|
2018-10-02 19:00:38 -04:00
|
|
|
described_class.new(key: 'foo', name: 'foo', category: :Other, content: content)
|
2018-08-14 17:29:59 -04:00
|
|
|
end
|
|
|
|
end
|