Skip to content

Instantly share code, notes, and snippets.

@aslakhellesoy
Created November 28, 2017 15:12
Show Gist options
  • Save aslakhellesoy/017fc05cf7e1be9d122caf54082b7dc3 to your computer and use it in GitHub Desktop.
Save aslakhellesoy/017fc05cf7e1be9d122caf54082b7dc3 to your computer and use it in GitHub Desktop.
# features/support/parameter_types.rb
suffix = '(?:st|nd|rd|th)'
ParameterType(
name: 'flight',
regexp: /(\d+)#{suffix} flight/,
transformer: ->(n) { n.to_i }
)
ParameterType(
name: 'hotel',
regexp: /(\d+)#{suffix} hotel/,
transformer: ->(n) { n.to_i }
)
# features/travel.feature
Feature: Travel
Scenario Outline: optional-flight & optional-hotel
Given <query>
Examples:
| query |
| I reach StageFour: 3rd flight-2nd hotel test |
| I reach StageFour: 3rd hotel test |
| I reach StageFour: 17th flight test |
| I reach StageFive: 2nd flight-1st hotel test |
| I reach StageFive: 44th hotel test |
| I reach StageFive: 11th flight test |
# featrures/step_definitions/travel_steps.rb
Given('I reach StageFour:/StageFive: {flight}-{hotel} test') do |flight_number, hotel_number|
flight_and_hotel(flight_number, hotel_number)
end
Given('I reach StageFour:/StageFive: {flight} test') do |flight_number|
flight_and_hotel(flight_number, nil)
end
Given('I reach StageFour:/StageFive: {hotel} test') do |hotel_number|
flight_and_hotel(nil, hotel_number)
end
module TravelWorld
def flight_and_hotel(flight, hotel)
puts "Flight #{flight} - Hotel #{hotel}"
end
end
World(TravelWorld)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment