From c89a62b8e91dc1329aee92392eb32a51a25a8315 Mon Sep 17 00:00:00 2001 From: Markus Doits Date: Sat, 31 Mar 2018 18:34:01 +0200 Subject: refactor config handling and specs a little bit --- spec/pronto/eslint_spec.rb | 39 +++++++++++++++++++++++++++++++++++++++ spec/spec_helper.rb | 9 ++++----- 2 files changed, 43 insertions(+), 5 deletions(-) (limited to 'spec') 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 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 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' end RSpec.shared_context 'with config', config: true do - requested_config = metadata[:config].to_yaml + requested_config = metadata[:config] - let(:config_path) { File.join(repo.path.to_s, Pronto::ESLintNpm::CONFIG_FILE) } - - before(:each) { File.write(config_path, requested_config) } - after(:each) { FileUtils.rm(config_path) } + before(:each) do + allow_any_instance_of(Pronto::ESLintNpm).to receive(:config_options).and_return(requested_config) + end end -- cgit v1.2.3