diff options
Diffstat (limited to 'spec')
-rwxr-xr-x | spec/fixtures/test.git/custom_eslint.sh | 1 | ||||
-rw-r--r-- | spec/pronto/eslint_spec.rb | 36 | ||||
-rw-r--r-- | spec/spec_helper.rb | 10 |
3 files changed, 42 insertions, 5 deletions
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' | |||
3 | module Pronto | 3 | module Pronto |
4 | describe ESLintNpm do | 4 | describe ESLintNpm do |
5 | let(:eslint) { ESLintNpm.new(patches) } | 5 | let(:eslint) { ESLintNpm.new(patches) } |
6 | let(:patches) { [] } | ||
6 | 7 | ||
7 | describe '#run' do | 8 | describe '#run' do |
8 | subject(:run) { eslint.run } | 9 | subject(:run) { eslint.run } |
@@ -35,6 +36,33 @@ module Pronto | |||
35 | it 'has correct first message' do | 36 | it 'has correct first message' do |
36 | expect(run.first.msg).to eql("'foo' is not defined.") | 37 | expect(run.first.msg).to eql("'foo' is not defined.") |
37 | end | 38 | end |
39 | |||
40 | context( | ||
41 | 'with files to lint config that never matches', | ||
42 | config: { files_to_lint: 'will never match' } | ||
43 | ) do | ||
44 | it 'returns zero errors' do | ||
45 | expect(run.count).to eql(0) | ||
46 | end | ||
47 | end | ||
48 | |||
49 | context( | ||
50 | 'with files to lint config that matches only .js', | ||
51 | config: { files_to_lint: /\.js/ } | ||
52 | ) do | ||
53 | it 'returns correct amount of errors' do | ||
54 | expect(run.count).to eql(2) | ||
55 | end | ||
56 | end | ||
57 | |||
58 | context( | ||
59 | 'with different eslint executable', | ||
60 | config: { eslint_executable: './custom_eslint.sh' } | ||
61 | ) do | ||
62 | it 'calls the custom eslint eslint_executable' do | ||
63 | expect { run }.to raise_error(JSON::ParserError, /custom eslint called/) | ||
64 | end | ||
65 | end | ||
38 | end | 66 | end |
39 | 67 | ||
40 | context 'repo with ignored and not ignored file, each with three warnings' do | 68 | context 'repo with ignored and not ignored file, each with three warnings' do |
@@ -52,8 +80,8 @@ module Pronto | |||
52 | end | 80 | end |
53 | end | 81 | end |
54 | 82 | ||
55 | describe '.files_to_lint' do | 83 | describe '#files_to_lint' do |
56 | subject(:files_to_lint) { ESLintNpm.files_to_lint } | 84 | subject(:files_to_lint) { eslint.files_to_lint } |
57 | 85 | ||
58 | it 'matches .js by default' do | 86 | it 'matches .js by default' do |
59 | expect(files_to_lint).to match('my_js.js') | 87 | expect(files_to_lint).to match('my_js.js') |
@@ -64,8 +92,8 @@ module Pronto | |||
64 | end | 92 | end |
65 | end | 93 | end |
66 | 94 | ||
67 | describe '.eslint_executable' do | 95 | describe '#eslint_executable' do |
68 | subject(:eslint_executable) { ESLintNpm.eslint_executable } | 96 | subject(:eslint_executable) { eslint.eslint_executable } |
69 | 97 | ||
70 | it 'is `eslint` by default' do | 98 | it 'is `eslint` by default' do |
71 | expect(eslint_executable).to eql('eslint') | 99 | 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 @@ | |||
1 | require 'fileutils' | 1 | require 'fileutils' |
2 | require 'rspec' | 2 | require 'rspec' |
3 | require 'rspec/its' | ||
4 | require 'pronto/eslint_npm' | 3 | require 'pronto/eslint_npm' |
5 | 4 | ||
6 | %w(test eslintignore).each do |repo_name| | 5 | %w(test eslintignore).each do |repo_name| |
@@ -13,3 +12,12 @@ require 'pronto/eslint_npm' | |||
13 | after { FileUtils.mv(dot_git, git) } | 12 | after { FileUtils.mv(dot_git, git) } |
14 | end | 13 | end |
15 | end | 14 | end |
15 | |||
16 | RSpec.shared_context 'with config', config: true do | ||
17 | requested_config = metadata[:config].to_yaml | ||
18 | |||
19 | let(:config_path) { File.join(repo.path.to_s, Pronto::ESLintNpm::CONFIG_FILE) } | ||
20 | |||
21 | before(:each) { File.write(config_path, requested_config) } | ||
22 | after(:each) { FileUtils.rm(config_path) } | ||
23 | end | ||