Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixing deprecation warnings on RSpec 3

  • Loading branch information...
commit 642e11232983e1a4b6f7fd99e84670213686d7d5 1 parent 2beb782
@wless1 wless1 authored
View
20 lib/guard/rspec/formatter.rb
@@ -6,6 +6,14 @@ class RSpec
class Formatter < ::RSpec::Core::Formatters::BaseFormatter
TEMPORARY_FILE_PATH = File.expand_path('./tmp/rspec_guard_result')
+ def self.rspec_3?
+ ::RSpec::Core::Version::STRING.split('.').first == "3"
+ end
+
+ if rspec_3?
+ ::RSpec::Core::Formatters.register self, :dump_summary
+ end
+
# rspec issue https://github.com/rspec/rspec-core/issues/793
def self.extract_spec_location(metadata)
root_metadata = metadata
@@ -35,7 +43,17 @@ def self.spec_path?(path)
end
# Write summary to temporary file for runner
- def dump_summary(duration, total, failures, pending)
+ def dump_summary(*args)
+ if self.class.rspec_3?
+ notification = args[0]
+ duration = notification.duration
+ total = notification.example_count
+ failures = notification.failure_count
+ pending = notification.pending_count
+ else
+ duration, total, failures, pending = args
+ end
+
write do |f|
f.puts _message(total, failures, pending, duration)
f.puts _failed_paths.join("\n") if failures > 0
View
14 spec/lib/guard/rspec/formatter_spec.rb
@@ -60,6 +60,20 @@
expect(result).to match /^3 examples, 1 failures in 123\.0 seconds\n#{spec_filename}\n$/
end
+ context "for rspec 3" do
+ let(:notification) {
+ Struct.new(:duration, :example_count, :failure_count, :pending_count).new(123, 3, 1, 0)
+ }
+ before do
+ formatter.class.stub(:rspec_3?).and_return(true)
+ end
+
+ it 'writes summary line and failed location' do
+ allow(formatter).to receive(:examples) { [failed_example] }
+ formatter.dump_summary(notification)
+ expect(result).to match /^3 examples, 1 failures in 123\.0 seconds\n#{spec_filename}\n$/
+ end
+ end
end
it 'should find the spec file for shared examples' do
Please sign in to comment.
Something went wrong with that request. Please try again.