#485 √ resolved
Scott Taylor

Add file and line numbers to pending specs

Reported by Scott Taylor | August 5th, 2008 @ 11:30 AM | in No-Milestone-Assigned

In a large test suite it's often hard to track down where a pending spec is coming from. I've implemented a monkey patch so that I'll get the following output:


Event in_past? should forward to it's schedule (TODO: FIXME)
	(From: ./spec/unit/models/event_spec.rb:422)

Would rspec be interested in a formal patch? Here's the monkey patch that made it work:


module Spec
  module Example
    module Pending
      alias_method :__regular_pending__, :pending

      private :__regular_pending__

      # Override Rspecs pending to give file and line number of the pending spec
      def pending(message = "TODO")
        message = "#{message}) \n\t(From: #{caller[0]}"
        __regular_pending__(message)
      end
    end
  end
end

Comments and changes to this ticket

  • Pat Maddox

    Pat Maddox August 11th, 2008 @ 09:16 PM

    Yeah, I really like this. Can you please submit a patch?

  • Scott Taylor

    Scott Taylor August 14th, 2008 @ 08:24 AM

    Yeah, when I get the time. Didn't want to work on it if no one else would use it. So far, I've been overloaded with FP stuff @ EM.

    Btw, Pat, it was good to see you the other day. Did you end up going to the #nyc.rb meeting?

  • Scott Taylor

    Scott Taylor September 13th, 2008 @ 09:17 AM

    Any thoughts on the best way to implement this? As I see it, I have a few options:

    1. Use the monkey patch (with specs, of course) provided above. It's a bit hacky, though, since it relies on the base text formatter to wrap the pending error message in parens

    2. Create a PendingError class which subclasses from StandardError, and then subclass ExamplePendingError from it. From there, either:

    a.) Override PendingError#to_s or PendingError#message. Wrap the thing in parens along with the caller info. The problem with this is that it breaks 10 or so specs in the test suite (the tests that depend on it aren't using mocks, but the real objects)

    OR:

    b) Override the base formatter's #pending_message to take three arguments: 1. the example, 2. the default message, and 3. the caller info. The downside to this approach is that all of the formatters would need to change. Potentially, this would also break any other formatters which may be out there, "in the wild", so to speak.

    Thoughts?

  • Scott Taylor

    Scott Taylor September 13th, 2008 @ 11:15 AM

    Well, I went with #2b. I've sent you and David a pull request:

    http://github.com/smtlaissezfair...

  • Pat Maddox

    Pat Maddox September 13th, 2008 @ 05:09 PM

    • → Assigned user changed from “” to “Pat Maddox”

    Any chance you could change the other formatters to make use of this info? I think it's useful new behavior and it'd be nice to share the love... and since this change is going to break the API for some people, I think it's important that we make it really solid - so that means making every formatter display the caller info.

    Another thought re: breaking the api - what if, before calling pending_example from the reporter, you checked the arity of pending_example? If it's two, you don't pass the caller, and you also print some message saying that the 2 param signature is deprecated and will be removed some time (prob not next dot release, but the one after). This would let us get the caller info within RSpec formatters but not break any existing formatters. David, Scott, and anyone else, WDYT?

  • Scott Taylor

    Scott Taylor September 13th, 2008 @ 05:44 PM

    Any chance you could change the other formatters to make use of this info?

    Of course. This seems like it would be easy to do

    Another thought re: breaking the api - what if, before calling pending_example from the reporter, you checked the arity of pending_example?

    I actually like the arity / deprecation warning idea. The arity idea had occurred to me, but I hadn't thought of giving a warning for two args.

    I, too, would be curious as to what David and the rest of the guys think (does Aslak participate at all in the rspec side of things, or has he gone all vegetarian)?

  • Scott Taylor

    Scott Taylor September 14th, 2008 @ 12:44 AM

    Regarding point 1: all (except one) of the plain text formatters call super, so they already have the file and line number of the pending specs. The one exception is the HTML formatter, which already has a backtrace built in.

    As for point 2: I've added back traces on the following branch:

    http://github.com/smtlaissezfair...

    Although that is currently leading to a 404 because of a bug in github.

    I'll update the ticket when that bug gets resolved. Alternatively I can git format-patch, if you'd like.

  • Scott Taylor

    Scott Taylor September 14th, 2008 @ 01:11 AM

    I've git format-patch'ed the thing, and attached the patches as a tarball.

  • Pat Maddox

    Pat Maddox September 14th, 2008 @ 01:50 AM

    • → State changed from “new” to “resolved”

    on github. thanks man

    http://github.com/dchelimsky/rsp... is the last commit in the series

Please Login or create a free account to add a new comment.

You can update this ticket by sending an email to from your email client. (help)

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Behaviour Driven Development for Ruby.

Shared Ticket Bins

People watching this ticket

Attachments