require 'spec_helper'
require 'magic_reveal/slide_renderer'
require 'tmpdir'
describe MagicReveal::SlideRenderer do
describe '.header' do
context 'when no slides have been shown' do
before { subject.has_shown_slides = false }
it 'starts with
/) end end context 'without language' do it 'has pre without class' do expect(subject.block_code(code, nil)) .to match(/\A\s*\s*\Z}) end it 'has no space between/) end end it 'wraps the text in a' do expect(subject.block_code('whatever', nil)) .to match(%r{tag' do text = "#{rand 99} text #{rand 99}" expect(subject.block_code(text, nil)) .to match(%r{
#{Regexp.quote text}
}) end it 'escapes the code text' do CGI.should_receive(:escapeHTML).and_return('text') subject.block_code('whatever', nil) end it 'ends with
and ' do
expect(subject.block_code('whatever', nil))
.to match(/]*>/)
end
it 'has no space between
and
' do
expect(subject.block_code('whatever', nil))
.to match(%r{
})
end
it "doesn't add whitespace after code and before " do
expect(subject.block_code('mouse', nil)).to match(%r{mouse})
end
end
describe 'prepare_code' do
context 'with @@source = filename' do
around do |example|
Dir.mktmpdir do |dir|
@tmpdir = Pathname.new dir
example.run
end
end
let(:filename) { @tmpdir + "file#{rand 99}" }
it 'loads the contents from filename' do
text = "#{rand 99} bottles of beer"
filename.open('w') { |f| f.write text }
expect(subject.prepare_code "@@source = #{filename}").to eq(text)
end
end
context 'without @@source' do
it 'returns the text' do
text = "#{rand 99} luft balloons."
expect(subject.prepare_code text).to eq(text)
end
it 'strips leading whitespace' do
expect(subject.prepare_code " \t\nmouse")
.to eq('mouse')
end
it 'strips trailing whitespace' do
expect(subject.prepare_code "mouse\n\t ")
.to eq('mouse')
end
end
end
end