Cucumber
Railshöck, 31 January 2018
Richard Bützer, Renuo AG
2
Document – for whom?
3
Document – where?
4
Document – when?
6
7
Ticket #1234
As user, I want to be able to login, so I can access my personal data
Given I am not logged in�When I log in with valid credentials�Then I see my user profile
8
Feature test
9
example 'login' do
visit login_path
fill_in 'username', with: 'alice'
fill_in 'password', with: 'alice$password'
click 'Login'
expect(page).to have_content 'Hi Alice!'
end
10
11
Cucumber test: Login
As a user
I want to be able to login
So I have access to my private data.
Scenario: Login
Given I am not logged in
When I log in with valid credentials
Then I see my user profile
12
Cucumber test step
13
When(/^I log in with valid credentials$/) do
fill_in 'username', with: 'Alice'
fill_in 'password', with: 'alice$password'
click 'Login'
end
Scenario: Login
Given I am not logged in
When I log in with valid credentials
Then I see my user profile
Cucumber test step
14
Then(/^I see the text "([^"]*)"$/) do |text|
expect(page).to have_content(text)
end
Then I see the text "Hello World"
Cucumber == Capybara + overhead?
15
example 'login' do
visit login_path
fill_in 'username', with: 'alice'
fill_in 'password', with: 'alice$passwd'
click 'Login'
expect(page).to have_content 'Hi Alice!'
end
As a user
I want to be able to login
So I have access to my private data.
Scenario: Login
Given I am not logged in
When I log in with valid cred.
Then I see my user profile
Cucumber == Capybara + overhead?
The costs of Cucumber:
16
Cucumber == Capybara + overhead?
The costs of Cucumber:
17
Cucumber == Capybara + overhead?
The costs of Cucumber:
18
Benefits
19
20
Capybara test
21
example 'login' do
visit login_path
fill_in 'username', with: 'alice'
fill_in 'password', with: 'alice$password'
click 'Login'
expect(page).to have_content 'Hi Alice!'
end
Cucumber test
As a user
I want to be able to login
So I have access to my private data.
Scenario: Login
Given I am not logged in
When I log in with valid credentials
Then I see my user profile
22
Our experience
23
Our experience
24
Acceptance tests
«The only way I know of to effectively eliminate communication errors between programmers and stakeholders is to write automated acceptance tests. These tests are so formal that they execute. They are completely unambiguous, and they cannot get out of sync with the application. They are the perfect requirements document.»
Robert C. Martin, «The Clean Coder»
25
Summary
The costs of Cucumber:
The benefits of Cucumber:
26
Thank You
Given I know the answer
When You ask a question
Then I will answer you
Renuo AG
Industriestrasse 44
8304 Wallisellen