mdub / rspec-longrun

MIT License
10 stars 9 forks source link

Steps aren't printed out in rspec >= 2.14 #3

Closed zmoazeni closed 10 years ago

zmoazeni commented 10 years ago

Hi there, the internals have changed in 2.14 where the internal steps aren't printed out. The longrun spec works, but you can reproduce it with the following:

# in ./something_spec.rb
describe "Account management" do
  include RSpec::Longrun::DSL

  example "Log in and alter preferences" do
    step "Log in" do
    end

    step "Navigate to preferences page" do
    end
  end
end
RSPEC_VERSION=2.14.0 bundle update rspec
ruby-2.0.0-p353 ~/projects/rspec-longrun (master) ∴ be rspec something_spec.rb 
Account management {
  Log in and alter preferences OK (0.00s)
} (0.00s)

Finished in 0.00045 seconds
1 example, 0 failures

I haven't figured out the best way to submit a PR, but this works for me locally without having to monkey patch RSpec::Core:

RSpec.configuration.before(:suite) do
  RSpec.configuration.formatters.each do |formatter|
    RSpec.configuration.reporter.register_listener(formatter, :step_started, :step_finished)
  end
end

module DSL
  private

  def step(description)
    pending(description) unless block_given?
    begin
      RSpec.configuration.reporter.notify(:step_started, description)
      yield
    ensure
      RSpec.configuration.reporter.notify(:step_finished, description)
    end
  end
end

Looking at the rspec internals, I believe all of those methods are considered public API.

mdub commented 10 years ago

Cheers for the report. I've managed to derive a failing test, and will look at integrating your fix. Looks like Reporter#register_listener is new, so I might have to get tricky to support backward compatibility.

zmoazeni commented 10 years ago

@mdub Yeah that's fair.

One hackish suggestion:

1.9.3p484 :020 > RSpec.configuration.reporter.respond_to?(:register_listener)
 => true 

Another slightly more robust one:

1.9.3p484 :018 > major, minor = RSpec::Version::STRING.split('.')
 => ["2", "14", "1"] 
1.9.3p484 :019 > major.to_i <= 2 && minor.to_i < 14
 => false