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

feat: allow array as cmd option #55

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ all_on_start: true # Check all files at Guard startup.
cli: '--rails' # Pass arbitrary RuboCop CLI arguments.
# An array or string is acceptable.
# default: nil
cmd: './bin/rubocop' # Pass custom cmd to run rubocop.
cmd: './bin/rubocop' # Pass custom cmd to run rubocop as String or Array.
# default: rubocop

hide_stdout: false # Do not display console output (in case outputting to file).
Expand All @@ -88,6 +88,17 @@ guard :rubocop, cli: %w(--format fuubar --format html -o ./tmp/rubocop_results.h
end
```

### Running with Bundler

guard-rubocop can be configured to run with bundler.
Configure your Guardfile with the cmd option:

``` ruby
guard :rubocop, cmd: %w(bundle exec guard) do
# ...
end
```

## Advanced Tips

If you're using a testing Guard plugin such as [`guard-rspec`](https://github.com/guard/guard-rspec) together with `guard-rubocop` in the TDD way (the red-green-refactor cycle),
Expand Down
1 change: 1 addition & 0 deletions lib/guard/rubocop/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def build_command(paths)
command << '--force-exclusion'
command.concat(args_specified_by_user)
command.concat(paths)
command.flatten
end

def should_add_default_formatter_for_console?
Expand Down
10 changes: 10 additions & 0 deletions spec/guard/rubocop/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,16 @@
end
end

context 'when set as array' do
let(:options) { { cmd: %w[bundle exec rubocop] } }

it 'uses the supplied :cmd' do
expect(build_command[0]).to eq('bundle')
expect(build_command[1]).to eq('exec')
expect(build_command[2]).to eq('rubocop')
end
end

context 'when not set' do
it 'uses the default command' do
expect(build_command[0]).to eq('rubocop')
Expand Down