spec/integration/extension_spec.rb in middleman-webp-0.3.2 vs spec/integration/extension_spec.rb in middleman-webp-0.4.0
- old
+ new
@@ -1,15 +1,16 @@
require 'spec_helper'
+require 'middleman-core'
require 'middleman-core/cli'
require_relative '../../lib/middleman-webp/extension'
describe Middleman::WebPExtension do
before do
@builder = Middleman::Cli::Build.new
- @builder.stubs(:say_status).with do |action, msg, opts|
- action == :webp and msg =~ /Please install latest version of webp/
- end
+ #@builder.stubs(:thor).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|
@@ -19,31 +20,35 @@
File.unlink(file)
end
end
describe '#before_build' do
- it 'does not generate WebP versions using external tools' do
+ it 'does not generate WebP versions by default' 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')
+ root: '.',
+ config: {source: 'spec/fixtures/ok-source'}
})
- @builder.expects(:say_status).never.with do |action, msg, opts|
- action == :webp and msg =~ /Total conversion savings/
- end
+ Middleman::WebP::Logger.any_instance.expects(:info).never
+ .with do |msg, color|
+ msg =~ /Total conversion savings/
+ end
- @builder.expects(:say_status).never.with do |action, msg, opts|
- action == :run and msg =~ /cwebp/
- end
+ Middleman::WebP::Logger.any_instance.expects(:info).never
+ .with do |msg|
+ msg =~ /cwebp/
+ end
- @builder.expects(:say_status).never.with do |action, msg, opts|
- action == :webp and msg =~ /\.webp \([0-9.]+ % smaller\)/
- end
+ Middleman::WebP::Logger.any_instance.expects(:info).never
+ .with do |msg|
+ 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
@@ -54,25 +59,23 @@
initialized: '',
instance_available: true,
after_configuration: nil,
before_build: nil,
after_build: nil,
- inst: stub(source_dir: 'spec/fixtures/ok-source')
+ verbose: true,
+ root: '.',
+ config: {source: 'spec/fixtures/ok-source'}
})
- @builder.expects(:say_status).once.with do |action, msg, opts|
- action == :webp and msg =~ /Total conversion savings/
+ Middleman::WebP::Logger.any_instance.expects(:info).once.with do |msg, c|
+ msg =~ /Total conversion savings/
end
- @builder.expects(:say_status).twice.with do |action, msg, opts|
- action == :run and msg =~ /cwebp/
+ Middleman::WebP::Logger.any_instance.expects(:info).twice.with do |msg|
+ msg =~ /\.webp \([0-9.]+ % smaller\)/
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)
@@ -80,33 +83,30 @@
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/
+ Middleman::WebP::Logger.any_instance.expects(:info).once.with do |msg|
+ 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')
+ root: '.',
+ config: {build_dir: 'spec/fixtures/ok-build'}
})
- @builder.expects(:say_status).twice.with do |action, msg, opts|
- action == :run and msg =~ /cwebp/
+ Middleman::WebP::Logger.any_instance.expects(:info).twice.with do |msg|
+ msg =~ /\.webp \([0-9.]+ % smaller\)/
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)
@extension.after_build(@builder)
Dir.glob('spec/fixtures/ok-build/**/*.webp').size.must_equal 2
end
@@ -116,17 +116,18 @@
initialized: '',
instance_available: true,
after_configuration: nil,
before_build: nil,
after_build: nil,
- inst: stub(build_dir: 'spec/fixtures/dummy-build')
+ root: '.',
+ config: {build_dir: 'spec/fixtures/dummy-build'}
})
Middleman::WebP::Converter.any_instance.
expects(:exec_convert_tool).times(3)
- @builder.expects(:say_status).times(3).with do |action, msg, opts|
+ Middleman::WebP::Logger.any_instance.expects(:error).times(3).with do |msg|
msg =~ /Converting .*empty\.(jpg|gif|png) failed/
end
@extension = Middleman::WebPExtension.new(app_mock)
@extension.after_build(@builder)
@@ -137,11 +138,12 @@
initialized: '',
instance_available: true,
after_configuration: nil,
before_build: nil,
after_build: nil,
- inst: stub(build_dir: 'spec/fixtures/dummy-build')
+ root: '.',
+ config: {build_dir: 'spec/fixtures/dummy-build'}
})
Middleman::WebP::Converter.any_instance.
expects(:exec_convert_tool).times(3).with do |src, dst|
if dst.to_s =~ /spec\/fixtures\/dummy-build\/.*webp$/
@@ -152,12 +154,11 @@
else
false
end
end
- @builder.expects(:say_status).times(3).with do |action, msg, opts|
- action == :webp and msg =~ /.*empty.webp skipped/
- end
+ Middleman::WebP::Logger.any_instance.expects(:info).times(3)
+ .with { |msg| msg =~ /.*empty.webp skipped/ }.returns(nil)
@extension = Middleman::WebPExtension.new(app_mock)
@extension.after_build(@builder)
Dir.glob('spec/fixtures/dummy-build/**/*.webp').size.must_equal 0