Ruby - a tester’s best friend Peter Lind @peter_lind
May 13, 2015
Ruby - a tester’s best friendPeter Lind @peter_lind
Ruby, wait what?
Born in 1993 Object-oriented Dynamic Open Source Elegant syntax Focus on programmer happiness Great for scripting And for apps Ruby On Rails?
Basics
[array] {hash_key: hash_value} {hash_key => hash_value} do |var| <block body> end { |var| <block body> } class ClassName <class body> end def method_name <method body> end
local_variable, @instance_variable, @@class_variable, Constant, $global
Basics
ruby script.rb
IRB
gems– gem install <library>
rake– Rakefile
How to install
Use version 1.9.2
OSX / Linux– Might already have it– If not, use RVM
•http://beginrescueend.com/rvm/install/
Windows– Use Railsinstaller
•http://railsinstaller.org/
Culture
Ruby is your friend, not your parent
Culture
Ruby is your friend, not your parent
Everything can be redefined
Culture
Ruby is your friend, not your parent
Everything can be redefined
Readability
Culture
Ruby is your friend, not your parent
Everything can be redefined
Readability
Culture
Ruby is your friend, not your parent
Everything can be redefined
Readability
TDD/BDD
Tools
Sinatra– Sinatra is a DSL for quickly creating web applications in Ruby
with minimal effort– http://www.sinatrarb.com/
Tools
Sinatra– Sinatra is a DSL for quickly creating web applications in Ruby
with minimal effort– http://www.sinatrarb.com/
Cucumber– BDD that talks to domain experts first and code second– http://cukes.info/
Cucumber
Features– Describes scenarios– In the Gherkin language, almost English (or over 40 other)– Given, When, Then
Cucumber
Features– Describes scenarios– In the Gherkin language, almost English (or over 40 other)– Given, When, Then
Step definitions– In Ruby– Available for Java, .NET others
Tools
Sinatra– Sinatra is a DSL for quickly creating web applications in Ruby
with minimal effort– http://www.sinatrarb.com/
Cucumber– BDD that talks to domain experts first and code second– http://cukes.info/
Capybara– Acceptance test framework for web applications– https://github.com/jnicklas/capybara
Cucumber and Capybara example
http://www.youtube.com/watch?v=S5XQTOVTPYY
https://github.com/peterlind/cuke4all
Java Web App
Tests
pets.featureFeature: Manage pets
Scenario: List pets Given a pet exists with name: "Fido", sort: 0, weight: 23 When I go to the list pets page Then I should see "Fido"
Scenario: Enter a pet Given I am on the enter pet page And I fill in "Name" with "Rufus" And I fill in "Sort" with "Cat" And I fill in "Weight" with "8" And I press "Save" Then a pet should exist with name: "Rufus", weight: 8
Capybara
Pickle
THANKS!
[email protected]@peter_lind