Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

the Ruby version of TurnTicketDispenser with tests and refactorings

  • Loading branch information...
commit 3ce56793d6ea4a5e625c402457f2dd293f6256eb 1 parent 01b61b2
@Sam-Serpoosh Sam-Serpoosh authored
View
14 TDDMicroExercises.YoursSolutions/Sam-Serpoosh/code/turn_ticket_dispenser/ticket_dispenser.rb
@@ -0,0 +1,14 @@
+require_relative "./turn_number_sequence"
+require_relative "./turn_ticket"
+
+class TicketDispenser
+
+ def initialize(ticket_sequence_generator=TurnNumberSequence)
+ @ticket_sequence_generator = ticket_sequence_generator
+ end
+
+ def get_turn_ticket
+ new_turn_number = @ticket_sequence_generator.get_next_turn_number
+ TurnTicket.new(new_turn_number)
+ end
+end
View
7 TDDMicroExercises.YoursSolutions/Sam-Serpoosh/code/turn_ticket_dispenser/turn_number_sequence.rb
@@ -0,0 +1,7 @@
+class TurnNumberSequence
+ @@current_turn_number = -1
+
+ def self.get_next_turn_number
+ @@current_turn_number += 1
+ end
+end
View
9 TDDMicroExercises.YoursSolutions/Sam-Serpoosh/code/turn_ticket_dispenser/turn_ticket.rb
@@ -0,0 +1,9 @@
+class TurnTicket
+ def initialize(turn_number)
+ @turn_number = turn_number
+ end
+
+ def turn_number
+ @turn_number
+ end
+end
View
12 TDDMicroExercises.YoursSolutions/Sam-Serpoosh/spec/turn_ticket_dispenser_spec/ticket_dispenser_spec.rb
@@ -0,0 +1,12 @@
+require_relative "../../code/turn_ticket_dispenser/ticket_dispenser"
+
+
+describe TicketDispenser do
+ it "gets the next ticket" do
+ TurnNumberSequence.stub(:get_next_turn_number => 2)
+ ticket_dispenser = TicketDispenser.new
+
+ ticket = ticket_dispenser.get_turn_ticket
+ ticket.turn_number.should == 2
+ end
+end
View
0  TDDMicroExercises/Ruby/alarm.rb → ...ses/Ruby/tire_pressure_monitoring_system/alarm.rb
File renamed without changes
View
0  TDDMicroExercises/Ruby/sensor.rb → ...es/Ruby/tire_pressure_monitoring_system/sensor.rb
File renamed without changes
View
11 TDDMicroExercises/Ruby/turn_ticket_dispenser/ticket_dispenser.rb
@@ -0,0 +1,11 @@
+require_relative "./turn_number_sequence"
+require_relative "./turn_ticket"
+
+class TicketDispenser
+ def get_turn_ticket
+ new_turn_number = TurnNumberSequence.get_next_turn_number
+ new_turn_ticket = TurnTicket.new(new_turn_number)
+
+ return new_turn_ticket
+ end
+end
View
7 TDDMicroExercises/Ruby/turn_ticket_dispenser/turn_number_sequence.rb
@@ -0,0 +1,7 @@
+class TurnNumberSequence
+ TURN_NUMBER = -1
+
+ def self.get_next_turn_number
+ TURN_NUMBER += 1
+ end
+end
View
9 TDDMicroExercises/Ruby/turn_ticket_dispenser/turn_ticket.rb
@@ -0,0 +1,9 @@
+class TurnTicket
+ def initialize(turn_number)
+ @turn_number = turn_number
+ end
+
+ def turn_number
+ return @turn_number
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.