You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 21, 2024. It is now read-only.
This will `extend` each new `World` object with those modules.
92
98
93
99
If you use [Ruby on Rails](/docs/tools/ruby#ruby-on-rails), there is already a `World` set up for you, so you will get
94
-
an instance of `Cucumber::Rails::World`, which is a subclass of `ActionDispatch::IntegrationTest`. This gives you access to a lot of Rails' helper methods.
100
+
an instance of `Cucumber::Rails::World`, which is a subclass of `ActionDispatch::IntegrationTest`. This gives you access
101
+
to a lot of Rails' helper methods.
102
+
{{% /block %}}
95
103
96
-
Cucumber-js also uses a `World` as an isolated context for each scenario. You can find more information in the
104
+
{{% block "javascript" %}} Cucumber-js uses a `World` as an isolated context for each scenario. You can find more
105
+
information in the
97
106
[cucumber-js documentation on GitHub](https://github.com/cucumber/cucumber-js/blob/master/docs/support_files/world.md).
107
+
{{% /block %}}
108
+
109
+
{{% block "java,kotlin" %}} JVM languages do not know a "World" object, like Ruby and JavaScript. Instead, you'll need
110
+
to use [Dependency Injection](#dependency-injection).{{% /block %}}
98
111
99
112
## Dependency Injection
100
-
If your programming language is Java, you will be writing glue code
101
-
([step definitions](/docs/cucumber/step-definitions) and [hooks](/docs/cucumber/api/#hooks)) in plain old Java classes.
113
+
{{% block "java,kotlin" %}} If your programming language is a JVM language, you will be writing glue code
114
+
([step definitions](/docs/cucumber/step-definitions) and [hooks](/docs/cucumber/api/#hooks)) in classes.
102
115
103
116
Cucumber will create a new instance of each of your glue code classes before each scenario.
104
117
@@ -112,10 +125,12 @@ The available dependency injection modules are:
112
125
-[Guice](#guice)
113
126
-[OpenEJB](#openejb)
114
127
-[Weld](#weld)
115
-
-[Needle](#needle)
128
+
-[Needle](#needle)
116
129
117
-
### PicoContainer
130
+
{{% /block %}} {{% block "ruby,javascript" %}} Dependency Injection is specific to JVM languages. {{% /block %}}
118
131
132
+
### PicoContainer
133
+
{{% block "java,kotlin" %}}
119
134
To use PicoContainer, add the following dependency to your `pom.xml`:
There is no documentation yet, but the code is on [GitHub](https://github.com/cucumber/cucumber-jvm/tree/master/picocontainer).
136
-
For more information, please see [sharing state using Picocontainer](http://www.thinkcode.se/blog/2017/04/01/sharing-state-between-steps-in-cucumberjvm-using-picocontainer).
151
+
For more information, please see [sharing state using PicoContainer](http://www.thinkcode.se/blog/2017/04/01/sharing-state-between-steps-in-cucumberjvm-using-picocontainer).
152
+
{{% /block %}}
137
153
138
-
### Spring
154
+
{{% block "ruby,javascript" %}} PicoContainer is a Dependency Injection framework for JVM languages. {{% /block %}}
139
155
156
+
157
+
### Spring
158
+
{{% block "java,kotlin" %}}
140
159
To use Spring, add the following dependency to your `pom.xml`:
There is no documentation yet, but the code is on [GitHub](https://github.com/cucumber/cucumber-jvm/tree/master/guice).
177
199
For more information, please see [sharing state using Guice](http://www.thinkcode.se/blog/2017/08/16/sharing-state-between-steps-in-cucumberjvm-using-guice).
200
+
{{% /block %}}
178
201
179
-
### OpenEJB
202
+
{{% block "ruby,javascript" %}} Guice is a Dependency Injection framework for JVM languages. {{% /block %}}
180
203
204
+
### OpenEJB
205
+
{{% block "java,kotlin" %}}
181
206
To use OpenEJB, add the following dependency to your `pom.xml`:
{{% block "ruby,javascript" %}} Using the Cucumber object factory is specific to JVM languages. {{% /block %}}
396
440
441
+
### Using the Cucumber object factory a test runner (JUnit/TestNG)
442
+
{{% block "java,kotlin" %}}
397
443
The Cucumber modules for [JUnit](/docs/cucumber/api/#junit) and [TestNG](/docs/cucumber/checking-assertions/#testng) allow to run Cucumber through a JUnit/TestNG test.
398
444
The custom object factory can be configured using the `@CucumberOptions` annotation.
445
+
{{% /block %}}
446
+
447
+
{{% block "ruby,javascript" %}} Using the Cucumber object factory is specific to JVM languages. {{% /block %}}
399
448
400
449
# Databases
401
450
402
451
There are several options to remove state from your database, to prevent leaking state between scenarios.
403
452
404
453
## The Before Hook Approach
405
454
406
-
The recommended approach to clean a database between scenarios is to use a
407
-
`Before`[hook](/docs/cucumber/api/#hooks) to remove all data *before* a scenario starts.
408
-
409
-
This is usually better than using an `After`[hook](/docs/cucumber/api/#hooks), as it allows
410
-
you to perform a post-mortem inspection of the database if a scenario fails.
455
+
The recommended approach to clean a database between scenarios is to use a `Before`[hook](/docs/cucumber/api/#hooks) to
456
+
remove all data *before* a scenario starts. This is usually better than using an `After`
457
+
[hook](/docs/cucumber/api/#hooks), as it allows you to perform a post-mortem inspection of the database if a scenario
458
+
fails.
411
459
412
460
An alternative approach is to use database transactions.
413
461
@@ -440,22 +488,27 @@ Feature: Let's write a lot of stuff to the DB
440
488
```
441
489
442
490
### With JUnit and Spring
443
-
491
+
{{% block "java,kotlin" %}}
444
492
See the [`spring-txn`](https://github.com/cucumber/cucumber-jvm/tree/master/examples/spring-txn) example in Cucumber-JVM for a minimal setup.
493
+
{{% /block %}}
494
+
495
+
{{% block "ruby,javascript" %}} JUnit and Spring are used with JVM languages. {{% /block %}}
445
496
446
497
# Browser Automation and Transactions
447
498
448
-
If you're using a [browser automation](/docs/guides/browser-automation) tool that talks to your application over HTTP, the
449
-
transactional approach will not work if your [step definitions](/docs/cucumber/step-definitions) and the web application serving
450
-
HTTP request each have their own database connection.
451
-
With transactions on, transactions are **never** committed to the database (but rolled back at the end of each Scenario).
452
-
Therefore, the web server's connection will never see data from Cucumber, and therefore your browser won't either.
453
-
Likewise, Cucumber's connection won't see data from the web server.
499
+
If you're using a [browser automation](/docs/guides/browser-automation) tool that talks to your application over HTTP,
500
+
the transactional approach will not work if your [step definitions](/docs/cucumber/step-definitions) and the web
501
+
application serving HTTP request each have their own database connection. With transactions on, transactions are
502
+
**never** committed to the database (but rolled back at the end of each Scenario). Therefore, the web server's
503
+
connection will never see data from Cucumber, and therefore your browser won't either. Likewise, Cucumber's connection
504
+
won't see data from the web server.
454
505
455
-
In this case, you will have to turn off database transactions and make sure the data is explicitly deleted before each Scenario.
506
+
In this case, you will have to turn off database transactions and make sure the test data is explicitly deleted before each Scenario.
456
507
457
508
## Turn off transactions
458
-
If you're using [Ruby on Rails](/docs/tools/ruby#ruby-on-rails), you can turn off transactions for a feature or particular scenarios. Use the `@no-txn` tag, like this:
509
+
{{% block "ruby" %}}
510
+
If you're using [Ruby on Rails](/docs/tools/ruby#ruby-on-rails), you can turn off transactions for
511
+
a feature or particular scenarios. Use the `@no-txn` tag, like this:
459
512
460
513
```
461
514
@no-txn
@@ -476,12 +529,14 @@ With Rails, you can also turn off transaction globally in your `features/support
which you can install with `gem install database_cleaner`.
536
+
## Cleaning Your Database
537
+
{{% block "ruby" %}} If you're using [Ruby on Rails](/docs/tools/ruby#ruby-on-rails), a good tool to deal with this is
538
+
Ben Mabey's [Database Cleaner](https://github.com/bmabey/database_cleaner) gem, which you can install with `gem install
539
+
database_cleaner`.
485
540
486
541
You can use this very effectively with the `@no-txn` tag. For example, add something like the following somewhere in e.g. `features/support/db_cleaner.rb`:
487
542
@@ -525,3 +580,6 @@ After('@no-txn') do
525
580
DatabaseCleaner.strategy = :transaction
526
581
end
527
582
```
583
+
{{% /block %}}
584
+
585
+
{{% block "java,kotlin,javascript" %}} Ruby tools provide specific ways to clean your database. {{% /block %}}
0 commit comments