Skip to content

Commit

Permalink
Initial commit BDD Air
Browse files Browse the repository at this point in the history
  • Loading branch information
arunsark committed Jul 1, 2012
0 parents commit d33565a
Show file tree
Hide file tree
Showing 7 changed files with 200 additions and 0 deletions.
37 changes: 37 additions & 0 deletions .gitignore
@@ -0,0 +1,37 @@
.bundle
db/*.sqlite3
log/*.log
log/*.pid
tmp/**/*
tmp/*
tmp/
*~
*#
*#*
.sass-cache/*
.sass-cache
bin/
*.log
doc/
*.swp
.project
.DS_Store
public/system
public/stylesheets/
public/uploads/
*.rbc
*.sassc
capybara-*.html
.rspec
/.bundle
/vendor/bundle
/public/system/*
/coverage/
/spec/tmp/*
**.orig
rerun.txt
pickle-email-*.html
tags
activerecord-nulldb-adpater
.gems
bundler_stubs/
4 changes: 4 additions & 0 deletions Gemfile
@@ -0,0 +1,4 @@
source 'http://rubygems.org'

gem 'cucumber'
gem 'rspec'
28 changes: 28 additions & 0 deletions Gemfile.lock
@@ -0,0 +1,28 @@
GEM
remote: http://rubygems.org/
specs:
builder (3.0.0)
cucumber (1.2.1)
builder (>= 2.1.2)
diff-lcs (>= 1.1.3)
gherkin (~> 2.11.0)
json (>= 1.4.6)
diff-lcs (1.1.3)
gherkin (2.11.1)
json (>= 1.4.6)
json (1.7.3)
rspec (2.10.0)
rspec-core (~> 2.10.0)
rspec-expectations (~> 2.10.0)
rspec-mocks (~> 2.10.0)
rspec-core (2.10.1)
rspec-expectations (2.10.0)
diff-lcs (~> 1.1.3)
rspec-mocks (2.10.1)

PLATFORMS
ruby

DEPENDENCIES
cucumber
rspec
12 changes: 12 additions & 0 deletions booking_flight_tickets.feature
@@ -0,0 +1,12 @@
Feature: Booking Flight Tickets
In order to confirm my travel
As a user
I need to be able to easily book my tickets


Scenario: Book a ticket
Given there is a flight "6E-154" between "Bangalore" and "Hyderabad" on "01/12/2012"
And I search for flights between "Bangalore" and "Hyderabad" on "01/12/2012"
And I select the flight "6E-154" from the search result
When I book the tickets for "01/12/2012"
Then I should have the ticket booked on "6E-154" for "01/12/2012"
12 changes: 12 additions & 0 deletions features/booking_flight_tickets.feature
@@ -0,0 +1,12 @@
Feature: Booking Flight Tickets
In order to confirm my travel
As a user
I need to be able to easily book my tickets


Scenario: Book a ticket
Given there is a flight "6E-154" between "Bangalore" and "Hyderabad" on "01/12/2012"
And I search for flights between "Bangalore" and "Hyderabad" on "01/12/2012"
And I select the flight "6E-154" from the search result
When I book the tickets
Then I should have my tickets booked
71 changes: 71 additions & 0 deletions features/step_definitions/booking_flights_steps.rb
@@ -0,0 +1,71 @@
class Flight
attr_accessor :flight_number

def initialize(flight_number)
@flight_number = flight_number
@itineraries = []
end

def add_itinerary(itinerary)
@itineraries << itinerary
end
end

class Itinerary
attr_accessor :from, :to, :date
def initialize(from, to, date)
@from = from
@to = to
@date = date
end
end

class FlightSelector
attr_accessor :flight_list

def initialize(flight_list)
@flight_list = flight_list
end

def search(itinerary)
@flight_list
end
end

class ReservationSystem
def self.book_tickets(flight, itinerary, passenger)
OpenStruct.new(flight_number: flight.flight_number,
from: itinerary.from,
to: itinerary.to,
date: itinerary.date,
passenger_name: passenger.name)
end
end

Given /^there is a flight "(.*?)" between "(.*?)" and "(.*?)" on "(.*?)"$/ do |flight_number, from, to, on_date|
flight = Flight.new(flight_number)
flight.add_itinerary(Itinerary.new(from, to, on_date))
flight_list << flight
end

Given /^I search for flights between "(.*?)" and "(.*?)" on "(.*?)"$/ do |from, to, on_date|
create_my_itinerary(from, to, on_date)
search_flights for: my_itinerary
end

Given /^I select the flight "(.*?)" from the search result$/ do |flight_number|
choose_flight(flight_number)
end

When /^I book the tickets$/ do
passenger = OpenStruct.new(name: "Arun")
book_tickets flight: selected_flight, itinerary: my_itinerary, passenger: passenger
end

Then /^I should have my tickets booked$/ do
my_ticket.flight_number.should eq(selected_flight.flight_number)
my_ticket.date.should eq(my_itinerary.date)
my_ticket.from.should eq(my_itinerary.from)
my_ticket.to.should eq(my_itinerary.to)
my_ticket.passenger_name.should eq("Arun")
end
36 changes: 36 additions & 0 deletions features/support/booking_support.rb
@@ -0,0 +1,36 @@
module BookingSupport
def flight_list
@flight_list ||= []
end

def search_flights(params)
flight_selector = FlightSelector.new(@flight_list)
@search_results = flight_selector.search(params[:for])
end

def choose_flight(flight_number)
@selected_flight = @search_results.select { |flight| flight.flight_number == flight_number }[0]
end

def create_my_itinerary(from, to, on_date)
@my_itinerary = Itinerary.new(from, to, on_date)
end

def my_itinerary
@my_itinerary
end

def selected_flight
@selected_flight
end

def book_tickets(params)
@my_ticket = ReservationSystem.book_tickets(params[:flight], params[:itinerary], params[:passenger])
end

def my_ticket
@my_ticket
end
end

World(BookingSupport)

0 comments on commit d33565a

Please sign in to comment.