Skip to content

Commit 0931a4d

Browse files
author
Alexey Chernenkov
committed
Merge pull request #254 from wless1/fix-rspec-3-deprecations
Fixing deprecation warnings on RSpec 3
2 parents 2beb782 + 642e112 commit 0931a4d

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

lib/guard/rspec/formatter.rb

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ class RSpec
66
class Formatter < ::RSpec::Core::Formatters::BaseFormatter
77
TEMPORARY_FILE_PATH = File.expand_path('./tmp/rspec_guard_result')
88

9+
def self.rspec_3?
10+
::RSpec::Core::Version::STRING.split('.').first == "3"
11+
end
12+
13+
if rspec_3?
14+
::RSpec::Core::Formatters.register self, :dump_summary
15+
end
16+
917
# rspec issue https://github.com/rspec/rspec-core/issues/793
1018
def self.extract_spec_location(metadata)
1119
root_metadata = metadata
@@ -35,7 +43,17 @@ def self.spec_path?(path)
3543
end
3644

3745
# Write summary to temporary file for runner
38-
def dump_summary(duration, total, failures, pending)
46+
def dump_summary(*args)
47+
if self.class.rspec_3?
48+
notification = args[0]
49+
duration = notification.duration
50+
total = notification.example_count
51+
failures = notification.failure_count
52+
pending = notification.pending_count
53+
else
54+
duration, total, failures, pending = args
55+
end
56+
3957
write do |f|
4058
f.puts _message(total, failures, pending, duration)
4159
f.puts _failed_paths.join("\n") if failures > 0

spec/lib/guard/rspec/formatter_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,20 @@
6060
expect(result).to match /^3 examples, 1 failures in 123\.0 seconds\n#{spec_filename}\n$/
6161
end
6262

63+
context "for rspec 3" do
64+
let(:notification) {
65+
Struct.new(:duration, :example_count, :failure_count, :pending_count).new(123, 3, 1, 0)
66+
}
67+
before do
68+
formatter.class.stub(:rspec_3?).and_return(true)
69+
end
70+
71+
it 'writes summary line and failed location' do
72+
allow(formatter).to receive(:examples) { [failed_example] }
73+
formatter.dump_summary(notification)
74+
expect(result).to match /^3 examples, 1 failures in 123\.0 seconds\n#{spec_filename}\n$/
75+
end
76+
end
6377
end
6478

6579
it 'should find the spec file for shared examples' do

0 commit comments

Comments
 (0)