Skip to content

Commit df2ec70

Browse files
committed
Enable to open rspec result from emacs
1 parent 76249c3 commit df2ec70

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ failed_mode: :focus # What to do with failed specs
9191
all_after_pass: true # Run all specs after changed specs pass, default: false
9292
all_on_start: true # Run all the specs at startup, default: false
9393
launchy: nil # Pass a path to an rspec results file, e.g. ./tmp/spec_results.html
94+
emacs: nil # Pass a path to an rspec results file, e.g. ./tmp/spec_results.txt
9495
notification: false # Display notification after the specs are done running, default: true
9596
run_all: { cmd: 'custom rspec command', message: 'custom message' } # Custom options to use when running all specs
9697
title: 'My project' # Display a custom title for the notification, default: 'RSpec results'
@@ -108,6 +109,17 @@ guard :rspec, cmd: 'rspec -f html -o ./tmp/spec_results.html', launchy: './tmp/s
108109
end
109110
```
110111

112+
### Using Emacs to view rspec results
113+
114+
guard-rspec can be configured to launch a results file in lieu of outputing rspec results to the terminal.
115+
Configure your Guardfile with the emacs option:
116+
117+
``` ruby
118+
guard :rspec, cmd: 'rspec -o ./spec_results.txt', emacs: './spec_results.txt' do
119+
# ...
120+
end
121+
```
122+
111123
## Development
112124

113125
* Documentation hosted at [RubyDoc](http://rubydoc.info/github/guard/guard-rspec/master/frames).

lib/guard/rspec/options.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module Options
1010
cmd: nil,
1111
cmd_additional_args: nil,
1212
launchy: nil,
13+
emacs: nil,
1314
notification: true,
1415
title: "RSpec results"
1516
}

lib/guard/rspec/runner.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,25 @@ def _open_launchy
8686
::Launchy.open(options[:launchy]) if pn.exist?
8787
end
8888

89+
def _open_emacs(failed_paths)
90+
return unless options[:emacs]
91+
pn = Pathname.new(options[:emacs])
92+
elisp = <<-"EOS".gsub(/\s+/, " ").strip
93+
(display-buffer
94+
(save-excursion
95+
(with-current-buffer (find-file-noselect \"#{pn}\" t)
96+
(revert-buffer t t)
97+
(ansi-color-apply-on-region (point-min)(point-max))
98+
(set-buffer-modified-p nil)
99+
(compilation-mode t)
100+
(current-buffer))))
101+
EOS
102+
IO.popen(["emacsclient", "--eval", elisp]) do |p|
103+
p.readlines
104+
p.close
105+
end if pn.exist? && !failed_paths.empty?
106+
end
107+
89108
def _run_all_after_pass
90109
return unless options[:all_after_pass]
91110
run_all
@@ -105,6 +124,7 @@ def _process_run_result(result, all)
105124
inspector.failed(failed_paths)
106125
notifier.notify(summary)
107126
_open_launchy
127+
_open_emacs(failed_paths)
108128

109129
_run_all_after_pass if !all && result
110130
end

spec/lib/guard/rspec/runner_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,20 @@
210210

211211
runner.run(paths)
212212
end
213+
context "with emacs option" do
214+
let(:options) { { cmd: "rspec", emacs: "emacs_path" } }
215+
216+
before do
217+
allow(Pathname).to receive(:new).
218+
with("emacs_path") { double(exist?: true) }
219+
end
220+
221+
it "opens emacs" do
222+
expect(IO).to receive(:popen).
223+
with(array_including("emacsclient", "--eval"))
224+
runner.run(paths)
225+
end
226+
end
213227
end
214228

215229
it "notifies success" do

0 commit comments

Comments
 (0)