This is now an archive web site. Some is still relevant as at February 2026 but some is purely of historic interest.
Lisa and I (Graham) are now fully retired from IT training.We have made many friends over 30 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Apache, Linux and Solaris/SunOS too. Our training notes are out of date, but with upward compatability some examples remain operational and relevant. You are welcome to make use of them "as seen", at your own risk. We now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We remain active, enjoying the times that we are retired but still healthy enough in mind and body to do things!
I am also active in many other area and still look after a lot of web sites - you can find an index ((here)) |
|
Guide exercise to help you learn Gherkin, Cucumber and Rspec (written 2015-01-06)
During today's Ruby course, I moved on to Cucumber and Gherkin very quickly - for a private course with delegates looking to using Behaviour Driven Development as the core of their work. Ruby's basics were covered first - variables, calculations, conditionals and loops. Then we moved on to functions, classes and methods. And by the afternoon of the second day, we were on to defining features in Gherkin:
Defining the steps used to test those features
1. Define the behaviour
Feature: Seeing how many can sit at a table
Scenario: Seeing numbers that can fit around each table
Given I have a table 1900 x 825 mm
When I ask how many people can sit at it with 850 mm each
Then I should be told 4
When I ask how many people can sit at it with standard space each
Then I should be told 6
Scenario: Seeing numbers that can fit around each table
Given I have a table 700 x 700 mm
When I ask how many people can sit at it with standard space each
Then I should be told 0
See tables.feature
2. Define the tests to implement that behaviour
(much of this automated from your first Cucumber run)
Given(/^I have a table (\d+) x (\d+) mm$/) do |arg1, arg2|
@centre = Table.new("Gill",11,arg1.to_i,arg2.to_i)
end
When(/^I ask how many people can sit at it with (\d+) mm each$/) do |arg1|
@bums = @centre.getSeats(arg1.to_i)
end
When(/^I ask how many people can sit at it with standard space each$/) do
@bums = @centre.getSeats
end
Then(/^I should be told (\d+)$/) do |arg1|
expect(@bums).to eq(arg1.to_i)
end
See table_steps.rb
3. Define the class to satisfy the tests
class Table
def initialize(waiter,number,mm1,mm2)
@waiter = waiter
@number = number
@mm1 = mm1
@mm2 = mm2
end
def getSeats(elbows = 800)
side1 = (@mm1 / elbows).to_i
side2 = (@mm2 / elbows).to_i
return 2 * (side1 + side2)
end
end
See tables.rb
Exercise for delegates - get the above code working on your training system and then implement code for the following extra scenario ( already provided, commented out in the feature file)
# Table cloths hang over by 10 cm and weigh 275 grams / square metre
# Scenario: Seeing how heavy a table cloth is
# Given I have a table 1900 x 825 mm
# When I ask how heavy the table cloth is
# Then I should be told the weight is 591.9375
The exercise here is an interesting one - we don't have delegates write a behariour, tests and class from scratch as that's a lot to take in for the first use. Rather, we have them take an example that we've gone through with them, then provide enhancements.
If you're learning Ruby on our Learning to Program in Ruby or Ruby Programming courses, I would be happy to extent into an introduction to Gherkin, Cucumber and Rspec for you. (written 2015-01-06)
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles R211 - Ruby - RSpec [4383] Improved test in Cucumber with RSpec - (2015-01-03) [4544] RSpec - Ruby testing (stand alone example / no cucumber) - (2015-10-17) [4579] Behaviour and test driven development in Ruby using RSpec - (2015-11-21) [4681] Ruby testing with RSpec - a new example - (2016-05-19) R221 - Ruby - Introduction to Cucumber [4380] Behaviour Driven Development / Ruby and Cucumber - (2015-01-02) [4381] Installing Cucumber (Ruby) - (2015-01-03) [4382] Second step Cucumber and Gherkin - beyond Hello World - (2015-01-03) [4384] Installing Cucumber on Ubuntu - cannot load such file -- mkmf (LoadError) message - (2015-01-04) [4551] Testing your new class - first steps with cucumber - (2015-10-23) [4552] Scenario outlines - tables of values to test - in Gherkin / Cucumber - (2015-10-23)
Some other Articles
Checking MySQL database backups have worked (not failed)Cucumber example - test::unit, scenario outlines, datafile driven testGlobal Regular Expression matching in Ruby (using scan)Regression Testing my website - Cucumber and WatirGuide exercise to help you learn Gherkin, Cucumber and RspecA booking that looks too good to be true? It probably is too good to be true!
|
4759 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96 at 50 posts per page
This is a page archived from The Horse's Mouth at
http://www.wellho.net/horse/ -
the diary and writings of Graham Ellis.
Every attempt was made to provide current information at the time the
page was written, but things do move forward in our business - new software
releases, price changes, new techniques. So much so, and it's so long ago
that we are retired
Link to Ezine home page (for reading).
|
|