Skip to content

Commit

Permalink
[core] Merge pull request rspec/rspec-core#970 from rspec/restore_sim…
Browse files Browse the repository at this point in the history
…pler_deprecation_formatter_fix

Restore simpler deprecation formatter fix

---
This commit was imported from rspec/rspec-core@358c46d.
  • Loading branch information
JonRowe committed Jul 10, 2013
1 parent 31bccca commit 6edef31
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 40 deletions.
4 changes: 4 additions & 0 deletions rspec-core/lib/rspec/core/formatters/deprecation_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ def initialize(deprecation_stream=$stderr, summary_stream=$stdout)
@count = 0
end

def start(example_count=nil)
#no-op to fix #966
end

def deprecation(data)
@count += 1
if data[:message]
Expand Down
15 changes: 1 addition & 14 deletions rspec-core/lib/rspec/core/reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def initialize(*formatters)
# events to all registered listeners
def register_listener(listener, *notifications)
notifications.each do |notification|
@listeners[notification.to_sym] << listener if understands(listener, notification)
@listeners[notification.to_sym] << listener if listener.respond_to?(notification)
end
true
end
Expand Down Expand Up @@ -128,18 +128,5 @@ def notify(event, *args, &block)
end
end

private
if Method.method_defined?(:owner) # 1.8.6 lacks Method#owner
def understands(listener, notification)
listener.respond_to?(notification) && listener.method(notification).owner != ::Kernel
end
else
def understands(listener, notification)
# Hack for 1.8.6
# {}.method(:=~).to_s # => "#<Method: Hash(Kernel)#=~>"
listener.respond_to?(notification) && !listener.method(notification).to_s.include('(Kernel)')
end
end

end
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,29 @@

module RSpec::Core::Formatters
describe DeprecationFormatter do
let(:deprecation_stream) { StringIO.new }
let(:summary_stream) { StringIO.new }
let(:formatter) { DeprecationFormatter.new deprecation_stream, summary_stream }

describe "#deprecation" do
let(:deprecation_stream) { StringIO.new }
let(:summary_stream) { StringIO.new }
let(:formatter) { DeprecationFormatter.new deprecation_stream, summary_stream }
def with_start_defined_on_kernel
return yield if ::Kernel.method_defined?(:start)

begin
::Kernel.module_eval { def start(*); raise "boom"; end }
yield
ensure
::Kernel.module_eval { undef start }
end
end

it 'does not blow up when `Kernel` defines `start`' do
with_start_defined_on_kernel do
reporter = ::RSpec::Core::Reporter.new(formatter)
reporter.start(3)
end
end

describe "#deprecation" do
it "includes the method" do
formatter.deprecation(:deprecated => "i_am_deprecated")
deprecation_stream.rewind
Expand Down
22 changes: 0 additions & 22 deletions rspec-core/spec/rspec/core/reporter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,28 +120,6 @@ module RSpec::Core
end
end

describe 'when message implemented on kernel' do
def with_message_defined_on_kernel
return yield if ::Kernel.method_defined?(:start)

begin
::Kernel.module_eval { def start(*); raise "boom"; end }
yield
ensure
::Kernel.module_eval { undef start }
end
end

let(:formatter) { double("formatter") }

it 'does not blow up when `Kernel` defines message instead of a formatter' do
with_message_defined_on_kernel do
reporter = ::RSpec::Core::Reporter.new(formatter)
reporter.start(3)
end
end
end

describe "timing" do
it "uses RSpec::Core::Time as to not be affected by changes to time in examples" do
formatter = double(:formatter)
Expand Down

0 comments on commit 6edef31

Please sign in to comment.