Support conversion of RSpec::Core::ExampleGroup#example #23

Closed
yujinakayama opened this Issue Nov 13, 2013 · 0 comments

Comments

Projects
None yet
1 participant
Owner

yujinakayama commented Nov 13, 2013

RSpec::Core::ExampleGroup#example

Deprecated since 2.99, removed at 3.0.

Yielding current running example to it/example and before/after hooks

Available since 2.99.

RSpec.current_example

Available since 2.99.

expose_current_running_example_as config option

Available since 2.99.

Summary

rspec/rspec-core#666 (comment)

They have completely different purposes. It's not an either/or.

  • expose_current_running_example_as :example config option is meant to support users who are using gems that depend on the RSpec 2 API. It's not meant for library authors to use.
  • RSpec.current_example is an idea @alindeman suggested as a possible means to assist library authors in making their code work on RSpec 2 and RSpec 3. It's not meant for end users to use.

https://github.com/rspec/rspec-core/blob/7d6d2ca489a7f47d1a3103f134f3f8af305908f2/lib/rspec/core/example_group.rb#L513-L527

RSpec::Core::ExampleGroup#example is deprecated and will be removed in RSpec 3. There are a few options for what you can use instead:

  • rspec-core's DSL methods (it, before, after, let, subject, etc) now yield the example as a block argument, and that is the recommended way to access the current example from those contexts.
  • The current example is now exposed via RSpec.current_example, which is accessible from any context.
  • If you can't update the code at this call site (e.g. because it is in an extension gem), you can use this snippet to continue making this method available in RSpec 2.99 and RSpec 3:
RSpec.configure do |c|
  c.expose_current_running_example_as :example
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment