bdd 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +9 -5
- data/README.md +72 -224
- data/bdd.gemspec +6 -12
- data/examples/README.md +244 -0
- data/examples/minitest/abc_test.rb +58 -0
- data/examples/rspec/abc_spec.rb +58 -0
- data/examples/rspec/examples_with_shared_code/README.txt +1 -0
- data/examples/rspec/examples_with_shared_code/basic_spec.rb +42 -0
- data/examples/rspec/examples_with_shared_code/shared_1_spec.rb +40 -0
- data/examples/rspec/examples_with_shared_code/shared_2_spec.rb +40 -0
- data/examples/rspec/zombie_example_spec.rb +59 -0
- data/lib/bdd.rb +10 -13
- data/lib/bdd/adapters.rb +7 -0
- data/lib/bdd/adapters/base.rb +47 -0
- data/lib/bdd/adapters/minitest_adapter.rb +56 -0
- data/lib/bdd/adapters/rspec_adapter.rb +75 -0
- data/lib/bdd/check.rb +50 -0
- data/lib/bdd/class_methods.rb +22 -0
- data/lib/bdd/colors.rb +34 -0
- data/lib/bdd/minitest.rb +13 -0
- data/lib/bdd/rspec.rb +8 -3
- data/lib/bdd/string_builder.rb +22 -0
- data/lib/bdd/title.rb +22 -0
- data/lib/bdd/version.rb +1 -1
- metadata +42 -12
- data/.rspec +0 -2
- data/lib/bdd/rspec/example_group.rb +0 -107
- data/lib/bdd/rspec/formatter.rb +0 -73
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1bbba94ca8816485d96068bc62f9fb67718f7398
|
4
|
+
data.tar.gz: 77460d66dffe6fede33b6ac1f6d682845f772a46
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 592c999c12b91ac8e6ecfa662671ec2a2db8af1b33401f2ba7413212a12c5df7b72949610c41f72490e712a4ffac165d0d06b79c4fdc69f8e1647b1a47d19e3a
|
7
|
+
data.tar.gz: a730d892831dd0074ff7467512dd9efe60e8109f7ccf16e75097e90bdaf4eb54be2942982c2df2e1901290a24b1d495e4f14e9053feb7a39f7bfc83b8b3e9d6a
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,17 +1,15 @@
|
|
1
1
|
## Bdd
|
2
2
|
|
3
|
-
Bdd brings cucumber-style Given/When/Then/And/But
|
3
|
+
Bdd brings you cucumber-style Given/When/Then/And/But test reports
|
4
4
|
|
5
5
|
### Status
|
6
6
|
|
7
|
-
|
|
8
|
-
| :----: | :----: |
|
9
|
-
| [![Master Build Status](https://
|
10
|
-
|
7
|
+
| Our Tests | Latest Version | # of Downloads | Contribute |
|
8
|
+
| :----: | :----: | :----: | :----: |
|
9
|
+
| [![Master Build Status](https://travis-ci.org/thejamespinto/bdd.svg?branch=master)](https://travis-ci.org/thejamespinto/bdd) | [![Gem Version](https://img.shields.io/gem/v/bdd.svg)](https://rubygems.org/gems/bdd) | [![Downloads](http://img.shields.io/gem/dt/bdd.svg)](https://rubygems.org/gems/bdd) | [![GitHub Issues](https://img.shields.io/github/issues/thejamespinto/bdd.svg)](https://rubygems.org/gems/bdd) |
|
11
10
|
|
12
11
|
[![GitHub License](https://img.shields.io/github/license/mashape/apistatus.svg)](https://rubygems.org/gems/bdd)
|
13
|
-
|
14
|
-
[![GitHub Issues](https://img.shields.io/github/issues/thejamespinto/bdd.svg)](https://rubygems.org/gems/bdd)
|
12
|
+
|
15
13
|
|
16
14
|
|
17
15
|
|
@@ -24,289 +22,139 @@ This gem brings two major functionality to your tests
|
|
24
22
|
|
25
23
|
|
26
24
|
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
|
27
30
|
## Installation
|
28
31
|
|
29
32
|
Include in your Gemfile:
|
30
33
|
|
31
34
|
```ruby
|
32
35
|
group :test do
|
33
|
-
|
36
|
+
# pick one
|
37
|
+
gem 'bdd', require: 'bdd/rspec'
|
38
|
+
gem 'bdd', require: 'bdd/minitest'
|
34
39
|
end
|
35
40
|
```
|
36
41
|
|
37
|
-
### RSpec
|
38
|
-
|
39
|
-
Run specs with custom format specified inline:
|
40
42
|
|
41
|
-
`
|
42
|
-
rspec --format Bdd::RSpec::Formatter --color spec
|
43
|
-
`
|
44
43
|
|
45
|
-
Or, if you want to use as your default formatter, simply put the options in your .rspec file:
|
46
44
|
|
47
|
-
|
48
|
-
|
49
|
-
```yml
|
50
|
-
--format Bdd::RSpec::Formatter
|
51
|
-
--color
|
52
|
-
```
|
53
|
-
|
54
|
-
## Output Example
|
55
|
-
|
56
|
-
`spec/features/search_spec.rb`
|
45
|
+
### Installation For RSpec
|
57
46
|
|
58
47
|
```ruby
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
visit '/search'
|
63
|
-
expect(page).to have_content('Search')
|
64
|
-
end
|
65
|
-
|
66
|
-
When 'I search something' do
|
67
|
-
fill_in 'Search', with: 'John'
|
68
|
-
click_button 'Go'
|
69
|
-
end
|
70
|
-
|
71
|
-
Then 'I should see the word result' do
|
72
|
-
expect(page).to have_content('Result')
|
73
|
-
end
|
74
|
-
end
|
48
|
+
group :test do
|
49
|
+
gem 'rspec'
|
50
|
+
gem 'bdd', require: 'bdd/rspec'
|
75
51
|
end
|
76
52
|
```
|
77
53
|
|
78
|
-
|
79
|
-
### Documentation formatting output:
|
80
|
-
|
81
|
-
`rspec -fd spec/features/search_spec.rb`
|
82
|
-
|
83
|
-
<pre>
|
84
|
-
<b>Searching</b>
|
85
|
-
<b>Result is found</b>
|
86
|
-
<b>Given</b> I am on the search page
|
87
|
-
<b> When</b> I search something
|
88
|
-
<b> Then</b> I should see the word result
|
89
|
-
</pre>
|
90
|
-
|
91
|
-
|
92
|
-
### Shared Steps
|
93
|
-
|
94
|
-
### Basic Example with shared steps
|
95
|
-
|
96
|
-
You can refactor steps into methods using plain Ruby syntax.
|
54
|
+
Add this to your `spec/spec_helper.rb` file.
|
97
55
|
|
98
56
|
```ruby
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
fill_in 'Login', with: 'jack@example.com'
|
103
|
-
fill_in 'Password', with: 'password'
|
104
|
-
click_button "Log in"
|
105
|
-
expect(page).to have_content('Welcome jack@example.com')
|
106
|
-
end
|
57
|
+
RSpec.configure do |config|
|
58
|
+
config.color = true
|
59
|
+
config.default_formatter = Bdd::RSpec::Formatter
|
107
60
|
end
|
108
61
|
|
109
|
-
|
110
|
-
Then "I should see a confirmation message" do
|
111
|
-
expect(page).to have_content('Your profile was updated successfully')
|
112
|
-
end
|
113
|
-
end
|
62
|
+
# optionally, define methods in your own language
|
114
63
|
|
115
|
-
|
116
|
-
|
117
|
-
given_I_log_in
|
118
|
-
When 'I update profile description' do
|
119
|
-
...
|
120
|
-
end
|
121
|
-
then_I_should_see_a_confirmation_message
|
122
|
-
end
|
123
|
-
|
124
|
-
it 'User updates profile avatar' do
|
125
|
-
given_I_log_in
|
126
|
-
When 'I update profile avatar' do
|
127
|
-
...
|
128
|
-
end
|
129
|
-
then_I_should_see_a_confirmation_message
|
130
|
-
end
|
131
|
-
end
|
64
|
+
Bdd.define(%w[Dado], %w[Quando Entao], %w[E Mas]) # Portuguese
|
65
|
+
Bdd.define(%w[Zakładając], %w[Jeśli To], %w[Także Ale]) # Polish
|
132
66
|
```
|
133
|
-
Output:
|
134
|
-
<pre>
|
135
|
-
<b>User Flow</b>
|
136
|
-
<b>User updates profile description</b>
|
137
|
-
<b>Given</b> I log in
|
138
|
-
<b> When</b> I update profile description
|
139
|
-
<b> Then</b> I should see a confirmation message
|
140
|
-
</pre>
|
141
67
|
|
142
68
|
|
143
69
|
|
144
|
-
### Nested Example 1
|
145
70
|
|
146
|
-
|
147
|
-
|
148
|
-
Given is automatically inserted as a before
|
149
|
-
Then is automatically inserted as an after
|
71
|
+
### Installation For Minitest
|
150
72
|
|
151
73
|
```ruby
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
click_button "Log in"
|
157
|
-
expect(page).to have_content('Welcome jack@example.com')
|
74
|
+
group :test do
|
75
|
+
gem 'minitest'
|
76
|
+
gem 'minitest-reporters'
|
77
|
+
gem 'bdd', require: 'bdd/minitest'
|
158
78
|
end
|
79
|
+
```
|
159
80
|
|
160
|
-
|
161
|
-
expect(page).to have_content('Your profile was updated successfully')
|
162
|
-
end
|
81
|
+
Add this to your `test/test_helper.rb` file.
|
163
82
|
|
164
|
-
|
165
|
-
|
166
|
-
When 'I update profile description' do
|
167
|
-
...
|
168
|
-
end
|
169
|
-
end
|
83
|
+
```ruby
|
84
|
+
Minitest::Reporters.use!(Bdd::Minitest::Reporter.new)
|
170
85
|
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
end
|
176
|
-
end
|
86
|
+
# optionally, add methods in your own language
|
87
|
+
|
88
|
+
Bdd.define(%w[Dado], %w[Quando Entao], %w[E Mas]) # Portuguese
|
89
|
+
Bdd.define(%w[Zakładając], %w[Jeśli To], %w[Także Ale]) # Polish
|
177
90
|
```
|
178
|
-
Output:
|
179
|
-
<pre>
|
180
|
-
<b>User Flow</b>
|
181
|
-
<b>User updates profile description</b>
|
182
|
-
<b>Given</b> I log in
|
183
|
-
<b> When</b> I update profile description
|
184
|
-
<b> Then</b> I should see a confirmation message
|
185
|
-
</pre>
|
186
91
|
|
187
92
|
|
188
93
|
|
189
|
-
### Nested Example 2
|
190
94
|
|
191
|
-
Nesting will silence any output from the internal steps
|
192
95
|
|
193
|
-
```ruby
|
194
|
-
def given_I_am_on_the_log_in_page
|
195
|
-
Given 'I am on the login page' do
|
196
|
-
visit '/login'
|
197
|
-
end
|
198
|
-
end
|
199
96
|
|
200
|
-
|
201
|
-
When 'I put credentials' do
|
202
|
-
fill_in 'Login', with: 'jack@example.com'
|
203
|
-
fill_in 'Password', with: 'password'
|
204
|
-
click_button "Log in"
|
205
|
-
end
|
206
|
-
end
|
97
|
+
## Usage
|
207
98
|
|
208
|
-
|
209
|
-
Then 'I should be logged in' do
|
210
|
-
expect(page).to have_content('Welcome jack@example.com')
|
211
|
-
end
|
212
|
-
end
|
99
|
+
File `spec/features/search_spec.rb`
|
213
100
|
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
end
|
101
|
+
```ruby
|
102
|
+
context 'Searching' do
|
103
|
+
it 'Result is found' do
|
104
|
+
Given 'I am on the search page' do
|
105
|
+
visit '/search'
|
106
|
+
expect(page).to have_content('Search')
|
107
|
+
end
|
221
108
|
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
When 'I update profile description' do
|
226
|
-
...
|
109
|
+
When 'I search something' do
|
110
|
+
fill_in 'Search', with: 'John'
|
111
|
+
click_button 'Go'
|
227
112
|
end
|
228
|
-
then_I_should_see_a_confirmation_message
|
229
|
-
end
|
230
113
|
|
231
|
-
|
232
|
-
|
233
|
-
When 'I update profile avatar' do
|
234
|
-
...
|
114
|
+
Then 'I should see the word result' do
|
115
|
+
expect(page).to have_content('Result')
|
235
116
|
end
|
236
|
-
then_I_should_see_a_confirmation_message
|
237
117
|
end
|
238
118
|
end
|
239
119
|
```
|
240
|
-
Output:
|
241
|
-
<pre>
|
242
|
-
<b>User Flow</b>
|
243
|
-
<b>User updates profile description</b>
|
244
|
-
<b>Given</b> I log in
|
245
|
-
<b> When</b> I update profile description
|
246
|
-
<b> Then</b> I should see a confirmation message
|
247
|
-
</pre>
|
248
|
-
|
249
120
|
|
250
|
-
|
121
|
+
Run tests
|
251
122
|
|
252
|
-
|
123
|
+
`rspec -fd spec/features/search_spec.rb`
|
253
124
|
|
254
|
-
|
255
|
-
def when_I_log_in
|
256
|
-
When "I log in" do
|
257
|
-
visit '/login'
|
258
|
-
fill_in 'Login', with: 'jack@example.com'
|
259
|
-
fill_in 'Password', with: 'password'
|
260
|
-
click_button "Log in"
|
261
|
-
expect(page).to have_content('Welcome jack@example.com')
|
262
|
-
end
|
263
|
-
end
|
125
|
+
Output
|
264
126
|
|
127
|
+
<pre>
|
128
|
+
<b>Searching</b>
|
129
|
+
<b>Result is found</b>
|
130
|
+
<b>Given</b> I am on the search page
|
131
|
+
<b> When</b> I search something
|
132
|
+
<b> Then</b> I should see the word result
|
133
|
+
</pre>
|
265
134
|
|
266
|
-
def given_I_log_in
|
267
|
-
Given when_I_log_in
|
268
|
-
end
|
269
135
|
|
270
|
-
|
271
|
-
it 'User updates profile description' do
|
272
|
-
given_I_log_in
|
273
|
-
When 'I update profile description' do
|
274
|
-
...
|
275
|
-
end
|
276
|
-
then_I_should_see_a_confirmation_message
|
277
|
-
end
|
136
|
+
### More Examples
|
278
137
|
|
279
|
-
|
280
|
-
given_I_log_in
|
281
|
-
When 'I update profile avatar' do
|
282
|
-
...
|
283
|
-
end
|
284
|
-
then_I_should_see_a_confirmation_message
|
285
|
-
end
|
286
|
-
end
|
287
|
-
```
|
288
|
-
Output:
|
289
|
-
<pre>
|
290
|
-
<b>User Flow</b>
|
291
|
-
<b>User updates profile description</b>
|
292
|
-
<b>Given</b> I log in
|
293
|
-
<b> When</b> I update profile description
|
294
|
-
<b> Then</b> I should see a confirmation message
|
295
|
-
</pre>
|
138
|
+
* [READ ALL EXAMPLES](http://github.com/thejamespinto/bdd/tree/master/examples)
|
296
139
|
|
140
|
+
<br><br><br><br>
|
297
141
|
|
298
142
|
|
299
143
|
|
300
144
|
|
145
|
+
## Defining custom steps
|
301
146
|
|
147
|
+
In case your flow is different and you would like to define your own wording.
|
302
148
|
|
303
|
-
|
149
|
+
You can add more English words, or add an entirely new language:
|
304
150
|
|
305
|
-
|
151
|
+
```ruby
|
152
|
+
Bdd.define(%w[Given], %w[When Then], %w[And But]) # English
|
153
|
+
Bdd.define(%w[Dado], %w[Quando Entao], %w[E Mas]) # Portuguese
|
154
|
+
Bdd.define(%w[Zakładając], %w[Jeśli To], %w[Także Ale]) # Polish
|
155
|
+
```
|
306
156
|
|
307
|
-
__minitest__ and __test_unit__ pull requests are wanted.
|
308
157
|
|
309
|
-
__internationalization__ pull requests are wanted.
|
310
158
|
|
311
159
|
|
312
160
|
## Authors
|
data/bdd.gemspec
CHANGED
@@ -9,24 +9,18 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["James Pinto"]
|
10
10
|
spec.email = ["thejamespinto@gmail.com"]
|
11
11
|
|
12
|
-
spec.summary =
|
12
|
+
spec.summary =
|
13
13
|
spec.description = %q{Cucumber style in your RSpec tests}
|
14
14
|
spec.homepage = "https://github.com/thejamespinto/bdd"
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
-
spec.bindir = "
|
18
|
-
spec.executables = spec.files.grep(%r{^
|
17
|
+
spec.bindir = "bin"
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
# if spec.respond_to?(:metadata)
|
22
|
-
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com' to prevent pushes to rubygems.org, or delete to allow pushes to any server."
|
23
|
-
# end
|
24
|
-
|
25
|
-
spec.add_runtime_dependency 'rspec'
|
26
|
-
spec.add_runtime_dependency 'colorize'
|
27
|
-
|
28
|
-
|
29
21
|
# spec.add_development_dependency "bundler", "~> 1.9"
|
30
22
|
# spec.add_development_dependency "rake", "~> 10.0"
|
31
|
-
|
23
|
+
spec.add_development_dependency 'rspec'
|
24
|
+
spec.add_development_dependency 'minitest'
|
25
|
+
spec.add_development_dependency 'minitest-reporters', '1.1.9'
|
32
26
|
end
|
data/examples/README.md
ADDED
@@ -0,0 +1,244 @@
|
|
1
|
+
[Back to README](https://github.com/thejamespinto/bdd)
|
2
|
+
|
3
|
+
## Output Example
|
4
|
+
|
5
|
+
`spec/features/search_spec.rb`
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
context 'Searching' do
|
9
|
+
it 'Result is found' do
|
10
|
+
Given 'I am on the search page' do
|
11
|
+
visit '/search'
|
12
|
+
expect(page).to have_content('Search')
|
13
|
+
end
|
14
|
+
|
15
|
+
When 'I search something' do
|
16
|
+
fill_in 'Search', with: 'John'
|
17
|
+
click_button 'Go'
|
18
|
+
end
|
19
|
+
|
20
|
+
Then 'I should see the word result' do
|
21
|
+
expect(page).to have_content('Result')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
```
|
26
|
+
|
27
|
+
|
28
|
+
### Documentation formatting output:
|
29
|
+
|
30
|
+
`rspec -fd spec/features/search_spec.rb`
|
31
|
+
|
32
|
+
<pre>
|
33
|
+
<b>Searching</b>
|
34
|
+
<b>Result is found</b>
|
35
|
+
<b>Given</b> I am on the search page
|
36
|
+
<b> When</b> I search something
|
37
|
+
<b> Then</b> I should see the word result
|
38
|
+
</pre>
|
39
|
+
|
40
|
+
|
41
|
+
### Shared Steps
|
42
|
+
|
43
|
+
### Basic Example with shared steps
|
44
|
+
|
45
|
+
You can refactor steps into methods using plain Ruby syntax.
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
def given_I_log_in
|
49
|
+
Given "I log in" do
|
50
|
+
visit '/login'
|
51
|
+
fill_in 'Login', with: 'jack@example.com'
|
52
|
+
fill_in 'Password', with: 'password'
|
53
|
+
click_button "Log in"
|
54
|
+
expect(page).to have_content('Welcome jack@example.com')
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def then_I_should_see_a_confirmation_message
|
59
|
+
Then "I should see a confirmation message" do
|
60
|
+
expect(page).to have_content('Your profile was updated successfully')
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context 'User Flow' do
|
65
|
+
it 'User updates profile description' do
|
66
|
+
given_I_log_in
|
67
|
+
When 'I update profile description' do
|
68
|
+
...
|
69
|
+
end
|
70
|
+
then_I_should_see_a_confirmation_message
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'User updates profile avatar' do
|
74
|
+
given_I_log_in
|
75
|
+
When 'I update profile avatar' do
|
76
|
+
...
|
77
|
+
end
|
78
|
+
then_I_should_see_a_confirmation_message
|
79
|
+
end
|
80
|
+
end
|
81
|
+
```
|
82
|
+
Output:
|
83
|
+
<pre>
|
84
|
+
<b>User Flow</b>
|
85
|
+
<b>User updates profile description</b>
|
86
|
+
<b>Given</b> I log in
|
87
|
+
<b> When</b> I update profile description
|
88
|
+
<b> Then</b> I should see a confirmation message
|
89
|
+
</pre>
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
### Nested Example 1
|
94
|
+
|
95
|
+
Outside of the scope
|
96
|
+
|
97
|
+
Given is automatically inserted as a before
|
98
|
+
Then is automatically inserted as an after
|
99
|
+
|
100
|
+
```ruby
|
101
|
+
Given "I log in" do
|
102
|
+
visit '/login'
|
103
|
+
fill_in 'Login', with: 'jack@example.com'
|
104
|
+
fill_in 'Password', with: 'password'
|
105
|
+
click_button "Log in"
|
106
|
+
expect(page).to have_content('Welcome jack@example.com')
|
107
|
+
end
|
108
|
+
|
109
|
+
Then "I should see a confirmation message" do
|
110
|
+
expect(page).to have_content('Your profile was updated successfully')
|
111
|
+
end
|
112
|
+
|
113
|
+
context 'User Flow' do
|
114
|
+
it 'User updates profile description' do
|
115
|
+
When 'I update profile description' do
|
116
|
+
...
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'User updates profile avatar' do
|
121
|
+
When 'I update profile avatar' do
|
122
|
+
...
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
```
|
127
|
+
Output:
|
128
|
+
<pre>
|
129
|
+
<b>User Flow</b>
|
130
|
+
<b>User updates profile description</b>
|
131
|
+
<b>Given</b> I log in
|
132
|
+
<b> When</b> I update profile description
|
133
|
+
<b> Then</b> I should see a confirmation message
|
134
|
+
</pre>
|
135
|
+
|
136
|
+
|
137
|
+
|
138
|
+
### Nested Example 2
|
139
|
+
|
140
|
+
Nesting will silence any output from the internal steps
|
141
|
+
|
142
|
+
```ruby
|
143
|
+
def given_I_am_on_the_log_in_page
|
144
|
+
Given 'I am on the login page' do
|
145
|
+
visit '/login'
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
def when_I_submit_the_log_in_form
|
150
|
+
When 'I put credentials' do
|
151
|
+
fill_in 'Login', with: 'jack@example.com'
|
152
|
+
fill_in 'Password', with: 'password'
|
153
|
+
click_button "Log in"
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
def then_I_should_be_logged_in
|
158
|
+
Then 'I should be logged in' do
|
159
|
+
expect(page).to have_content('Welcome jack@example.com')
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
def given_I_log_in
|
164
|
+
Given "I log in" do
|
165
|
+
given_I_am_on_the_log_in_page
|
166
|
+
when_I_submit_the_log_in_form
|
167
|
+
then_I_should_be_logged_in
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
context 'User Flow' do
|
172
|
+
it 'User updates profile description' do
|
173
|
+
given_I_log_in
|
174
|
+
When 'I update profile description' do
|
175
|
+
...
|
176
|
+
end
|
177
|
+
then_I_should_see_a_confirmation_message
|
178
|
+
end
|
179
|
+
|
180
|
+
it 'User updates profile avatar' do
|
181
|
+
given_I_log_in
|
182
|
+
When 'I update profile avatar' do
|
183
|
+
...
|
184
|
+
end
|
185
|
+
then_I_should_see_a_confirmation_message
|
186
|
+
end
|
187
|
+
end
|
188
|
+
```
|
189
|
+
Output:
|
190
|
+
<pre>
|
191
|
+
<b>User Flow</b>
|
192
|
+
<b>User updates profile description</b>
|
193
|
+
<b>Given</b> I log in
|
194
|
+
<b> When</b> I update profile description
|
195
|
+
<b> Then</b> I should see a confirmation message
|
196
|
+
</pre>
|
197
|
+
|
198
|
+
|
199
|
+
### Renaming
|
200
|
+
|
201
|
+
Useful for refactored nesting, you can change a step's name
|
202
|
+
|
203
|
+
```ruby
|
204
|
+
def when_I_log_in
|
205
|
+
When "I log in" do
|
206
|
+
visit '/login'
|
207
|
+
fill_in 'Login', with: 'jack@example.com'
|
208
|
+
fill_in 'Password', with: 'password'
|
209
|
+
click_button "Log in"
|
210
|
+
expect(page).to have_content('Welcome jack@example.com')
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
|
215
|
+
def given_I_log_in
|
216
|
+
Given when_I_log_in
|
217
|
+
end
|
218
|
+
|
219
|
+
context 'User Flow'
|
220
|
+
it 'User updates profile description' do
|
221
|
+
given_I_log_in
|
222
|
+
When 'I update profile description' do
|
223
|
+
...
|
224
|
+
end
|
225
|
+
then_I_should_see_a_confirmation_message
|
226
|
+
end
|
227
|
+
|
228
|
+
it 'User updates profile avatar' do
|
229
|
+
given_I_log_in
|
230
|
+
When 'I update profile avatar' do
|
231
|
+
...
|
232
|
+
end
|
233
|
+
then_I_should_see_a_confirmation_message
|
234
|
+
end
|
235
|
+
end
|
236
|
+
```
|
237
|
+
Output:
|
238
|
+
<pre>
|
239
|
+
<b>User Flow</b>
|
240
|
+
<b>User updates profile description</b>
|
241
|
+
<b>Given</b> I log in
|
242
|
+
<b> When</b> I update profile description
|
243
|
+
<b> Then</b> I should see a confirmation message
|
244
|
+
</pre>
|