]> git.immae.eu Git - github/fretlink/pronto-hlint.git/blobdiff - spec/pronto/eslint_spec.rb
refactor config handling and specs a little bit
[github/fretlink/pronto-hlint.git] / spec / pronto / eslint_spec.rb
index 52e52f2db6f004b145a21577c0c18ffb3c011589..a00a05b519656393d6bb898916491e6832bc1e5b 100644 (file)
@@ -100,6 +100,45 @@ module Pronto
       it 'is `eslint` by default' do
         expect(eslint_executable).to eql('eslint')
       end
+
+      context(
+        'with different eslint executable config',
+        config: { 'eslint_executable' => 'custom_eslint' }
+      ) do
+        it 'is correct' do
+          eslint.read_config
+          expect(eslint_executable).to eql('custom_eslint')
+        end
+      end
+    end
+
+    describe '#eslint_command_line' do
+      subject(:eslint_command_line) { eslint.send(:eslint_command_line, path) }
+      let(:path) { '/some/path.rb' }
+
+      it 'adds json output flag' do
+        expect(eslint_command_line).to include('-f json')
+      end
+
+      it 'adds path' do
+        expect(eslint_command_line).to include(path)
+      end
+
+      it 'starts with eslint executable' do
+        expect(eslint_command_line).to start_with(eslint.eslint_executable)
+      end
+
+      context 'with path that should be escaped' do
+        let(:path) { '/must be/$escaped' }
+
+        it 'escapes the path correctly' do
+          expect(eslint_command_line).to include('/must\\ be/\\$escaped')
+        end
+
+        it 'does not include unescaped path' do
+          expect(eslint_command_line).not_to include(path)
+        end
+      end
     end
   end
 end