spec/compiler_spec.rb in smallvictories-0.0.11 vs spec/compiler_spec.rb in smallvictories-0.0.12
- old
+ new
@@ -2,10 +2,13 @@
describe SmallVictories do
let(:destination_css) { './fixtures/destination/_sv_custom.css' }
let(:destination_js) { './fixtures/destination/_sv_custom.js' }
let(:destination_html) { './fixtures/destination/index.html' }
+ let(:destination_sprite_file) { './fixtures/destination/_sv_sprite.png' }
+ let(:source_sprite_file) { './fixtures/source/_sv_sprite.png' }
+ let(:destination_sprite_style) { './fixtures/source/sprite.scss' }
let(:compiler) { SmallVictories::Compiler.new(config: SmallVictories::Configuration.new) }
before do
allow_any_instance_of(SmallVictories::Configuration).to receive(:source).and_return('./spec/fixtures/source')
allow_any_instance_of(SmallVictories::Configuration).to receive(:destination).and_return('./spec/fixtures/destination')
@@ -41,10 +44,21 @@
describe '#compile_css' do
it 'compiles the css file' do
compiler.compile_css
expect(File.open(destination_css).read).to include '.bootstrap{color:black;box-sizing:content-box}html{background:white}body div{background:red}p{font-size:30px}'
end
+
+ context 'with compile disabled' do
+ before do
+ allow_any_instance_of(SmallVictories::Configuration).to receive(:compile_css).and_return(false)
+ end
+
+ it 'does not compile the liquid files' do
+ compiler.compile_css
+ expect(File.exists?(destination_css)).to eq false
+ end
+ end
end
describe '#minify_css' do
it 'compiles and prefixes the css file' do
compiler.minify_css
@@ -55,10 +69,21 @@
describe '#compile_js' do
it 'compiles the js file' do
compiler.compile_js
expect(File.open(destination_js).read).to include '(function(){alert("hi")}).call(this),console.log("hi");'
end
+
+ context 'with compile disabled' do
+ before do
+ allow_any_instance_of(SmallVictories::Configuration).to receive(:compile_js).and_return(false)
+ end
+
+ it 'does not compile the liquid files' do
+ compiler.compile_js
+ expect(File.exists?(destination_js)).to eq false
+ end
+ end
end
describe '#minify_js' do
it 'minifies the js file' do
compiler.minify_js
@@ -70,10 +95,21 @@
it 'compiles the liquid files' do
compiler.compile_html
expect(File.open(destination_html).read).to include "<html>\n<h1>Index</h1>\n<p>My snippet</p>\n\n\n</html>"
end
+ context 'with compile disabled' do
+ before do
+ allow_any_instance_of(SmallVictories::Configuration).to receive(:compile_html).and_return(false)
+ end
+
+ it 'does not compile the liquid files' do
+ compiler.compile_html
+ expect(File.exists?(destination_html)).to eq false
+ end
+ end
+
context 'with no layout' do
before do
allow_any_instance_of(SmallVictories::Configuration).to receive(:layout).and_return('no-file-here')
end
@@ -112,8 +148,21 @@
end
it 'shows the error in html' do
compiler.compile_html
expect(File.open(destination_html).read).to include "<html>\n<h1>Index</h1>\nLiquid error: No such template 'snippet'\n\n</html>"
+ end
+ end
+
+ describe '#compile_sprite' do
+ it 'compiles the image files into a sprite' do
+ compiler.compile_sprite
+ expect(File.exists?(destination_sprite_file)).to eq true
+ expect(File.exists?(source_sprite_file)).to eq true
+ end
+
+ it 'compiles the css for the image sprite' do
+ compiler.compile_sprite
+ expect(File.exists?(destination_sprite_style)).to eq true
end
end
end