Matt Wynne
2011-Jun-15 12:29 UTC
[rspec-users] 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 matt at mattwynne.net 07974 430184
David Chelimsky
2011-Jun-15 12:47 UTC
[rspec-users] Name of current example''s file:line in a before block?
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, > Mattbefore { puts example.location } Cheers, David
Matt Wynne
2011-Jun-15 19:50 UTC
[rspec-users] Name of current example''s file:line in a before block?
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-userscheers, Matt matt at mattwynne.net 07974 430184