diff options
| author | mo khan <mo@mokhan.ca> | 2014-05-26 16:34:16 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2014-05-26 16:34:26 -0600 |
| commit | 7245619df4350c63d5d858c23efbe1057933a2e4 (patch) | |
| tree | a9d1246808a1d989ba92fa001b8a2ce69d139f5e | |
| parent | 4ddbad3e6bd5a95ed4b9c680e93f39003612a61f (diff) | |
split apart files and add first spec.
| -rw-r--r-- | lib/customer.rb (renamed from lib/refactoring.rb) | 28 | ||||
| -rw-r--r-- | lib/movie.rb | 12 | ||||
| -rw-r--r-- | lib/rental.rb | 7 | ||||
| -rw-r--r-- | spec/spec_helper.rb | 3 | ||||
| -rw-r--r-- | spec/unit/customer_spec.rb | 10 |
5 files changed, 36 insertions, 24 deletions
diff --git a/lib/refactoring.rb b/lib/customer.rb index 52bfafb..c2ce3b0 100644 --- a/lib/refactoring.rb +++ b/lib/customer.rb @@ -1,24 +1,3 @@ -class Movie - REGULAR = 0 - NEW_RELEASE = 1 - CHILDRENS = 2 - - attr_reader :title - attr_accessor :price_code - - def initialize(title, price_code) - @title, @price_code = title, price_code - end -end - -class Rental - attr_reader :movie, :days_rented - - def initialize(movie, days_rented) - @movie, @days_rented = movie, days_rented - end -end - class Customer attr_reader :name @@ -30,7 +9,7 @@ class Customer def add_rental(arg) @rentals << arg end - + def statement total_amount, frequent_renter_points = 0, 0 result = "Rental Record for #{@name}\n" @@ -53,7 +32,7 @@ class Customer frequent_renter_points += 1 # add bonus for a two day new release rental if element.movie.price_code == Movie.NEW_RELEASE && element.days_rented > 1 - frequent_renter_points += 1 + frequent_renter_points += 1 end # show figures for this rental result += "\t" + element.movie.title + "\t" + this_amount.to_s + "\n" @@ -63,4 +42,5 @@ class Customer result += "Amount owed is #{total_amount}\n" result += "You earned #{frequent_renter_points} frequent renter points" result - end
\ No newline at end of file + end +end diff --git a/lib/movie.rb b/lib/movie.rb new file mode 100644 index 0000000..a085d46 --- /dev/null +++ b/lib/movie.rb @@ -0,0 +1,12 @@ +class Movie + REGULAR = 0 + NEW_RELEASE = 1 + CHILDRENS = 2 + + attr_reader :title + attr_accessor :price_code + + def initialize(title, price_code) + @title, @price_code = title, price_code + end +end diff --git a/lib/rental.rb b/lib/rental.rb new file mode 100644 index 0000000..3409359 --- /dev/null +++ b/lib/rental.rb @@ -0,0 +1,7 @@ +class Rental + attr_reader :movie, :days_rented + + def initialize(movie, days_rented) + @movie, @days_rented = movie, days_rented + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index dbc4f1a..8c72aae 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -4,6 +4,9 @@ # loaded once. # # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration +require 'customer' +require 'movie' +require 'rental' RSpec.configure do |config| config.treat_symbols_as_metadata_keys_with_true_values = true config.run_all_when_everything_filtered = true diff --git a/spec/unit/customer_spec.rb b/spec/unit/customer_spec.rb new file mode 100644 index 0000000..703693e --- /dev/null +++ b/spec/unit/customer_spec.rb @@ -0,0 +1,10 @@ +require "spec_helper" + +describe Customer do + describe "#statement" do + it "produces a statement" do + customer = Customer.new('george') + customer.statement.should_not be_nil + end + end +end |
