Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/cli options #9

Merged
merged 2 commits into from May 23, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -4,7 +4,7 @@ guard :rspec, cmd: 'bundle exec rspec', all_on_start: true do
watch('spec/spec_helper.rb') { "spec" }
end

guard :reek do
guard :reek, cli: '--single-line' do
watch('config.reek')
watch(/^lib\/.*\.rb$/)
end
@@ -44,7 +44,7 @@ Please read the [Guard usage documentation](https://github.com/guard/guard#readm
You can pass some options in `Guardfile` like the following example:

```ruby
guard :reek, all_on_start: false, run_all: false do
guard :reek, all_on_start: false, run_all: false, cli: '--single-line --no-wiki-links' do
# ...
end
```
@@ -54,6 +54,9 @@ end
```
all_on_start: true # Check all files at Guard startup.
# default: true
cli: '--single-line' # Pass arbitrary reek CLI arguments.
# An array or string is acceptable.
# default: nil
run_all: true # Check all files on "Enter"
# default: true
```
@@ -8,7 +8,7 @@ class Runner
attr_reader :notifier, :ui, :result

def initialize(options)
@options = options
@cli = options[:cli]
@notifier = options[:notifier] || Notifier
@ui = options[:ui] || UI
end
@@ -17,14 +17,18 @@ def run(paths = [])
paths = [] if paths.include?('.reek')
ui_message(paths)

command = ['reek'].concat(paths)
@result = system(*command)
command = reek_cmd.concat(paths)
@result = Kernel.system(*command)

notify_about_result
end

private

def reek_cmd
['reek', @cli].compact
end

def ui_message(paths)
if paths.empty?
ui.info('Guard::Reek running on all')
@@ -3,31 +3,38 @@
describe Guard::Reek::Runner do
subject { Guard::Reek::Runner.new(options) }
let(:options) { { ui: ui, notifier: notifier } }
let(:kernel) { class_double('Kernel', system: true) }
let(:ui) { class_double('Guard::UI', info: true) }
let(:notifier) { class_double('Guard::Notifier', notify: true) }

before do
allow(subject).to receive(:system)
allow(Kernel).to receive(:system)
end

it 'executes reek' do
expect(subject).to receive(:system).with('reek')
expect(Kernel).to receive(:system).with('reek')
subject.run
end

it 'executes reek with file' do
expect(subject).to receive(:system).with('reek', 'test.rb')
expect(Kernel).to receive(:system).with('reek', 'test.rb')
subject.run(['test.rb'])
end

it 'executes reek when .reek updated' do
expect(subject).to receive(:system).with('reek')
expect(Kernel).to receive(:system).with('reek')
subject.run(['.reek'])
end

it 'executes reek with cli options' do
options[:cli] = '-s'
expect(Kernel).to receive(:system).with('reek', '-s')
subject.run
end

context 'when reek exited with 0 status' do
before do
allow(subject).to receive(:system).and_return(true)
allow(Kernel).to receive(:system).and_return(true)
end

it 'notifies about success' do
@@ -38,7 +45,7 @@

context 'when reek exited with non 0 status' do
before do
allow(subject).to receive(:system).and_return(false)
allow(Kernel).to receive(:system).and_return(false)
end

it 'notifies about failure' do