[rspec-users] Name of current example's file:line in a before block?

Matt Wynne matt at mattwynne.net
Wed Jun 15 15:50:02 EDT 2011

On 15 Jun 2011, at 13:47, David Chelimsky wrote:

> On Jun 15, 2011, at 7:29 AM, Matt Wynne wrote:
>> Hi,
>> I have an idea for a tool I want to build. In a Cucumber Before() block, I can say:
>> Before do |scenario|
>> puts scenario.file_colon_line
>> end
>> That then gives me the information I'd need to run that test case (and only that test case) again.
>> Is there any way (however hacky / brittle) to do something similar in an RSpec before block, or do I need to delve into writing a formatter?
>> cheers,
>> Matt
> before { puts example.location }

Good answer!

Now, for bonus points: when the example is from a set of shared examples, is there an easy way to get the location of the line where the shared examples were included? (i.e. the file:line I'd need to pass to `rspec` in order to actually re-run that example). I can grep, but it would be easier if I could ask RSpec's model. Possible?

> Cheers,
> David
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users


matt at mattwynne.net
07974 430184

More information about the rspec-users mailing list