diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/pronto/eslint_spec.rb | 39 | ||||
-rw-r--r-- | spec/spec_helper.rb | 9 |
2 files changed, 43 insertions, 5 deletions
diff --git a/spec/pronto/eslint_spec.rb b/spec/pronto/eslint_spec.rb index 52e52f2..a00a05b 100644 --- a/spec/pronto/eslint_spec.rb +++ b/spec/pronto/eslint_spec.rb | |||
@@ -100,6 +100,45 @@ module Pronto | |||
100 | it 'is `eslint` by default' do | 100 | it 'is `eslint` by default' do |
101 | expect(eslint_executable).to eql('eslint') | 101 | expect(eslint_executable).to eql('eslint') |
102 | end | 102 | end |
103 | |||
104 | context( | ||
105 | 'with different eslint executable config', | ||
106 | config: { 'eslint_executable' => 'custom_eslint' } | ||
107 | ) do | ||
108 | it 'is correct' do | ||
109 | eslint.read_config | ||
110 | expect(eslint_executable).to eql('custom_eslint') | ||
111 | end | ||
112 | end | ||
113 | end | ||
114 | |||
115 | describe '#eslint_command_line' do | ||
116 | subject(:eslint_command_line) { eslint.send(:eslint_command_line, path) } | ||
117 | let(:path) { '/some/path.rb' } | ||
118 | |||
119 | it 'adds json output flag' do | ||
120 | expect(eslint_command_line).to include('-f json') | ||
121 | end | ||
122 | |||
123 | it 'adds path' do | ||
124 | expect(eslint_command_line).to include(path) | ||
125 | end | ||
126 | |||
127 | it 'starts with eslint executable' do | ||
128 | expect(eslint_command_line).to start_with(eslint.eslint_executable) | ||
129 | end | ||
130 | |||
131 | context 'with path that should be escaped' do | ||
132 | let(:path) { '/must be/$escaped' } | ||
133 | |||
134 | it 'escapes the path correctly' do | ||
135 | expect(eslint_command_line).to include('/must\\ be/\\$escaped') | ||
136 | end | ||
137 | |||
138 | it 'does not include unescaped path' do | ||
139 | expect(eslint_command_line).not_to include(path) | ||
140 | end | ||
141 | end | ||
103 | end | 142 | end |
104 | end | 143 | end |
105 | end | 144 | end |
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b3d8596..c05f072 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb | |||
@@ -17,10 +17,9 @@ require 'pronto/eslint_npm' | |||
17 | end | 17 | end |
18 | 18 | ||
19 | RSpec.shared_context 'with config', config: true do | 19 | RSpec.shared_context 'with config', config: true do |
20 | requested_config = metadata[:config].to_yaml | 20 | requested_config = metadata[:config] |
21 | 21 | ||
22 | let(:config_path) { File.join(repo.path.to_s, Pronto::ESLintNpm::CONFIG_FILE) } | 22 | before(:each) do |
23 | 23 | allow_any_instance_of(Pronto::ESLintNpm).to receive(:config_options).and_return(requested_config) | |
24 | before(:each) { File.write(config_path, requested_config) } | 24 | end |
25 | after(:each) { FileUtils.rm(config_path) } | ||
26 | end | 25 | end |