RSpec 3 compatibility #31

mhenrixon opened this Issue Feb 3, 2014 · 5 comments


None yet
4 participants

Hey so the gem does not work under RSpec 3. It has to do with example being yielded into blocks instead of immediately available on the file itself.

I am looking into it but if you have any suggestions I am all ears.

The line that goes wrong is the following:

# /Users/mhenrixon/code/github/approvals/lib/approvals/extensions/rspec/dsl.rb:12:in 'verify'


kytrinyx commented Feb 3, 2014

I never actually use the RSpec integration -- it was a hack that I messed around with a couple years back. I'd have to go dig around in the RSpec 3 source code to see how they've organised things. Unfortunately, I don't think I have time to look at it for the next few weeks.

I am thinking of removing it (or at least moving it into a plugin) when I prepare the gem for v1.0.


markijbema commented Feb 19, 2014

I depend pretty much on the rspec functionality, so I'd rather keep it. Perfectly willing to invest some time in making it compatible, as I want to switch to rspec 3 as soon as it's there as well. The code is small enough that this shouldn't be too much work.

@marten you did some investigation into why this failed as well, did you find something?

marten commented Feb 19, 2014

Yes, group.example is gone in RSpec 3. If you want it, you can either use RSpec.current_example or you have capture it explicitly: it 'foo' do |example|. Neither of those are available in older RSpec versions, so you'll have to add a version check and switch behaviour based on that.

After figuring that out, my 2 minute timer for "let's see if this RSpec test would be cleaner using Approvals" was up, and I didn't pursue it further.


markijbema commented Feb 21, 2014

I'm currently working on upgrading to 2.99. One thing I noticed is what rspec suggests:

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

This sounds like a decent workaround, if you want to upgrade to 3 now, and have approvals.


markijbema commented Feb 21, 2014

Ok, my pullrequest should fix it. It runs without deprecation warnings on 2.99, and @marten verified that it works on 3.0 for him.

If we want to test this properly, we need to do a little more effort. We currently have one test suite, which tests (at least) two things: whether our code works, and whether code which uses approvals work.

If we want to test in both rspec 2 and 3, we need to test the latter using appraisals, but we cannot do so with the first (you cannot have a spec which works in both 2.14 and 3.0, unless you're willing to sacrifice a lot of syntax). This seemed a lot of effort for now, but eventually I think we'd want that.

kytrinyx closed this in #39 Feb 21, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment