spec/integration/extension_spec.rb in middleman-webp-0.2.7 vs spec/integration/extension_spec.rb in middleman-webp-0.3.0
- old
+ new
@@ -3,31 +3,98 @@
require_relative '../../lib/middleman-webp/extension'
describe Middleman::WebPExtension do
before do
@builder = Middleman::Cli::Build.new
- @builder.expects(:say_status).once.with do |action, msg, opts|
- action == :webp and msg =~ /Total conversion savings/
- end
@builder.stubs(:say_status).with do |action, msg, opts|
action == :webp and msg =~ /Please install latest version of webp/
end
end
after do
# Remove temporarily created files
Dir.glob('spec/fixtures/ok-build/**/*.webp').each do |file|
File.unlink(file)
end
+ Dir.glob('spec/fixtures/ok-source/**/*.webp').each do |file|
+ File.unlink(file)
+ end
end
+ describe '#before_build' do
+ it 'does not generate WebP versions using external tools' do
+ app_mock = stub({
+ initialized: '',
+ instance_available: true,
+ after_configuration: nil,
+ before_build: nil,
+ after_build: nil,
+ inst: stub(source_dir: 'spec/fixtures/ok-source')
+ })
+
+ @builder.expects(:say_status).never.with do |action, msg, opts|
+ action == :webp and msg =~ /Total conversion savings/
+ end
+
+ @builder.expects(:say_status).never.with do |action, msg, opts|
+ action == :run and msg =~ /cwebp/
+ end
+
+ @builder.expects(:say_status).never.with do |action, msg, opts|
+ action == :webp and msg =~ /\.webp \([0-9.]+ % smaller\)/
+ end
+
+ @extension = Middleman::WebPExtension.new(app_mock)
+ @extension.before_build(@builder)
+
+ Dir.glob('spec/fixtures/ok-source/**/*.webp').size.must_equal 0
+ end
+
+ it 'generates WebP versions using external tools when option is set' do
+ app_mock = stub({
+ initialized: '',
+ instance_available: true,
+ after_configuration: nil,
+ before_build: nil,
+ after_build: nil,
+ inst: stub(source_dir: 'spec/fixtures/ok-source')
+ })
+
+ @builder.expects(:say_status).once.with do |action, msg, opts|
+ action == :webp and msg =~ /Total conversion savings/
+ end
+
+ @builder.expects(:say_status).twice.with do |action, msg, opts|
+ action == :run and msg =~ /cwebp/
+ end
+
+ @builder.expects(:say_status).twice.with do |action, msg, opts|
+ action == :webp and msg =~ /\.webp \([0-9.]+ % smaller\)/
+ end
+
+ @extension = Middleman::WebPExtension.new(app_mock) do |webp|
+ webp.run_before_build = true
+ end
+ @extension.before_build(@builder)
+
+ Dir.glob('spec/fixtures/ok-source/**/*.webp').size.must_equal 2
+ end
+ end
+
describe '#after_build' do
+ before do
+ @builder.expects(:say_status).once.with do |action, msg, opts|
+ action == :webp and msg =~ /Total conversion savings/
+ end
+ end
+
it 'generates WebP versions using external tools' do
app_mock = stub({
initialized: '',
instance_available: true,
after_configuration: nil,
+ before_build: nil,
after_build: nil,
inst: stub(build_dir: 'spec/fixtures/ok-build')
})
@builder.expects(:say_status).twice.with do |action, msg, opts|
@@ -47,10 +114,11 @@
it 'shows errors if files couldn\'t be converted' do
app_mock = stub({
initialized: '',
instance_available: true,
after_configuration: nil,
+ before_build: nil,
after_build: nil,
inst: stub(build_dir: 'spec/fixtures/dummy-build')
})
Middleman::WebP::Converter.any_instance.
@@ -67,9 +135,10 @@
it 'rejects file if it is larger than original' do
app_mock = stub({
initialized: '',
instance_available: true,
after_configuration: nil,
+ before_build: nil,
after_build: nil,
inst: stub(build_dir: 'spec/fixtures/dummy-build')
})
Middleman::WebP::Converter.any_instance.