guard-rubocop 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b0043258943e6ce7804f19377ee96f8cb4fbe231
4
- data.tar.gz: 63e9ca25fb5011528c2e86df4b1a98eccfda5e4a
3
+ metadata.gz: 7ee264c2bba19588cd6ec3f4c4cce81a1138d74c
4
+ data.tar.gz: 9b615077842cffb9ac97de41fa79f3904fa42a5e
5
5
  SHA512:
6
- metadata.gz: 292b240599d027edd2125021b55212ae4f0291eaa7d897a4489d2cf8d338c8bb372480a344cc2e468e2f09a2ff941530921a1db8d9e6b66c681c2c30abe3f121
7
- data.tar.gz: 052a46d2a3f6e4a2ba5abb368e0ff6cc91d3cad56bdb21d9e8de14f57a26106420833544c7fd204e7b943143f44c0ea4a242c30e38dfe1005506531be1b9af89
6
+ metadata.gz: 0f501120bc69f42e6be7edae56133788ec314560d31f275f7c41e00be536a61235078a13ee2ab8c016bfe641149a90393e77b75f535add608f6092e4cc3295c9
7
+ data.tar.gz: dec761efcec40969296561f2606ec5e81e3fc2e48807bda3cdda3eac31668cab7cc5082588914851bc2dc78c444567717cfd554a1d075ba346ac9179a70dbbef
data/Gemfile CHANGED
@@ -2,12 +2,8 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- # Travis CI
6
5
  group :test do
7
6
  gem 'coveralls'
8
- end
9
-
10
- # Jenkins
11
- group :ci do
12
7
  gem 'simplecov-rcov', '~> 0.2'
8
+ gem 'ci_reporter', '~> 1.8'
13
9
  end
data/README.md CHANGED
@@ -1,5 +1,4 @@
1
- # Guard::Rubocop [![Build Status](https://travis-ci.org/yujinakayama/guard-rubocop.png?branch=master)](https://travis-ci.org/yujinakayama/guard-rubocop) [![Coverage Status](https://coveralls.io/repos/yujinakayama/guard-rubocop/badge.png?branch=master)](https://coveralls.io/r/yujinakayama/guard-rubocop) [![Dependency Status](https://gemnasium.com/yujinakayama/guard-rubocop.png)](https://gemnasium.com/yujinakayama/guard-rubocop) [![Code Climate](https://codeclimate.com/github/yujinakayama/guard-rubocop.png)](https://codeclimate.com/github/yujinakayama/guard-rubocop)
2
-
1
+ # Guard::Rubocop [![Gem Version](https://badge.fury.io/rb/guard-rubocop.png)](http://badge.fury.io/rb/guard-rubocop) [![Dependency Status](https://gemnasium.com/yujinakayama/guard-rubocop.png)](https://gemnasium.com/yujinakayama/guard-rubocop) [![Build Status](https://travis-ci.org/yujinakayama/guard-rubocop.png?branch=master)](https://travis-ci.org/yujinakayama/guard-rubocop) [![Coverage Status](https://coveralls.io/repos/yujinakayama/guard-rubocop/badge.png?branch=master)](https://coveralls.io/r/yujinakayama/guard-rubocop) [![Code Climate](https://codeclimate.com/github/yujinakayama/guard-rubocop.png)](https://codeclimate.com/github/yujinakayama/guard-rubocop)
3
2
 
4
3
  Guard::Rubocop allows you to automatically check Ruby code style with [RuboCop](https://github.com/bbatsov/rubocop) when files are modified.
5
4
 
data/Rakefile CHANGED
@@ -1 +1,18 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ namespace :ci do
7
+ task :spec do
8
+ ENV['CI'] = 'true'
9
+
10
+ ENV['CI_REPORTS'] = 'spec/reports'
11
+ require 'ci/reporter/rake/rspec'
12
+ Rake::Task['ci:setup:rspec'].invoke
13
+
14
+ Rake::Task['spec'].invoke
15
+ end
16
+ end
17
+
18
+ task :default => :spec
data/lib/guard/rubocop.rb CHANGED
@@ -6,9 +6,7 @@ require 'guard/notifier'
6
6
 
7
7
  module Guard
8
8
  class Rubocop < Guard
9
- # rubocop:disable SymbolSnakeCase
10
- autoload :Runner, 'guard/rubocop/runner'
11
- # rubocop:enable SymbolSnakeCase
9
+ autoload :Runner, 'guard/rubocop/runner' # rubocop:disable SymbolSnakeCase
12
10
 
13
11
  attr_reader :options, :failed_paths
14
12
 
@@ -40,8 +38,7 @@ module Guard
40
38
 
41
39
  def run_on_changes(paths)
42
40
  paths += @failed_paths if @options[:keep_failed]
43
- paths.map! { |path| File.expand_path(path) }
44
- paths.uniq!
41
+ paths = clean_paths(paths)
45
42
 
46
43
  UI.info "Checking Ruby code styles: #{paths.join(' ')}"
47
44
 
@@ -40,20 +40,10 @@ module Guard
40
40
 
41
41
  process.start
42
42
 
43
- ios = [stdout_reader]
44
43
  output = ''
45
44
 
46
45
  loop do
47
- available_ios, = IO.select(ios, nil, nil, MINIMUM_POLL_INTERVAL)
48
-
49
- if available_ios
50
- available_ios.each do |io|
51
- chunk = io.read_available_nonblock
52
- $stdout.write chunk
53
- output << chunk
54
- end
55
- end
56
-
46
+ output << capture_and_print_output(stdout_reader)
57
47
  break if process.exited?
58
48
  end
59
49
 
@@ -62,7 +52,7 @@ module Guard
62
52
 
63
53
  def notify
64
54
  image = passed ? :success : :failed
65
- Notifier.notify(summary, title: 'Rubocop results', image: image)
55
+ Notifier.notify(summary, title: 'RuboCop results', image: image)
66
56
  end
67
57
 
68
58
  def summary
@@ -75,6 +65,16 @@ module Guard
75
65
  output.scan(/^== (.+) ==$/).flatten
76
66
  end
77
67
 
68
+ private
69
+
70
+ def capture_and_print_output(output)
71
+ available_ios, = IO.select([output], nil, nil, MINIMUM_POLL_INTERVAL)
72
+ return '' unless available_ios
73
+ chunk = available_ios.first.read_available_nonblock
74
+ $stdout.write chunk
75
+ chunk
76
+ end
77
+
78
78
  class IO < ::IO
79
79
  READ_CHUNK_SIZE = 10000
80
80
 
@@ -7,7 +7,7 @@ module Guard
7
7
  # http://semver.org/
8
8
  MAJOR = 0
9
9
  MINOR = 0
10
- PATCH = 1
10
+ PATCH = 2
11
11
  VERSION = [MAJOR, MINOR, PATCH].join('.')
12
12
  end
13
13
  end
@@ -128,7 +128,7 @@ describe Guard::Rubocop::Runner, :silence_output do
128
128
  end
129
129
  end
130
130
 
131
- shared_context 'stubbed output', stubbed_output: true do
131
+ shared_context 'stubbed output', :stubbed_output do
132
132
  before do
133
133
  runner.stub(:output) do
134
134
  <<OUTPUT
@@ -143,7 +143,7 @@ OUTPUT
143
143
  end
144
144
  end
145
145
 
146
- describe '#notify', stubbed_output: true do
146
+ describe '#notify', :stubbed_output do
147
147
  it 'notifies summary' do
148
148
  Guard::Notifier.should_receive(:notify) do |message, options|
149
149
  message.should == '7 files inspected, 2 offences detected'
@@ -151,9 +151,9 @@ OUTPUT
151
151
  runner.notify
152
152
  end
153
153
 
154
- it 'notifies with title "Rubocop results"' do
154
+ it 'notifies with title "RuboCop results"' do
155
155
  Guard::Notifier.should_receive(:notify) do |message, options|
156
- options[:title].should == 'Rubocop results'
156
+ options[:title].should == 'RuboCop results'
157
157
  end
158
158
  runner.notify
159
159
  end
@@ -185,7 +185,7 @@ OUTPUT
185
185
  end
186
186
  end
187
187
 
188
- describe '#summary', stubbed_output: true do
188
+ describe '#summary', :stubbed_output do
189
189
  subject { super().summary }
190
190
 
191
191
  it 'returns summary line of output' do
@@ -193,7 +193,7 @@ OUTPUT
193
193
  end
194
194
  end
195
195
 
196
- describe '#failed_paths', stubbed_output: true do
196
+ describe '#failed_paths', :stubbed_output do
197
197
  subject { super().failed_paths }
198
198
 
199
199
  it 'returns failed file paths as array' do
@@ -2,193 +2,191 @@
2
2
 
3
3
  require 'spec_helper.rb'
4
4
 
5
- module Guard
6
- describe Rubocop, :silence_output do
7
- subject(:guard) { Rubocop.new(watchers, options) }
8
- let(:watchers) { [] }
9
- let(:options) { {} }
10
-
11
- let(:runner) { Rubocop::Runner.any_instance }
12
-
13
- describe '#options' do
14
- subject { super().options }
15
-
16
- context 'by default' do
17
- let(:options) { {} }
18
- its([:all_on_start]) { should be_true }
19
- its([:keep_failed]) { should be_true }
20
- its([:notification]) { should == :failed }
21
- end
22
- end
5
+ describe Guard::Rubocop, :silence_output do
6
+ subject(:guard) { Guard::Rubocop.new(watchers, options) }
7
+ let(:watchers) { [] }
8
+ let(:options) { {} }
23
9
 
24
- describe '#start' do
25
- context 'when :all_on_start option is enabled' do
26
- let(:options) { { all_on_start: true } }
27
-
28
- it 'runs all' do
29
- guard.should_receive(:run_all)
30
- guard.start
31
- end
32
- end
10
+ let(:runner) { Guard::Rubocop::Runner.any_instance }
33
11
 
34
- context 'when :all_on_start option is disabled' do
35
- let(:options) { { all_on_start: false } }
12
+ describe '#options' do
13
+ subject { super().options }
36
14
 
37
- it 'does nothing' do
38
- guard.should_not_receive(:run_all)
39
- guard.start
40
- end
41
- end
15
+ context 'by default' do
16
+ let(:options) { {} }
17
+ its([:all_on_start]) { should be_true }
18
+ its([:keep_failed]) { should be_true }
19
+ its([:notification]) { should == :failed }
42
20
  end
21
+ end
43
22
 
44
- shared_examples 'processes after running', :processes_after_running do
45
- context 'when passed' do
46
- it 'throws nothing' do
47
- runner.stub(:run).and_return(true)
48
- expect { subject }.not_to throw_symbol
49
- end
23
+ describe '#start' do
24
+ context 'when :all_on_start option is enabled' do
25
+ let(:options) { { all_on_start: true } }
50
26
 
51
- it 'clears failed paths' do
52
- runner.stub(:run).and_return(true)
53
- runner.stub(:failed_paths).and_return([])
54
- subject
55
- guard.failed_paths.should be_empty
56
- end
27
+ it 'runs all' do
28
+ guard.should_receive(:run_all)
29
+ guard.start
57
30
  end
31
+ end
58
32
 
59
- context 'when failed' do
60
- it 'throws symbol :task_has_failed' do
61
- runner.stub(:run).and_return(false)
62
- expect { subject }.to throw_symbol(:task_has_failed)
63
- end
33
+ context 'when :all_on_start option is disabled' do
34
+ let(:options) { { all_on_start: false } }
64
35
 
65
- it 'keeps failed paths' do
66
- guard.stub(:throw)
67
- failed_paths = [
68
- 'some_failed_file.rb',
69
- 'dir/another_failed_file.rb'
70
- ]
71
- runner.stub(:run).and_return(false)
72
- runner.stub(:failed_paths).and_return(failed_paths)
73
- subject
74
- guard.failed_paths.should == failed_paths
75
- end
36
+ it 'does nothing' do
37
+ guard.should_not_receive(:run_all)
38
+ guard.start
76
39
  end
77
40
  end
41
+ end
78
42
 
79
- describe '#run_all', :processes_after_running do
80
- subject { super().run_all }
81
-
82
- before do
43
+ shared_examples 'processes after running', :processes_after_running do
44
+ context 'when passed' do
45
+ it 'throws nothing' do
83
46
  runner.stub(:run).and_return(true)
47
+ expect { subject }.not_to throw_symbol
84
48
  end
85
49
 
86
- it 'inspects all files with rubocop' do
87
- runner.should_receive(:run).with(no_args)
88
- guard.run_all
50
+ it 'clears failed paths' do
51
+ runner.stub(:run).and_return(true)
52
+ runner.stub(:failed_paths).and_return([])
53
+ subject
54
+ guard.failed_paths.should be_empty
89
55
  end
90
56
  end
91
57
 
92
- describe '#run_on_changes', :processes_after_running do
93
- subject { super().run_on_changes(changed_paths) }
94
- let(:changed_paths) { ['some.rb', 'dir/another.rb', 'dir/../some.rb'] }
95
-
96
- before do
97
- runner.stub(:run).and_return(true)
58
+ context 'when failed' do
59
+ it 'throws symbol :task_has_failed' do
60
+ runner.stub(:run).and_return(false)
61
+ expect { subject }.to throw_symbol(:task_has_failed)
98
62
  end
99
63
 
100
- it 'inspects changed files with rubocop' do
101
- runner.should_receive(:run)
102
- guard.run_on_changes(changed_paths)
64
+ it 'keeps failed paths' do
65
+ guard.stub(:throw)
66
+ failed_paths = [
67
+ 'some_failed_file.rb',
68
+ 'dir/another_failed_file.rb'
69
+ ]
70
+ runner.stub(:run).and_return(false)
71
+ runner.stub(:failed_paths).and_return(failed_paths)
72
+ subject
73
+ guard.failed_paths.should == failed_paths
103
74
  end
75
+ end
76
+ end
104
77
 
105
- it 'passes cleaned paths to rubocop' do
106
- runner.should_receive(:run) do |paths|
107
- paths.should == [
108
- File.expand_path('some.rb'),
109
- File.expand_path('dir/another.rb')
110
- ]
111
- end
112
- guard.run_on_changes(changed_paths)
113
- end
78
+ describe '#run_all', :processes_after_running do
79
+ subject { super().run_all }
114
80
 
115
- let(:failed_path) { File.expand_path('failed_file_last_time.rb') }
81
+ before do
82
+ runner.stub(:run).and_return(true)
83
+ end
116
84
 
117
- context 'when :keep_failed option is enabled' do
118
- let(:options) { { keep_failed: true } }
85
+ it 'inspects all files with rubocop' do
86
+ runner.should_receive(:run).with(no_args)
87
+ guard.run_all
88
+ end
89
+ end
119
90
 
120
- it 'also inspects paths which are failed last time' do
121
- guard.failed_paths << failed_path
122
- runner.should_receive(:run) do |paths|
123
- paths.should include failed_path
124
- end
125
- guard.run_on_changes(changed_paths)
126
- end
127
- end
91
+ describe '#run_on_changes', :processes_after_running do
92
+ subject { super().run_on_changes(changed_paths) }
93
+ let(:changed_paths) { ['some.rb', 'dir/another.rb', 'dir/../some.rb'] }
128
94
 
129
- context 'when :keep_failed option is disabled' do
130
- let(:options) { { keep_failed: false } }
131
- let(:changed_paths) do
132
- [
133
- File.expand_path('some.rb'),
134
- File.expand_path('dir/another.rb')
135
- ]
136
- end
95
+ before do
96
+ runner.stub(:run).and_return(true)
97
+ end
137
98
 
138
- it 'inspects just changed paths' do
139
- guard.failed_paths << failed_path
140
- runner.should_receive(:run) do |paths|
141
- paths.should == changed_paths
142
- end
143
- guard.run_on_changes(changed_paths)
144
- end
145
- end
99
+ it 'inspects changed files with rubocop' do
100
+ runner.should_receive(:run)
101
+ guard.run_on_changes(changed_paths)
146
102
  end
147
103
 
148
- describe '#reload' do
149
- it 'clears failed paths' do
150
- guard.failed_paths << 'failed.rb'
151
- guard.reload
152
- guard.failed_paths.should be_empty
104
+ it 'passes cleaned paths to rubocop' do
105
+ runner.should_receive(:run) do |paths|
106
+ paths.should == [
107
+ File.expand_path('some.rb'),
108
+ File.expand_path('dir/another.rb')
109
+ ]
153
110
  end
111
+ guard.run_on_changes(changed_paths)
154
112
  end
155
113
 
156
- describe '#clean_paths' do
157
- it 'converts to absolute paths' do
158
- paths = [
159
- 'lib/guard/rubocop.rb',
160
- 'spec/spec_helper.rb'
161
- ]
162
- guard.clean_paths(paths).should == [
163
- File.expand_path('lib/guard/rubocop.rb'),
164
- File.expand_path('spec/spec_helper.rb')
165
- ]
114
+ let(:failed_path) { File.expand_path('failed_file_last_time.rb') }
115
+
116
+ context 'when :keep_failed option is enabled' do
117
+ let(:options) { { keep_failed: true } }
118
+
119
+ it 'also inspects paths which are failed last time' do
120
+ guard.failed_paths << failed_path
121
+ runner.should_receive(:run) do |paths|
122
+ paths.should include failed_path
123
+ end
124
+ guard.run_on_changes(changed_paths)
166
125
  end
126
+ end
167
127
 
168
- it 'removes to duplicated paths' do
169
- paths = [
170
- 'lib/guard/rubocop.rb',
171
- 'spec/spec_helper.rb',
172
- 'lib/guard/../guard/rubocop.rb'
173
- ]
174
- guard.clean_paths(paths).should == [
175
- File.expand_path('lib/guard/rubocop.rb'),
176
- File.expand_path('spec/spec_helper.rb')
128
+ context 'when :keep_failed option is disabled' do
129
+ let(:options) { { keep_failed: false } }
130
+ let(:changed_paths) do
131
+ [
132
+ File.expand_path('some.rb'),
133
+ File.expand_path('dir/another.rb')
177
134
  ]
178
135
  end
179
136
 
180
- it 'removes paths which are included in another path' do
181
- paths = [
182
- 'lib/guard/rubocop.rb',
183
- 'spec/spec_helper.rb',
184
- 'spec'
185
- ]
186
- guard.clean_paths(paths).should == [
187
- File.expand_path('lib/guard/rubocop.rb'),
188
- File.expand_path('spec')
189
- ]
137
+ it 'inspects just changed paths' do
138
+ guard.failed_paths << failed_path
139
+ runner.should_receive(:run) do |paths|
140
+ paths.should == changed_paths
141
+ end
142
+ guard.run_on_changes(changed_paths)
190
143
  end
191
144
  end
145
+ end
146
+
147
+ describe '#reload' do
148
+ it 'clears failed paths' do
149
+ guard.failed_paths << 'failed.rb'
150
+ guard.reload
151
+ guard.failed_paths.should be_empty
152
+ end
153
+ end
154
+
155
+ describe '#clean_paths' do
156
+ it 'converts to absolute paths' do
157
+ paths = [
158
+ 'lib/guard/rubocop.rb',
159
+ 'spec/spec_helper.rb'
160
+ ]
161
+ guard.clean_paths(paths).should == [
162
+ File.expand_path('lib/guard/rubocop.rb'),
163
+ File.expand_path('spec/spec_helper.rb')
164
+ ]
165
+ end
192
166
 
167
+ it 'removes duplicated paths' do
168
+ paths = [
169
+ 'lib/guard/rubocop.rb',
170
+ 'spec/spec_helper.rb',
171
+ 'lib/guard/../guard/rubocop.rb'
172
+ ]
173
+ guard.clean_paths(paths).should == [
174
+ File.expand_path('lib/guard/rubocop.rb'),
175
+ File.expand_path('spec/spec_helper.rb')
176
+ ]
177
+ end
178
+
179
+ it 'removes paths which are included in another path' do
180
+ paths = [
181
+ 'lib/guard/rubocop.rb',
182
+ 'spec/spec_helper.rb',
183
+ 'spec'
184
+ ]
185
+ guard.clean_paths(paths).should == [
186
+ File.expand_path('lib/guard/rubocop.rb'),
187
+ File.expand_path('spec')
188
+ ]
189
+ end
193
190
  end
191
+
194
192
  end
data/spec/spec_helper.rb CHANGED
@@ -1,27 +1,7 @@
1
1
  # coding: utf-8
2
2
 
3
- class NoExpectationExecutedError < StandardError
4
- end
5
-
6
3
  RSpec.configure do |config|
7
4
  config.treat_symbols_as_metadata_keys_with_true_values = true
8
-
9
- # Original snippet by sorah
10
- # https://gist.github.com/sorah/4315150
11
- config.after do
12
- result = self.example.metadata[:execution_result]
13
-
14
- has_mock_expectations = !RSpec::Mocks.space.instance_eval do
15
- receivers
16
- end.empty?
17
-
18
- next if result[:exception]
19
- next if result[:pending_message]
20
- next if RSpec::Matchers.last_should
21
- next if has_mock_expectations
22
-
23
- fail NoExpectationExecutedError
24
- end
25
5
  end
26
6
 
27
7
  Dir[File.join(File.dirname(__FILE__), 'support', '*')].each do |path|
@@ -33,7 +13,7 @@ SimpleCov.coverage_dir(File.join('spec', 'coverage'))
33
13
 
34
14
  if ENV['TRAVIS']
35
15
  require 'coveralls'
36
- Coveralls.wear!
16
+ SimpleCov.formatter = Coveralls::SimpleCov::Formatter
37
17
  elsif ENV['CI']
38
18
  require 'simplecov-rcov'
39
19
  SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guard-rubocop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuji Nakayama
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-20 00:00:00.000000000 Z
11
+ date: 2013-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: guard
@@ -166,7 +166,6 @@ files:
166
166
  - README.md
167
167
  - Rakefile
168
168
  - guard-rubocop.gemspec
169
- - lib/guard/.rubocop.yml
170
169
  - lib/guard/rubocop.rb
171
170
  - lib/guard/rubocop/runner.rb
172
171
  - lib/guard/rubocop/templates/Guardfile
@@ -175,7 +174,6 @@ files:
175
174
  - spec/guard/rubocop/runner_spec.rb
176
175
  - spec/guard/rubocop_spec.rb
177
176
  - spec/spec_helper.rb
178
- - spec/support/.rubocop.yml
179
177
  - spec/support/capture_helper.rb
180
178
  - spec/support/silence_output.rb
181
179
  homepage: https://github.com/yujinakayama/guard-rubocop
@@ -207,6 +205,6 @@ test_files:
207
205
  - spec/guard/rubocop/runner_spec.rb
208
206
  - spec/guard/rubocop_spec.rb
209
207
  - spec/spec_helper.rb
210
- - spec/support/.rubocop.yml
211
208
  - spec/support/capture_helper.rb
212
209
  - spec/support/silence_output.rb
210
+ has_rdoc:
@@ -1,4 +0,0 @@
1
- # A workaround for `autoload :Runner` in rubocop.rb
2
- # until comment based switch will be released
3
- SymbolSnakeCase:
4
- Enabled: false
@@ -1,2 +0,0 @@
1
- Syntax:
2
- Enabled: false