Re: [Cucumber] [JVM] How can I dynamically find the full path of the current feature file

921 views
Skip to first unread message

aslak hellesoy

unread,
Oct 4, 2012, 8:40:34 PM10/4/12
to cu...@googlegroups.com
On Fri, Oct 5, 2012 at 1:28 AM, RobF <rob...@yahoo.com> wrote:
> Hi,
>
> I'm actually running cuke4duke.

Actually as in "I can't use Cucumber-JVM"?

> Suppose my feature file hierarchy is rooted
> at C:\cuke4duke\features
> and that I have 2 subdirectories here A and B which contain A.feature and
> B.feature and also A.txt and B.txt.
> I want to have a step in A.feature that reads something like:
> Then extract information from A.txt
> The implementation behind this step would then look for A.txt in the same
> directory as A.feature. How do I find this directory?
>

There is no way for a step definition to know anything about the
feature/scenario that invoked it I'm afraid. I suggest you either move
all the .txt files to the same dir, or pass the (relative) path from
your step to your stepdef using an argument:

Given /I have a file named (.*)/

Aslak

> Any suggestions would be greatly appreciated.
>
> Thanks, Rob
>
> --
> -- Rules --
>
> 1) Please prefix the subject with [Ruby], [JVM] or [JS].
> 2) Please use interleaved answers
> http://en.wikipedia.org/wiki/Posting_style#Interleaved_style
> 3) If you have a question, don't reply to an existing message. Start a new
> topic instead.
>
> You received this message because you are subscribed to the Google Groups
> Cukes group. To post to this group, send email to cu...@googlegroups.com. To
> unsubscribe from this group, send email to
> cukes+un...@googlegroups.com. For more options, visit this group at
> https://groups.google.com/d/forum/cukes?hl=en
>
>

RobF

unread,
Oct 4, 2012, 8:52:00 PM10/4/12
to cu...@googlegroups.com
What about in a Before Scenario Hook? Could this directory be detected at that point?

Thanks, Rob

aslak hellesoy

unread,
Oct 4, 2012, 9:14:50 PM10/4/12
to cu...@googlegroups.com
On Fri, Oct 5, 2012 at 1:52 AM, RobF <rob...@yahoo.com> wrote:
> What about in a Before Scenario Hook? Could this directory be detected at
> that point?
>

Theoretically - yes. At least in Cucumber-JVM: (Cuke4Duke is not maintained)

@Before
public void before(ScenarioResult s) {
// We could add a method to ScenarioResult that lets you access
the scenario's location. Something like this.
Location l = s.getLocation();
URI u = l.getUri();
int line = l.getLine();
}

I think it would make sense to rename ScenarioResult to just Scenario
in that case.

Please create a ticket at github - or better yet: A pull request!

Aslak

RobF

unread,
Oct 4, 2012, 11:07:30 PM10/4/12
to cu...@googlegroups.com
Aslak,

Thank you for the prompt reply.

Rob

Reply all
Reply to author
Forward
0 new messages