|
1 | 1 | require 'spec_helper'
|
2 |
| -require 'image_optim' |
3 | 2 |
|
4 | 3 | describe Overcommit::Hook::PreCommit::ImageOptim do
|
5 | 4 | let(:config) { Overcommit::ConfigurationLoader.default_configuration }
|
|
10 | 9 | subject.stub(:applicable_files).and_return(%w[file1.jpg file2.png])
|
11 | 10 | end
|
12 | 11 |
|
13 |
| - context 'when a dependency of image_optim is not installed' do |
| 12 | + context 'when image_optim exits successfully' do |
| 13 | + let(:result) { double('result') } |
| 14 | + |
14 | 15 | before do
|
15 |
| - subject.stub(:optimize_images).and_raise(::ImageOptim::BinResolver::BinNotFound) |
| 16 | + result.stub(:success?).and_return(true) |
| 17 | + subject.stub(:execute).and_return(result) |
16 | 18 | end
|
17 | 19 |
|
18 |
| - it { should fail_hook } |
19 |
| - end |
| 20 | + context 'and images were optimized' do |
| 21 | + before do |
| 22 | + result.stub(:stdout).and_return([ |
| 23 | + '32.30% 1.2K file1.jpg', |
| 24 | + 'Total: 32.30% 1.2K', |
| 25 | + ].join("\n")) |
| 26 | + end |
20 | 27 |
|
21 |
| - context 'when an image was optimized' do |
22 |
| - before do |
23 |
| - subject.stub(:optimize_images).and_return(['file1.jpg']) |
| 28 | + it { should fail_hook } |
24 | 29 | end
|
25 | 30 |
|
26 |
| - it { should fail_hook } |
| 31 | + context 'and no images were optimized' do |
| 32 | + before do |
| 33 | + result.stub(:stdout).and_return([ |
| 34 | + '------ app/assets/images/favicons/favicon-96x96.png', |
| 35 | + 'Total: ------', |
| 36 | + ].join("\n")) |
| 37 | + end |
| 38 | + |
| 39 | + it { should pass } |
| 40 | + end |
27 | 41 | end
|
28 | 42 |
|
29 |
| - context 'when no images were optimized' do |
| 43 | + context 'when image_optim exits unsuccessfully' do |
| 44 | + let(:result) { double('result') } |
| 45 | + |
30 | 46 | before do
|
31 |
| - subject.stub(:optimize_images).and_return([]) |
| 47 | + result.stub(:success?).and_return(false) |
| 48 | + result.stub(:stdout).and_return('An error occurred') |
| 49 | + result.stub(:stderr).and_return('') |
| 50 | + subject.stub(:execute).and_return(result) |
32 | 51 | end
|
33 | 52 |
|
34 |
| - it { should pass } |
| 53 | + it { should fail_hook } |
35 | 54 | end
|
36 | 55 | end
|
0 commit comments