Skip to content

Commit

Permalink
Merge pull request #196 from vanboom/master
Browse files Browse the repository at this point in the history
Add `launchy' option to launch spec results instead of reading terminal output.
  • Loading branch information
thibaudgg committed Sep 22, 2013
2 parents 252b2ea + afc1320 commit 354ffff
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ gem 'rake'
group :test do
gem 'rspec'
gem 'coveralls', :require => false
gem 'launchy'
end
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ guard :rspec do
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
end
```

Please read [Guard doc](https://github.com/guard/guard#readme) for more information about the Guardfile DSL.

## Options
Expand Down Expand Up @@ -144,10 +143,21 @@ Former `:color`, `:drb`, `:fail_fast` and `:formatter` options are deprecated an
:focus_on_failed => false # focus on the first 10 failed specs first, rerun till they pass
:parallel => true # run all specs in parallel using [ParallelTests](https://github.com/grosser/parallel_tests) gem, default: false
:parallel_cli => "-n 2" # pass arbitrary Parallel Tests arguments, default: ""
:launchy => nil # pass a path to an rspec results file, e.g. ./tmp/spec_results.html
```

You can also use a custom binstubs directory using `:binstubs => 'some-dir'`.

### Using Launchy to view rspec results
guard-rspec can be configured to launch a results file in lieu of outputing rspec results to the terminal.
Configure your Guardfile with the launchy option
``` ruby
guard 'rspec', :cli=>'--color --format html --out ./tmp/spec_results.html' do
:launchy => "./tmp/spec_results.html"
# ...
end
```

### DRb mode

When you specify `--drb` within `:cli`, guard-rspec will circumvent the `rspec` command line tool by
Expand Down
16 changes: 12 additions & 4 deletions lib/guard/rspec/runner.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'drb/drb'
require 'rspec'
require 'pathname'

module Guard
class RSpec
Expand All @@ -8,14 +9,14 @@ class Runner
FAILURE_EXIT_CODE = 2

attr_accessor :options

def initialize(options = {})
@options = {
:bundler => true,
:binstubs => false,
:rvm => nil,
:cli => nil,
:env => nil,
:launchy => nil,
:notification => true,
:spring => false,
:turnip => false,
Expand Down Expand Up @@ -80,7 +81,7 @@ def parsed_or_default_formatter
end
end

private
private

def environment_variables
return if options[:env].nil?
Expand Down Expand Up @@ -145,6 +146,13 @@ def run_via_shell(paths, options)
Notifier.notify("Failed", :title => "RSpec results", :image => :failed, :priority => 2)
end

if options[:launchy]
require 'launchy'
pn = Pathname.new(options[:launchy])
if pn.exist?
Launchy.open(options[:launchy])
end
end
success
end

Expand Down Expand Up @@ -264,8 +272,8 @@ def deprecations_warnings
end
end
if options.key?(:version)
@options.delete(:version)
UI.info %{DEPRECATION WARNING: The :version option is deprecated. Only RSpec 2 is now supported.}
@options.delete(:version)
UI.info %{DEPRECATION WARNING: The :version option is deprecated. Only RSpec 2 is now supported.}
end
end

Expand Down
15 changes: 15 additions & 0 deletions spec/guard/rspec/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,21 @@
end
end
end

describe ':launchy =>' do
it 'runs with Launchy to launch the rspec output file' do
require 'launchy'
options = {:launchy=>'./tmp/test.html', :cli=>"--format html --out ./tmp/test.html"}
subject { described_class.new(options) }
subject.should_receive(:system).with(
"bundle exec rspec --format html --out ./tmp/test.html -r #{@lib_path.join('guard/rspec/formatter.rb')} " <<
'-f Guard::RSpec::Formatter --failure-exit-code 2 spec'
).and_return(true)
expect(FileTest).to receive(:exist?).and_return(true)
expect(Launchy).to receive(:open).with("./tmp/test.html").and_return(true)
subject.run(['spec'], options)
end
end
end
end
end
Expand Down

0 comments on commit 354ffff

Please sign in to comment.