3. Agenda
· Specification By Example
· 7 years of Cucumber: lessons learned
· Veggie alternatives
· Introducing: Maniok
· Q & A ?
3 — Maniok Lightning Talk at Geneva.rb. By Jean-Michel Garnier @21croissants, 2015-07-08
4. SpecificationByExample/
Gherkin?
Scenario: Spec By Example workshop
Given three amigos: Developer / Product / QA
When they talk in front of a white board
And write the outcome of their discussions in "scenarios"
Then they should build the "right" thing
pic from User Story Mapping book
More at http://kickstartacademy.io/
courses/bdd-kickstart
4 — Maniok Lightning Talk at Geneva.rb. By Jean-Michel Garnier @21croissants,
2015-07-08
5. Cucumber?8Mdownloads
1: Write test in plain text using Gherkin DSL
# features/buy_ticket/earl_bird.feature
Scenario: Early Bird tickets have sold out
Given there are no "Early Bird" tickets le! for "Baruco 2015"
When I want to buy a ticket
Then I should see the "Early Bird" tickets as "SOLD OUT"
5 — Maniok Lightning Talk at Geneva.rb. By Jean-Michel Garnier @21croissants, 2015-07-08
6. 2. Write step definition block in ruby to match
plain text
# features/step_definitions/buy_ticket/early_bird_steps.rb
Given(/^there are no "(.*?)" tickets le! for "(.*?)"$/) do |ticket_type_name, conference_name|
ticket_type = ticket_type_name.gsub(/s/, '_').downcase.to_sym
tickets = { ticket_type => 0 }
create :conference, name: conference_name, with: tickets
end
6 — Maniok Lightning Talk at Geneva.rb. By Jean-Michel Garnier @21croissants, 2015-07-08
7. Cost
· organizing step definitions is hard
· re-use existing step defs does not scale
· Regexp in step defs false idea
· Not fun :(
7 — Maniok Lightning Talk at Geneva.rb. By Jean-Michel Garnier @21croissants, 2015-07-08
8. Slow
Given a feature with a slow background to set lots of immutable test data
When there are 15 scenarios
Then cucumber will run the background for each scenario :(
8 — Maniok Lightning Talk at Geneva.rb. By Jean-Michel Garnier @21croissants, 2015-07-08
9. Capybara"acceptance"DSL
feature "Buy Early Bird ticket" do # describe
background do # before(:each)
end
given(:other_user) { create :user } # let <- Very confusing
scenario "Early Bird tickets have sold out" do # it
visit '/'
click_on "TICKETS"
expect(page).to have_content 'SOLD OUT'
end
Syntactic sugar for devs. Not suitable for Spec By Example
9 — Maniok Lightning Talk at Geneva.rb. By Jean-Michel Garnier @21croissants, 2015-07-08
11. turnip
# spec/acceptance/buy_ticket/earl_bird.feature
Scenario: Early Bird tickets have sold out
Given there are no "Early Bird" tickets le! for "Baruco 2015"
# spec/steps/buy_ticket/early_bird_steps.rb
module EarlyBirdSteps
step "there are no :ticket_type ticket for :conference_name" do |ticket_type, conference_name|
# same as Cucumber
end
end
By Jonas Nicklas (capybara), 264K downloads
11 — Maniok Lightning Talk at Geneva.rb. By Jean-Michel Garnier @21croissants, 2015-07-08
12. Spinach
# features/buy_ticket/earl_bird.feature
Scenario: Early Bird tickets have sold out
Given there are no "Early Bird" tickets le! for "Baruco 2015"
# features/steps/buy_ticket/early_bird_steps.rb
class Spinach::Features::TestHowSpinachWorks < Spinach::FeatureSteps
Given "there are no "ticket_type" ticket for "conference_name"" do
# Spinach assigns @ticket_type and @conference_name
# rest, same as Cucumber
end
end
By Codegram (Baruco). No I18n! 142K downloads
12 — Maniok Lightning Talk at Geneva.rb. By Jean-Michel Garnier @21croissants, 2015-07-08
13. Maniok (with a k):
RSpec.feature "Early Bird" do
before(:all) { step "Very slow data setup" { } }
scenario "Early Bird tickets have sold out" do
given 'there are no "Early Bird" tickets le! for "Baruco 2015"' do
create :conference, name: "Baruco 2015", with: { early_bird: 0 }
end
when "I want to buy a ticket" do
visit "/"; click_on "TICKETS"
end
then "I should see a big "SOLD OUT" sign and told to subscribe to the newsletter" do
expect(page).to have_content "SOLD OUT"
end
end; end
13 — Maniok Lightning Talk at Geneva.rb. By Jean-Michel Garnier @21croissants, 2015-07-08
14. GeneratedOutputusingRSpecGherkinFormatter
# features/buy_ticket/earl_bird.feature
Feature: Early Bird
Background:
* Very slow data setup
Scenario: Early Bird tickets have sold out
Given there are no "Early Bird" tickets le! for "Baruco 2015"
When I want to buy a ticket
Then I should see a big "SOLD OUT" sign and told to subscribe to the newsletter
14 — Maniok Lightning Talk at Geneva.rb. By Jean-Michel Garnier @21croissants, 2015-07-08
15. Pros
· small footprint (cuke is 16K LOC of ruby)
· DSL: given, when, then inside scenario block
· No mapping btw plain text feature & step defs
· Declarative style. Re-use ruby test helpers not
plain text
15 — Maniok Lightning Talk at Geneva.rb. By Jean-Michel Garnier @21croissants, 2015-07-08
16. Comingsoon
· Rewrite to make it RSpec 3.0 support
· Gherkin tables & Scenario outlines support
· Tim Pope's Fivemat support w/ Profiling each
step
· HTML formatter a la cucumber
· static HTML formatter a la rdoc (searchable)
16 — Maniok Lightning Talk at Geneva.rb. By Jean-Michel Garnier @21croissants, 2015-07-08
17. Merci!Q & A
17 — Maniok Lightning Talk at Geneva.rb. By Jean-Michel Garnier @21croissants, 2015-07-08