Name of current example's file:line in a before block?

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

[email protected]
07974 430184

On Jun 15, 2011, at 7:29 AM, Matt W. wrote:

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 }

Cheers,
David

On 15 Jun 2011, at 13:47, David C. wrote:

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
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users

cheers,
Matt

[email protected]
07974 430184

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs