Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds RSpec.current_example #1004

Merged
merged 3 commits into from
Jul 21, 2013
Merged

Conversation

alindeman
Copy link
Contributor

  • Library authors that want to support RSpec < 2 and 3
    can use RSpec.current_example to find the current example in a hook
    method. In RSpec versions before 2.99, self.example can be used (but
    self.example is deprecated in RSpec >= 2.99 and removed in RSpec 3).

@alindeman
Copy link
Contributor Author

Updated the commit message to say 2.99 and 3.0. 2.14 isn't relevant here. My mistake originally.

@alindeman
Copy link
Contributor Author

I think we will want to backport this to 2.99, but not 2.14.

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 0fb5360 on alindeman:current_example into 4181b1d on rspec:master.

@JonRowe
Copy link
Member

JonRowe commented Jul 19, 2013

Yeah we'd need to backport this to 2-99-maintenance

@@ -490,8 +482,11 @@ def instance_exec_with_rescue(example, context = nil, &hook)
begin
instance_exec(example, &hook)
rescue Exception => e
raise unless @_current_rspec_example
@_current_rspec_example.set_exception(e, context)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I preferred the previous format...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aw, really? :) Why is that? I found the explicit conditional easier to parse in my mind. That said, I'm willing to be convinced.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mentally parse it as "we must error unless we have an example to set the exception on"

* Library authors that want to support RSpec 2 and 3
  can use `RSpec.current_example` to find the current example in a hook
  method. In RSpec versions before 2.99, `self.example` can be used (but
  `self.example` is deprecated in RSpec >= 2.99 and removed in RSpec 3).
* While RSpec isn't necessarily thread safe right now, it might be in
  the future.
@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 2805971 on alindeman:current_example into afee9c1 on rspec:master.

@alindeman
Copy link
Contributor Author

Ready for re-review: RSpec.current_example is now thread-local.

@myronmarston @JonRowe

@myronmarston
Copy link
Member

LGTM. Merge when green.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants