spec/frontman/context_spec.rb in frontman-ssg-0.0.4 vs spec/frontman/context_spec.rb in frontman-ssg-0.1.0

- old
+ new

@@ -23,22 +23,61 @@ it 'should return nil for unknown content' do expect(subject.yield_content('unknown content')).to eq nil end it 'should return not react to unknown content' do - expect(subject.content_for?('unknown content')).to eq false + key = 'unknown content' + + expect(subject.content_for?(key)).to eq false end + it 'should react to known content' do + Frontman::App.instance.current_page = resource + key = 'my-key' + subject.content_for(key, 'myvalue') + expect(subject.content_for?(key)).to eq true + end + it 'should return content when it\'s set' do Frontman::App.instance.current_page = resource - subject.content_for('my-key', 'myvalue') - expect(subject.yield_content('my-key')).to eq 'myvalue' + key = 'my-key' + + subject.content_for(key, 'myvalue') + expect(subject.yield_content(key)).to eq 'myvalue' + + subject.append_content(key, ',othervalue') + expect(subject.yield_content(key)).to eq 'myvalue,othervalue' + + key = 'new-key' + subject.append_content(key, 'test') + expect(subject.yield_content(key)).to eq 'test' end - it 'should react to known content' do + it 'should accept a block' do Frontman::App.instance.current_page = resource - subject.content_for('my-key', 'myvalue') - expect(subject.content_for?('my-key')).to eq true + key = 'my-key' + + subject.content_for(key) do + 'myvalue' + end + + subject.append_content(key) do + ',othervalue' + end + + subject.content_for(key, '') + + subject.content_for(key, 'foobar') do + 'myvalue' + end + + subject.append_content(key, ',foobar') do + ',othervalue' + end + end + + it 'should render correctly' do + expect(Frontman::Resource.from_path('spec/frontman/mocks/context.haml').render).to eq "<h1>123\n</h1>\n<p>456\n</p>\n" end it 'should wrap the layout properly' do Frontman::Config.set(:layout_dir, 'spec/frontman/mocks/layouts') expect(Frontman::Resource.from_path('spec/frontman/mocks/wrap.haml').render).to eq "<h1>This is a test!</h1>\n\n"