Forum: RSpec Getting the file a scenario is defined in (Cucumber)

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
C8a634a01a2c4508360874bff7fb1a7f?d=identicon&s=25 Kevin Olbrich (olbrich)
on 2009-03-31 14:06
In Cucumber...
Is there a simple way to find out what file a scenario is defined in?

I'd like to use this information to load a set of fixtures depending on
which feature is being run.  So if I'm running the 'login.feature' file,
I'd like to be able to load the set of fixtures under
'/fixtures/login/*.yml'

_Kevin
0be0e4aa42aacd9a8a95c792de273ca7?d=identicon&s=25 Aslak Hellesøy (aslakhellesoy)
on 2009-03-31 17:09
(Received via mailing list)
On Tue, Mar 31, 2009 at 2:06 PM, Kevin Olbrich <lists@ruby-forum.com>
wrote:

> In Cucumber...
> Is there a simple way to find out what file a scenario is defined in?
>

No, but there is a dirty way:

Before do |scenario|
  f = scenario.instance_variable_get('@feature')
  if f
    puts f.file
  end
end

The scenario variable will be a Scnario, ScenarioOutline or ExampleCells
instance. In the latter case there is no @feature ivar.
Please file a feature request (or better yet - a patch) if you want to
see
this improved.

Also take a look at this ticket - maybe a cleaner way to achieve what
you
want.
https://rspec.lighthouseapp.com/projects/16211/tic...

Aslak
This topic is locked and can not be replied to.