forked from sds/scss-lint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rake_task_spec.rb
92 lines (73 loc) · 2.03 KB
/
rake_task_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
require 'spec_helper'
require 'scss_lint/rake_task'
require 'tempfile'
describe SCSSLint::RakeTask do
before do
STDOUT.stub(:write) # Silence console output
end
after(:each) do
Rake::Task['scss_lint'].clear if Rake::Task.task_defined?('scss_lint')
end
let(:file) do
Tempfile.new(%w[scss-file .scss]).tap do |f|
f.write(scss)
f.close
end
end
def run_task
Rake::Task[:scss_lint].tap do |t|
t.reenable # Allows us to execute task multiple times
t.invoke(file.path)
end
end
context 'basic RakeTask' do
before(:each) do
SCSSLint::RakeTask.new
end
context 'when SCSS document is valid with no lints' do
let(:scss) { '' }
it 'does not call Kernel.exit' do
expect { run_task }.not_to raise_error
end
end
context 'when SCSS document is invalid' do
let(:scss) { '.class {' }
it 'calls Kernel.exit with the status code' do
expect { run_task }.to raise_error SystemExit
end
end
end
context 'configured RakeTask with a config file' do
let(:scss) { '' }
let(:config_file) do
config = Tempfile.new(%w[foo .yml])
config.write('')
config.close
config.path
end
it 'passes config files to the CLI' do
SCSSLint::RakeTask.new.tap do |t|
t.config = config_file
end
cli = double(SCSSLint::CLI)
SCSSLint::CLI.should_receive(:new) { cli }
args = ['--config', config_file, file.path]
cli.should_receive(:run).with(args) { 0 }
expect { run_task }.not_to raise_error
end
end
context 'configured RakeTask with args' do
let(:scss) { '' }
it 'passes args to the CLI' do
formatter_args = ['--formatter', 'JSON']
SCSSLint::RakeTask.new.tap do |t|
t.args = formatter_args
end
cli = double(SCSSLint::CLI)
SCSSLint::CLI.should_receive(:new) { cli }
args = formatter_args + [file.path]
cli.should_receive(:run).with(args) { 0 }
expect { run_task }.not_to raise_error
end
end
end