[Cucumber] [JVM] State of the "World"

6,731 views
Skip to first unread message

Tim Walker

unread,
Jun 17, 2013, 1:20:30 PM6/17/13
to cu...@googlegroups.com
Hi, 

What is the current state of the Cucumber "World" object in Cucumber-JVM? I see some references to what looks like roll-your-own singleton pattern for global usage and some references in the new "Cucumber Recipes" book but am having a hard time finding any documentation or references to the current state. Has this been deprecated or ? 

Many thanks, 

Tim

aslak hellesoy

unread,
Jun 17, 2013, 1:36:25 PM6/17/13
to Cucumber Users
On Mon, Jun 17, 2013 at 12:20 PM, Tim Walker <walk...@gmail.com> wrote:
Hi, 

What is the current state of the Cucumber "World" object in Cucumber-JVM?

It depends on what programming language you're using. Are you using Java?

Aslak
 
I see some references to what looks like roll-your-own singleton pattern for global usage and some references in the new "Cucumber Recipes" book but am having a hard time finding any documentation or references to the current state. Has this been deprecated or ? 

Many thanks, 

Tim

--
-- 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
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Tim Walker

unread,
Jun 17, 2013, 1:45:35 PM6/17/13
to cu...@googlegroups.com
Java. 

Thank you.

Tim

aslak hellesoy

unread,
Jun 17, 2013, 2:02:27 PM6/17/13
to Cucumber Users
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?

See rule [2]

On Mon, Jun 17, 2013 at 12:45 PM, Tim Walker <walk...@gmail.com> wrote:
Java. 

Thank you.

Tim


On Mon, Jun 17, 2013 at 11:36 AM, aslak hellesoy <aslak.h...@gmail.com> wrote:



On Mon, Jun 17, 2013 at 12:20 PM, Tim Walker <walk...@gmail.com> wrote:
Hi, 

What is the current state of the Cucumber "World" object in Cucumber-JVM?

It depends on what programming language you're using. Are you using Java?


Ok, so you're using Java.

The purpose of a "World" is twofold:
1) Isolate state between scenarios.
2) share data between step definitions and hooks within a scenario.

How this is implemented is language specific. For example, in ruby, the implicit `self` variable inside a step definition points to the current scenario's World object. This is by default an instance of Object, but it can be anything you want if you use the World hook.

It's similar in Groovy.

It's different in Java. You have many (possibly connected) World objects.

The equivalent of the World in Cucumber-Java is _all of the objects with hook or stepdef annotations_. In other words, any class with methods annotated with @Before, @After, @Given and so on will be instantiated exactly once for each scenario.

This achieves the first goal.
To achieve the second goal you have two approaches:

a) Use a single class for all of your step definitions and hooks
b) Use several classes divided by responsibility [1] and use dependency injection [2] to connect them to each other.

Option a) quickly breaks down because your step definition code becomes a mess. That's why people tend to use b).

[2] PicoContainer, Spring, Guice, Weld, OpenEJB

Does this answer your question?

Aslak

Tim Walker

unread,
Jun 17, 2013, 3:16:54 PM6/17/13
to cu...@googlegroups.com
Yes. Thank you. Tim
Reply all
Reply to author
Forward
0 new messages