From 1845f2e31adc6f9b1513b779f44e3bd347d6fd11 Mon Sep 17 00:00:00 2001 From: Markus Doits Date: Sun, 11 Sep 2016 14:49:59 +0200 Subject: Allow to set config with `.pronto_eslint_npm.yml` Make configuration dependent on instance instead of class, too. --- spec/fixtures/test.git/custom_eslint.sh | 1 + spec/pronto/eslint_spec.rb | 36 +++++++++++++++++++++++++++++---- spec/spec_helper.rb | 10 ++++++++- 3 files changed, 42 insertions(+), 5 deletions(-) create mode 100755 spec/fixtures/test.git/custom_eslint.sh (limited to 'spec') diff --git a/spec/fixtures/test.git/custom_eslint.sh b/spec/fixtures/test.git/custom_eslint.sh new file mode 100755 index 0000000..54fafdc --- /dev/null +++ b/spec/fixtures/test.git/custom_eslint.sh @@ -0,0 +1 @@ +printf 'custom eslint called' diff --git a/spec/pronto/eslint_spec.rb b/spec/pronto/eslint_spec.rb index 7bbc77a..6358621 100644 --- a/spec/pronto/eslint_spec.rb +++ b/spec/pronto/eslint_spec.rb @@ -3,6 +3,7 @@ require 'spec_helper' module Pronto describe ESLintNpm do let(:eslint) { ESLintNpm.new(patches) } + let(:patches) { [] } describe '#run' do subject(:run) { eslint.run } @@ -35,6 +36,33 @@ module Pronto it 'has correct first message' do expect(run.first.msg).to eql("'foo' is not defined.") end + + context( + 'with files to lint config that never matches', + config: { files_to_lint: 'will never match' } + ) do + it 'returns zero errors' do + expect(run.count).to eql(0) + end + end + + context( + 'with files to lint config that matches only .js', + config: { files_to_lint: /\.js/ } + ) do + it 'returns correct amount of errors' do + expect(run.count).to eql(2) + end + end + + context( + 'with different eslint executable', + config: { eslint_executable: './custom_eslint.sh' } + ) do + it 'calls the custom eslint eslint_executable' do + expect { run }.to raise_error(JSON::ParserError, /custom eslint called/) + end + end end context 'repo with ignored and not ignored file, each with three warnings' do @@ -52,8 +80,8 @@ module Pronto end end - describe '.files_to_lint' do - subject(:files_to_lint) { ESLintNpm.files_to_lint } + describe '#files_to_lint' do + subject(:files_to_lint) { eslint.files_to_lint } it 'matches .js by default' do expect(files_to_lint).to match('my_js.js') @@ -64,8 +92,8 @@ module Pronto end end - describe '.eslint_executable' do - subject(:eslint_executable) { ESLintNpm.eslint_executable } + describe '#eslint_executable' do + subject(:eslint_executable) { eslint.eslint_executable } it 'is `eslint` by default' do expect(eslint_executable).to eql('eslint') diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 72a128b..da4fc00 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,6 +1,5 @@ require 'fileutils' require 'rspec' -require 'rspec/its' require 'pronto/eslint_npm' %w(test eslintignore).each do |repo_name| @@ -13,3 +12,12 @@ require 'pronto/eslint_npm' after { FileUtils.mv(dot_git, git) } end end + +RSpec.shared_context 'with config', config: true do + requested_config = metadata[:config].to_yaml + + 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) } +end -- cgit v1.2.3