2015 07 08_genevarb_maniok_presentation
TRANSCRIPT
ManiokSpecification By Example with
RSpec1 — Maniok Lightning Talk at Geneva.rb. By Jean-Michel Garnier @21croissants, 2015-07-08
About me@21croissants
2 — Maniok Lightning Talk at Geneva.rb. By Jean-Michel Garnier @21croissants, 2015-07-08
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
Specification By Example / 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
Cucumber? 8M downloads1: Write test in plain text using Gherkin DSL
# features/buy_ticket/earl_bird.featureScenario: 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
2. Write step definition block in ruby to match plain text
# features/step_definitions/buy_ticket/early_bird_steps.rbGiven(/^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: ticketsend
6 — Maniok Lightning Talk at Geneva.rb. By Jean-Michel Garnier @21croissants, 2015-07-08
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
Slow
Given a feature with a slow background to set lots of immutable test dataWhen there are 15 scenariosThen cucumber will run the background for each scenario :(
8 — Maniok Lightning Talk at Geneva.rb. By Jean-Michel Garnier @21croissants, 2015-07-08
Capybara "acceptance" DSLfeature "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 Example9 — Maniok Lightning Talk at Geneva.rb. By Jean-Michel Garnier @21croissants, 2015-07-08
Veggie alternatives10 — Maniok Lightning Talk at Geneva.rb. By Jean-Michel Garnier @21croissants, 2015-07-08
turnip# spec/acceptance/buy_ticket/earl_bird.featureScenario: Early Bird tickets have sold out Given there are no "Early Bird" tickets le! for "Baruco 2015"
# spec/steps/buy_ticket/early_bird_steps.rbmodule EarlyBirdSteps step "there are no :ticket_type ticket for :conference_name" do |ticket_type, conference_name| # same as Cucumber endend
By Jonas Nicklas (capybara), 264K downloads11 — Maniok Lightning Talk at Geneva.rb. By Jean-Michel Garnier @21croissants, 2015-07-08
Spinach# features/buy_ticket/earl_bird.featureScenario: Early Bird tickets have sold out Given there are no "Early Bird" tickets le! for "Baruco 2015"
# features/steps/buy_ticket/early_bird_steps.rbclass 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 endend
By Codegram (Baruco). No I18n! 142K downloads12 — Maniok Lightning Talk at Geneva.rb. By Jean-Michel Garnier @21croissants, 2015-07-08
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
Generated Output using RSpec GherkinFormatter
# features/buy_ticket/earl_bird.featureFeature: 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
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
Coming soon· 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