1 of 27

Cucumber

Railshöck, 31 January 2018

Richard Bützer, Renuo AG

2 of 27

2

3 of 27

Document – for whom?

3

4 of 27

Document – where?

4

5 of 27

5

6 of 27

Document – when?

6

7 of 27

7

8 of 27

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

9 of 27

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 of 27

10

11 of 27

11

12 of 27

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

13 of 27

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

14 of 27

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"

15 of 27

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

16 of 27

Cucumber == Capybara + overhead?

The costs of Cucumber:

  • Write Capybara steps
  • Write Cucumber specs
  • Setup
  • Learn

16

17 of 27

Cucumber == Capybara + overhead?

The costs of Cucumber:

  • Write steps (Capybara)
  • Write Cucumber specs
  • Setup
  • Learn

17

18 of 27

Cucumber == Capybara + overhead?

The costs of Cucumber:

  • Write steps (Capybara)
  • Write Cucumber specs
  • Setup
  • Learn

18

19 of 27

Benefits

19

20 of 27

20

21 of 27

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

22 of 27

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

23 of 27

Our experience

23

24 of 27

Our experience

24

25 of 27

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

26 of 27

Summary

The costs of Cucumber:

  • Setup
  • Learn

The benefits of Cucumber:

  • Documentation (internal, external)
  • Acceptance tests

26

27 of 27

Thank You

Given I know the answer

When You ask a question

Then I will answer you

Renuo AG

Industriestrasse 44

8304 Wallisellen