guard-rubocop 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.travis.yml +5 -0
- data/Gemfile +13 -0
- data/Guardfile +14 -0
- data/LICENSE.txt +22 -0
- data/README.md +70 -0
- data/Rakefile +1 -0
- data/guard-rubocop.gemspec +34 -0
- data/lib/guard/.rubocop.yml +4 -0
- data/lib/guard/rubocop.rb +79 -0
- data/lib/guard/rubocop/runner.rb +95 -0
- data/lib/guard/rubocop/templates/Guardfile +4 -0
- data/lib/guard/rubocop/version.rb +13 -0
- data/spec/.rubocop.yml +4 -0
- data/spec/guard/rubocop/runner_spec.rb +207 -0
- data/spec/guard/rubocop_spec.rb +194 -0
- data/spec/spec_helper.rb +47 -0
- data/spec/support/.rubocop.yml +2 -0
- data/spec/support/capture_helper.rb +18 -0
- data/spec/support/silence_output.rb +18 -0
- metadata +212 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b0043258943e6ce7804f19377ee96f8cb4fbe231
|
4
|
+
data.tar.gz: 63e9ca25fb5011528c2e86df4b1a98eccfda5e4a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 292b240599d027edd2125021b55212ae4f0291eaa7d897a4489d2cf8d338c8bb372480a344cc2e468e2f09a2ff941530921a1db8d9e6b66c681c2c30abe3f121
|
7
|
+
data.tar.gz: 052a46d2a3f6e4a2ba5abb368e0ff6cc91d3cad56bdb21d9e8de14f57a26106420833544c7fd204e7b943143f44c0ea4a242c30e38dfe1005506531be1b9af89
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard 'rspec' do
|
5
|
+
watch(%r{^spec/.+_spec\.rb$})
|
6
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
7
|
+
watch('spec/spec_helper.rb') { "spec" }
|
8
|
+
watch(%r{^spec/support/.+\.rb$}) { "spec" }
|
9
|
+
end
|
10
|
+
|
11
|
+
guard 'rubocop' do
|
12
|
+
watch(%r{.+\.rb$})
|
13
|
+
watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
|
14
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Yuji Nakayama
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# Guard::Rubocop [](https://travis-ci.org/yujinakayama/guard-rubocop) [](https://coveralls.io/r/yujinakayama/guard-rubocop) [](https://gemnasium.com/yujinakayama/guard-rubocop) [](https://codeclimate.com/github/yujinakayama/guard-rubocop)
|
2
|
+
|
3
|
+
|
4
|
+
Guard::Rubocop allows you to automatically check Ruby code style with [RuboCop](https://github.com/bbatsov/rubocop) when files are modified.
|
5
|
+
|
6
|
+
Tested on MRI 1.9 and MRI 2.0, according to RuboCop.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Please make sure to have [Guard](https://github.com/guard/guard) installed before continue.
|
11
|
+
|
12
|
+
Add `guard-rubocop` to your `Gemfile`:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
group :development do
|
16
|
+
gem 'guard-rubocop'
|
17
|
+
end
|
18
|
+
```
|
19
|
+
|
20
|
+
and then execute:
|
21
|
+
|
22
|
+
```sh
|
23
|
+
$ bundle install
|
24
|
+
```
|
25
|
+
|
26
|
+
or install it yourself as:
|
27
|
+
|
28
|
+
```sh
|
29
|
+
$ gem install guard-rubocop
|
30
|
+
```
|
31
|
+
|
32
|
+
Add the default Guard::Rubocop definition to your `Guardfile` by running:
|
33
|
+
|
34
|
+
```sh
|
35
|
+
$ guard init rubocop
|
36
|
+
```
|
37
|
+
|
38
|
+
## Usage
|
39
|
+
|
40
|
+
Please read the [Guard usage documentation](https://github.com/guard/guard#readme).
|
41
|
+
|
42
|
+
## Options
|
43
|
+
|
44
|
+
You can pass some options in `Guardfile`:
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
guard 'rubocop', all_on_start: false, notification: true do
|
48
|
+
# ...
|
49
|
+
end
|
50
|
+
```
|
51
|
+
|
52
|
+
### Available Options
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
all_on_start: true # Check all files at Guard startup, default: true
|
56
|
+
keep_failed: true # Keep failed files until they pass, default: true
|
57
|
+
notification: :failed # Display Growl notification after each run
|
58
|
+
# true - Always notify
|
59
|
+
# false - Never notify
|
60
|
+
# :failed - Notify only when failed
|
61
|
+
# default: :failed
|
62
|
+
```
|
63
|
+
|
64
|
+
## Contributing
|
65
|
+
|
66
|
+
1. Fork it
|
67
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
68
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
69
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
70
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
require 'guard/rubocop/version'
|
7
|
+
|
8
|
+
Gem::Specification.new do |spec|
|
9
|
+
spec.name = "guard-rubocop"
|
10
|
+
spec.version = Guard::RubocopVersion::VERSION
|
11
|
+
spec.authors = ["Yuji Nakayama"]
|
12
|
+
spec.email = ["nkymyj@gmail.com"]
|
13
|
+
spec.summary = "Guard plugin for RuboCop"
|
14
|
+
spec.description = "Guard::Rubocop allows you to automatically check Ruby code style with RuboCop when files are modified."
|
15
|
+
spec.homepage = "https://github.com/yujinakayama/guard-rubocop"
|
16
|
+
spec.license = "MIT"
|
17
|
+
|
18
|
+
spec.files = `git ls-files`.split($/)
|
19
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_runtime_dependency "guard", "~> 1.8"
|
24
|
+
spec.add_runtime_dependency "rubocop", "~> 0.5"
|
25
|
+
spec.add_runtime_dependency "childprocess", "~> 0.3"
|
26
|
+
spec.add_runtime_dependency "term-ansicolor", "~> 1.1"
|
27
|
+
|
28
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
29
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
30
|
+
spec.add_development_dependency "rspec", "~> 2.13"
|
31
|
+
spec.add_development_dependency "simplecov", "~> 0.7"
|
32
|
+
spec.add_development_dependency "guard-rspec", ">= 2.5.4"
|
33
|
+
spec.add_development_dependency "ruby_gntp", ">= 0.3"
|
34
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'guard'
|
4
|
+
require 'guard/guard'
|
5
|
+
require 'guard/notifier'
|
6
|
+
|
7
|
+
module Guard
|
8
|
+
class Rubocop < Guard
|
9
|
+
# rubocop:disable SymbolSnakeCase
|
10
|
+
autoload :Runner, 'guard/rubocop/runner'
|
11
|
+
# rubocop:enable SymbolSnakeCase
|
12
|
+
|
13
|
+
attr_reader :options, :failed_paths
|
14
|
+
|
15
|
+
def initialize(watchers = [], options = {})
|
16
|
+
super
|
17
|
+
|
18
|
+
@options = {
|
19
|
+
all_on_start: true,
|
20
|
+
keep_failed: true,
|
21
|
+
notification: :failed
|
22
|
+
}.merge(options)
|
23
|
+
|
24
|
+
@failed_paths = []
|
25
|
+
end
|
26
|
+
|
27
|
+
def start
|
28
|
+
run_all if @options[:all_on_start]
|
29
|
+
end
|
30
|
+
|
31
|
+
def run_all
|
32
|
+
UI.info 'Checking Ruby code style of all files'
|
33
|
+
|
34
|
+
runner = Runner.new(@options)
|
35
|
+
passed = runner.run
|
36
|
+
@failed_paths = runner.failed_paths
|
37
|
+
|
38
|
+
throw :task_has_failed unless passed
|
39
|
+
end
|
40
|
+
|
41
|
+
def run_on_changes(paths)
|
42
|
+
paths += @failed_paths if @options[:keep_failed]
|
43
|
+
paths.map! { |path| File.expand_path(path) }
|
44
|
+
paths.uniq!
|
45
|
+
|
46
|
+
UI.info "Checking Ruby code styles: #{paths.join(' ')}"
|
47
|
+
|
48
|
+
runner = Runner.new(@options)
|
49
|
+
passed = runner.run(paths)
|
50
|
+
@failed_paths = runner.failed_paths
|
51
|
+
|
52
|
+
throw :task_has_failed unless passed
|
53
|
+
end
|
54
|
+
|
55
|
+
def reload
|
56
|
+
@failed_paths = []
|
57
|
+
end
|
58
|
+
|
59
|
+
def clean_paths(paths)
|
60
|
+
paths = paths.dup
|
61
|
+
paths.map! { |path| File.expand_path(path) }
|
62
|
+
paths.uniq!
|
63
|
+
paths.reject! do |path|
|
64
|
+
included_in_other_path?(path, paths)
|
65
|
+
end
|
66
|
+
paths
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def included_in_other_path?(target_path, other_paths)
|
72
|
+
dir_paths = other_paths.select { |path| File.directory?(path) }
|
73
|
+
dir_paths.delete(target_path)
|
74
|
+
dir_paths.any? do |dir_path|
|
75
|
+
target_path.start_with?(dir_path)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'childprocess'
|
4
|
+
require 'term/ansicolor'
|
5
|
+
|
6
|
+
module Guard
|
7
|
+
class Rubocop
|
8
|
+
class Runner
|
9
|
+
PASSED_EXIT_CODE = 0
|
10
|
+
MINIMUM_POLL_INTERVAL = 0.1
|
11
|
+
|
12
|
+
attr_reader :passed, :output
|
13
|
+
|
14
|
+
alias_method :passed?, :passed
|
15
|
+
|
16
|
+
def initialize(options)
|
17
|
+
@options = options
|
18
|
+
end
|
19
|
+
|
20
|
+
def run(paths = [])
|
21
|
+
exit_code, output = rubocop(paths)
|
22
|
+
@passed = (exit_code == PASSED_EXIT_CODE)
|
23
|
+
@output = Term::ANSIColor.uncolor(output)
|
24
|
+
|
25
|
+
case @options[:notification]
|
26
|
+
when :failed
|
27
|
+
notify unless passed?
|
28
|
+
when true
|
29
|
+
notify
|
30
|
+
end
|
31
|
+
|
32
|
+
passed
|
33
|
+
end
|
34
|
+
|
35
|
+
def rubocop(args)
|
36
|
+
process = ChildProcess.build('rubocop', *args)
|
37
|
+
|
38
|
+
stdout_reader, stdout_writer = IO.pipe
|
39
|
+
process.io.stdout = stdout_writer
|
40
|
+
|
41
|
+
process.start
|
42
|
+
|
43
|
+
ios = [stdout_reader]
|
44
|
+
output = ''
|
45
|
+
|
46
|
+
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
|
+
|
57
|
+
break if process.exited?
|
58
|
+
end
|
59
|
+
|
60
|
+
[process.exit_code, output]
|
61
|
+
end
|
62
|
+
|
63
|
+
def notify
|
64
|
+
image = passed ? :success : :failed
|
65
|
+
Notifier.notify(summary, title: 'Rubocop results', image: image)
|
66
|
+
end
|
67
|
+
|
68
|
+
def summary
|
69
|
+
return nil unless output
|
70
|
+
output.lines.to_a.last.chomp
|
71
|
+
end
|
72
|
+
|
73
|
+
def failed_paths
|
74
|
+
return [] unless output
|
75
|
+
output.scan(/^== (.+) ==$/).flatten
|
76
|
+
end
|
77
|
+
|
78
|
+
class IO < ::IO
|
79
|
+
READ_CHUNK_SIZE = 10000
|
80
|
+
|
81
|
+
def read_available_nonblock
|
82
|
+
data = ''
|
83
|
+
loop do
|
84
|
+
begin
|
85
|
+
data << read_nonblock(READ_CHUNK_SIZE)
|
86
|
+
rescue ::IO::WaitReadable, EOFError
|
87
|
+
return data
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module Guard
|
4
|
+
# A workaround for declaring `class Rubocop`
|
5
|
+
# before `class Rubocop < Guard` in rubocop.rb
|
6
|
+
module RubocopVersion
|
7
|
+
# http://semver.org/
|
8
|
+
MAJOR = 0
|
9
|
+
MINOR = 0
|
10
|
+
PATCH = 1
|
11
|
+
VERSION = [MAJOR, MINOR, PATCH].join('.')
|
12
|
+
end
|
13
|
+
end
|
data/spec/.rubocop.yml
ADDED
@@ -0,0 +1,207 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper.rb'
|
4
|
+
require 'term/ansicolor'
|
5
|
+
|
6
|
+
describe Guard::Rubocop::Runner, :silence_output do
|
7
|
+
include CaptureHelper
|
8
|
+
|
9
|
+
subject(:runner) { Guard::Rubocop::Runner.new(options) }
|
10
|
+
let(:options) { {} }
|
11
|
+
|
12
|
+
describe '#run' do
|
13
|
+
subject { super().run(paths) }
|
14
|
+
let(:paths) { ['spec/spec_helper.rb'] }
|
15
|
+
|
16
|
+
before do
|
17
|
+
runner.stub(:rubocop)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'executes rubocop' do
|
21
|
+
runner.should_receive(:rubocop)
|
22
|
+
runner.run
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'when all files are passed' do
|
26
|
+
before do
|
27
|
+
runner.stub(:rubocop).and_return(0)
|
28
|
+
end
|
29
|
+
it { should be_true }
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'when any file is failed' do
|
33
|
+
before do
|
34
|
+
runner.stub(:rubocop).and_return(1)
|
35
|
+
end
|
36
|
+
it { should be_false }
|
37
|
+
end
|
38
|
+
|
39
|
+
shared_examples 'notifies', :notifies do
|
40
|
+
it 'notifies' do
|
41
|
+
runner.should_receive(:notify)
|
42
|
+
runner.run
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
shared_examples 'does not notify', :does_not_notify do
|
47
|
+
it 'does not notify' do
|
48
|
+
runner.should_not_receive(:notify)
|
49
|
+
runner.run
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
shared_examples 'notification' do |expectations|
|
54
|
+
context 'when passed' do
|
55
|
+
before do
|
56
|
+
runner.stub(:rubocop).and_return(0)
|
57
|
+
end
|
58
|
+
|
59
|
+
if expectations[:passed]
|
60
|
+
include_examples 'notifies'
|
61
|
+
else
|
62
|
+
include_examples 'does not notify'
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'when failed' do
|
67
|
+
before do
|
68
|
+
runner.stub(:rubocop).and_return(1)
|
69
|
+
end
|
70
|
+
|
71
|
+
if expectations[:failed]
|
72
|
+
include_examples 'notifies'
|
73
|
+
else
|
74
|
+
include_examples 'does not notify'
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context 'when :notification option is true' do
|
80
|
+
let(:options) { { notification: true } }
|
81
|
+
include_examples 'notification', { passed: true, failed: true }
|
82
|
+
end
|
83
|
+
|
84
|
+
context 'when :notification option is :failed' do
|
85
|
+
let(:options) { { notification: :failed } }
|
86
|
+
include_examples 'notification', { passed: false, failed: true }
|
87
|
+
end
|
88
|
+
|
89
|
+
context 'when :notification option is false' do
|
90
|
+
let(:options) { { notification: false } }
|
91
|
+
include_examples 'notification', { passed: false, failed: false }
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe '#rubocop' do
|
96
|
+
let(:paths) { ['spec/spec_helper.rb'] }
|
97
|
+
|
98
|
+
it 'runs rubocop command' do
|
99
|
+
capture(:stdout) do
|
100
|
+
runner.rubocop(paths)
|
101
|
+
end.should include 'inspected'
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'returns exit code and output' do
|
105
|
+
exit_code, output = runner.rubocop(paths)
|
106
|
+
exit_code.should == 0
|
107
|
+
output.should include 'inspected'
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
describe '#output' do
|
112
|
+
subject { super().output }
|
113
|
+
let(:paths) { ['spec/spec_helper.rb'] }
|
114
|
+
|
115
|
+
context 'before running' do
|
116
|
+
it { should be_nil }
|
117
|
+
end
|
118
|
+
|
119
|
+
context 'after running' do
|
120
|
+
before do
|
121
|
+
runner.stub(:notify)
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'returns uncolored output of rubocop command' do
|
125
|
+
captured_output = capture(:stdout) { runner.run(paths) }
|
126
|
+
runner.output.should == Term::ANSIColor.uncolor(captured_output)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
shared_context 'stubbed output', stubbed_output: true do
|
132
|
+
before do
|
133
|
+
runner.stub(:output) do
|
134
|
+
<<OUTPUT
|
135
|
+
== /home/foo/guard-rubocop/lib/guard/rubocop.rb ==
|
136
|
+
C: 1: Missing encoding comment.
|
137
|
+
== /home/foo/guard-rubocop/spec/support/silence_output.rb ==
|
138
|
+
C: 3: Ruby 1.8 hash syntax detected
|
139
|
+
|
140
|
+
7 files inspected, 2 offences detected
|
141
|
+
OUTPUT
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
describe '#notify', stubbed_output: true do
|
147
|
+
it 'notifies summary' do
|
148
|
+
Guard::Notifier.should_receive(:notify) do |message, options|
|
149
|
+
message.should == '7 files inspected, 2 offences detected'
|
150
|
+
end
|
151
|
+
runner.notify
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'notifies with title "Rubocop results"' do
|
155
|
+
Guard::Notifier.should_receive(:notify) do |message, options|
|
156
|
+
options[:title].should == 'Rubocop results'
|
157
|
+
end
|
158
|
+
runner.notify
|
159
|
+
end
|
160
|
+
|
161
|
+
context 'when passed' do
|
162
|
+
before do
|
163
|
+
runner.stub(:passed).and_return(true)
|
164
|
+
end
|
165
|
+
|
166
|
+
it 'shows success image' do
|
167
|
+
Guard::Notifier.should_receive(:notify) do |message, options|
|
168
|
+
options[:image].should == :success
|
169
|
+
end
|
170
|
+
runner.notify
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
context 'when failed' do
|
175
|
+
before do
|
176
|
+
runner.stub(:passed).and_return(false)
|
177
|
+
end
|
178
|
+
|
179
|
+
it 'shows failed image' do
|
180
|
+
Guard::Notifier.should_receive(:notify) do |message, options|
|
181
|
+
options[:image].should == :failed
|
182
|
+
end
|
183
|
+
runner.notify
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
describe '#summary', stubbed_output: true do
|
189
|
+
subject { super().summary }
|
190
|
+
|
191
|
+
it 'returns summary line of output' do
|
192
|
+
should == '7 files inspected, 2 offences detected'
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
describe '#failed_paths', stubbed_output: true do
|
197
|
+
subject { super().failed_paths }
|
198
|
+
|
199
|
+
it 'returns failed file paths as array' do
|
200
|
+
should == [
|
201
|
+
'/home/foo/guard-rubocop/lib/guard/rubocop.rb',
|
202
|
+
'/home/foo/guard-rubocop/spec/support/silence_output.rb'
|
203
|
+
]
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
end
|
@@ -0,0 +1,194 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper.rb'
|
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
|
23
|
+
|
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
|
33
|
+
|
34
|
+
context 'when :all_on_start option is disabled' do
|
35
|
+
let(:options) { { all_on_start: false } }
|
36
|
+
|
37
|
+
it 'does nothing' do
|
38
|
+
guard.should_not_receive(:run_all)
|
39
|
+
guard.start
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
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
|
50
|
+
|
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
|
57
|
+
end
|
58
|
+
|
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
|
64
|
+
|
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
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe '#run_all', :processes_after_running do
|
80
|
+
subject { super().run_all }
|
81
|
+
|
82
|
+
before do
|
83
|
+
runner.stub(:run).and_return(true)
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'inspects all files with rubocop' do
|
87
|
+
runner.should_receive(:run).with(no_args)
|
88
|
+
guard.run_all
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
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)
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'inspects changed files with rubocop' do
|
101
|
+
runner.should_receive(:run)
|
102
|
+
guard.run_on_changes(changed_paths)
|
103
|
+
end
|
104
|
+
|
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
|
114
|
+
|
115
|
+
let(:failed_path) { File.expand_path('failed_file_last_time.rb') }
|
116
|
+
|
117
|
+
context 'when :keep_failed option is enabled' do
|
118
|
+
let(:options) { { keep_failed: true } }
|
119
|
+
|
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
|
128
|
+
|
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
|
137
|
+
|
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
|
146
|
+
end
|
147
|
+
|
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
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
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
|
+
]
|
166
|
+
end
|
167
|
+
|
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')
|
177
|
+
]
|
178
|
+
end
|
179
|
+
|
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
|
+
]
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
end
|
194
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
class NoExpectationExecutedError < StandardError
|
4
|
+
end
|
5
|
+
|
6
|
+
RSpec.configure do |config|
|
7
|
+
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
|
+
end
|
26
|
+
|
27
|
+
Dir[File.join(File.dirname(__FILE__), 'support', '*')].each do |path|
|
28
|
+
require path
|
29
|
+
end
|
30
|
+
|
31
|
+
require 'simplecov'
|
32
|
+
SimpleCov.coverage_dir(File.join('spec', 'coverage'))
|
33
|
+
|
34
|
+
if ENV['TRAVIS']
|
35
|
+
require 'coveralls'
|
36
|
+
Coveralls.wear!
|
37
|
+
elsif ENV['CI']
|
38
|
+
require 'simplecov-rcov'
|
39
|
+
SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter
|
40
|
+
end
|
41
|
+
|
42
|
+
SimpleCov.start do
|
43
|
+
add_filter '/spec/'
|
44
|
+
add_filter '/vendor/bundle/'
|
45
|
+
end
|
46
|
+
|
47
|
+
require 'guard/rubocop'
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module CaptureHelper
|
4
|
+
def capture(stream_name)
|
5
|
+
stream_name = stream_name.to_s.downcase
|
6
|
+
original_stream = eval("$#{stream_name}")
|
7
|
+
eval("$#{stream_name} = StringIO.new")
|
8
|
+
|
9
|
+
begin
|
10
|
+
yield
|
11
|
+
result = eval("$#{stream_name}").string
|
12
|
+
ensure
|
13
|
+
eval("$#{stream_name} = original_stream")
|
14
|
+
end
|
15
|
+
|
16
|
+
result
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
shared_context 'silence output', silence_output: true do
|
4
|
+
before do
|
5
|
+
null_output = double('output').as_null_object
|
6
|
+
|
7
|
+
@original_stdout = $stdout
|
8
|
+
@original_stderr = $stderr
|
9
|
+
|
10
|
+
$stdout = null_output
|
11
|
+
$stderr = null_output
|
12
|
+
end
|
13
|
+
|
14
|
+
after do
|
15
|
+
$stdout = @original_stdout
|
16
|
+
$stderr = @original_stderr
|
17
|
+
end
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,212 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: guard-rubocop
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yuji Nakayama
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-04-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: guard
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.8'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rubocop
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.5'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.5'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: childprocess
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.3'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: term-ansicolor
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.1'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.1'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.3'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.3'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '10.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '10.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '2.13'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '2.13'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: simplecov
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ~>
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0.7'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ~>
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0.7'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: guard-rspec
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 2.5.4
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 2.5.4
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: ruby_gntp
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - '>='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0.3'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - '>='
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0.3'
|
153
|
+
description: Guard::Rubocop allows you to automatically check Ruby code style with
|
154
|
+
RuboCop when files are modified.
|
155
|
+
email:
|
156
|
+
- nkymyj@gmail.com
|
157
|
+
executables: []
|
158
|
+
extensions: []
|
159
|
+
extra_rdoc_files: []
|
160
|
+
files:
|
161
|
+
- .gitignore
|
162
|
+
- .travis.yml
|
163
|
+
- Gemfile
|
164
|
+
- Guardfile
|
165
|
+
- LICENSE.txt
|
166
|
+
- README.md
|
167
|
+
- Rakefile
|
168
|
+
- guard-rubocop.gemspec
|
169
|
+
- lib/guard/.rubocop.yml
|
170
|
+
- lib/guard/rubocop.rb
|
171
|
+
- lib/guard/rubocop/runner.rb
|
172
|
+
- lib/guard/rubocop/templates/Guardfile
|
173
|
+
- lib/guard/rubocop/version.rb
|
174
|
+
- spec/.rubocop.yml
|
175
|
+
- spec/guard/rubocop/runner_spec.rb
|
176
|
+
- spec/guard/rubocop_spec.rb
|
177
|
+
- spec/spec_helper.rb
|
178
|
+
- spec/support/.rubocop.yml
|
179
|
+
- spec/support/capture_helper.rb
|
180
|
+
- spec/support/silence_output.rb
|
181
|
+
homepage: https://github.com/yujinakayama/guard-rubocop
|
182
|
+
licenses:
|
183
|
+
- MIT
|
184
|
+
metadata: {}
|
185
|
+
post_install_message:
|
186
|
+
rdoc_options: []
|
187
|
+
require_paths:
|
188
|
+
- lib
|
189
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
190
|
+
requirements:
|
191
|
+
- - '>='
|
192
|
+
- !ruby/object:Gem::Version
|
193
|
+
version: '0'
|
194
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
195
|
+
requirements:
|
196
|
+
- - '>='
|
197
|
+
- !ruby/object:Gem::Version
|
198
|
+
version: '0'
|
199
|
+
requirements: []
|
200
|
+
rubyforge_project:
|
201
|
+
rubygems_version: 2.0.3
|
202
|
+
signing_key:
|
203
|
+
specification_version: 4
|
204
|
+
summary: Guard plugin for RuboCop
|
205
|
+
test_files:
|
206
|
+
- spec/.rubocop.yml
|
207
|
+
- spec/guard/rubocop/runner_spec.rb
|
208
|
+
- spec/guard/rubocop_spec.rb
|
209
|
+
- spec/spec_helper.rb
|
210
|
+
- spec/support/.rubocop.yml
|
211
|
+
- spec/support/capture_helper.rb
|
212
|
+
- spec/support/silence_output.rb
|