Skip to content
This repository has been archived by the owner on Nov 30, 2024. It is now read-only.

Commit

Permalink
Merge pull request #967 from rspec/quick_fix_for_deprecation_formatte…
Browse files Browse the repository at this point in the history
…r_on_jruby

Properly base #966 off 2-14-maintenance
  • Loading branch information
myronmarston committed Jul 9, 2013
2 parents 8b7bb6a + 286b8f9 commit 8ba91ce
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 9 deletions.
6 changes: 6 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#dev

Bug fix
* Implement `#start` on the Deprecation Formatter to prevent collision with
`ruby-debug` on JRuby (Alex Portnov, Jon Rowe)

### 2.14.0 / 2013-07-06
[full changelog](http://github.com/rspec/rspec-core/compare/v2.14.0.rc1...v2.14.0)

Expand Down
16 changes: 15 additions & 1 deletion 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 listener.respond_to?(notification)
@listeners[notification.to_sym] << listener if understands(listener, notification)
end
true
end
Expand Down Expand Up @@ -127,5 +127,19 @@ def notify(event, *args, &block)
formatter.send(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
1 change: 1 addition & 0 deletions spec/rspec/core/formatters/deprecation_formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

module RSpec::Core::Formatters
describe DeprecationFormatter do

describe "#deprecation" do
let(:deprecation_stream) { StringIO.new }
let(:summary_stream) { StringIO.new }
Expand Down
39 changes: 31 additions & 8 deletions spec/rspec/core/reporter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module RSpec::Core

%w[start_dump dump_pending dump_failures dump_summary close].each do |message|
it "sends #{message} to the formatter(s) that respond to message" do
formatter.as_null_object.should_receive(message)
formatter.should_receive(message)
reporter.abort(nil)
end

Expand All @@ -34,7 +34,7 @@ module RSpec::Core
it "passes example_group_started and example_group_finished messages to that formatter in that order" do
order = []

formatter = double("formatter").as_null_object
formatter = double("formatter")
formatter.stub(:example_group_started) { |group| order << "Started: #{group.description}" }
formatter.stub(:example_group_finished) { |group| order << "Finished: #{group.description}" }

Expand All @@ -61,7 +61,7 @@ module RSpec::Core

context "given an example group with no examples" do
it "does not pass example_group_started or example_group_finished to formatter" do
formatter = double("formatter").as_null_object
formatter = double("formatter")
formatter.should_not_receive(:example_group_started)
formatter.should_not_receive(:example_group_finished)

Expand Down Expand Up @@ -120,18 +120,41 @@ 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).as_null_object
reporter = Reporter.new formatter
reporter.start 1
Time.stub(:now => ::Time.utc(2012, 10, 1))

formatter = double(:formatter)
duration = nil
formatter.stub(:dump_summary) do |dur, _, _, _|
duration = dur
end

reporter = Reporter.new formatter
reporter.start 1
Time.stub(:now => ::Time.utc(2012, 10, 1))


reporter.finish 1234
expect(duration).to be < 0.2
end
Expand Down

0 comments on commit 8ba91ce

Please sign in to comment.