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

Enable to open rspec result from emacs #306

Open
wants to merge 1 commit 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
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ failed_mode: :focus # What to do with failed specs
all_after_pass: true # Run all specs after changed specs pass, default: false
all_on_start: true # Run all the specs at startup, default: false
launchy: nil # Pass a path to an rspec results file, e.g. ./tmp/spec_results.html
emacs: nil # Pass a path to an rspec results file, e.g. ./tmp/spec_results.txt
notification: false # Display notification after the specs are done running, default: true
run_all: { cmd: 'custom rspec command', message: 'custom message' } # Custom options to use when running all specs
title: 'My project' # Display a custom title for the notification, default: 'RSpec results'
Expand All @@ -108,6 +109,17 @@ guard :rspec, cmd: 'rspec -f html -o ./tmp/spec_results.html', launchy: './tmp/s
end
```

### Using Emacs 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 emacs option:

``` ruby
guard :rspec, cmd: 'rspec -o ./spec_results.txt', emacs: './spec_results.txt' do
# ...
end
```

## Development

* Documentation hosted at [RubyDoc](http://rubydoc.info/github/guard/guard-rspec/master/frames).
Expand Down
1 change: 1 addition & 0 deletions lib/guard/rspec/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module Options
cmd: nil,
cmd_additional_args: nil,
launchy: nil,
emacs: nil,
notification: true,
title: "RSpec results"
}
Expand Down
20 changes: 20 additions & 0 deletions lib/guard/rspec/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,25 @@ def _open_launchy
::Launchy.open(options[:launchy]) if pn.exist?
end

def _open_emacs(failed_paths)
return unless options[:emacs]
pn = Pathname.new(options[:emacs])
elisp = <<-"EOS".gsub(/\s+/, " ").strip
(display-buffer
(save-excursion
(with-current-buffer (find-file-noselect \"#{pn}\" t)
(revert-buffer t t)
(ansi-color-apply-on-region (point-min)(point-max))
(set-buffer-modified-p nil)
(compilation-mode t)
(current-buffer))))
EOS
IO.popen(["emacsclient", "--eval", elisp]) do |p|
p.readlines
p.close
end if pn.exist? && !failed_paths.empty?
end

def _run_all_after_pass
return unless options[:all_after_pass]
run_all
Expand All @@ -105,6 +124,7 @@ def _process_run_result(result, all)
inspector.failed(failed_paths)
notifier.notify(summary)
_open_launchy
_open_emacs(failed_paths)

_run_all_after_pass if !all && result
end
Expand Down
14 changes: 14 additions & 0 deletions spec/lib/guard/rspec/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,20 @@

runner.run(paths)
end
context "with emacs option" do
let(:options) { { cmd: "rspec", emacs: "emacs_path" } }

before do
allow(Pathname).to receive(:new).
with("emacs_path") { double(exist?: true) }
end

it "opens emacs" do
expect(IO).to receive(:popen).
with(array_including("emacsclient", "--eval"))
runner.run(paths)
end
end
end

it "notifies success" do
Expand Down