diff options
| author | mo khan <mo@mokhan.ca> | 2014-05-26 16:52:20 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2014-05-26 16:52:20 -0600 |
| commit | fab3dae0b354c4c4c292f300ac9bc6bf703d031c (patch) | |
| tree | f24516b71134e5a2c2ccf98d1d0aba2f4fcf925a | |
| parent | 7245619df4350c63d5d858c23efbe1057933a2e4 (diff) | |
add integration tests.
| -rw-r--r-- | lib/customer.rb | 2 | ||||
| -rw-r--r-- | spec/integration/customer_spec.rb | 68 | ||||
| -rw-r--r-- | spec/spec_helper.rb | 2 | ||||
| -rw-r--r-- | spec/unit/customer_spec.rb | 10 |
4 files changed, 70 insertions, 12 deletions
diff --git a/lib/customer.rb b/lib/customer.rb index c2ce3b0..4515e76 100644 --- a/lib/customer.rb +++ b/lib/customer.rb @@ -31,7 +31,7 @@ class Customer # add frequent renter points 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 + if element.movie.price_code == Movie::NEW_RELEASE && element.days_rented > 1 frequent_renter_points += 1 end # show figures for this rental diff --git a/spec/integration/customer_spec.rb b/spec/integration/customer_spec.rb new file mode 100644 index 0000000..4743085 --- /dev/null +++ b/spec/integration/customer_spec.rb @@ -0,0 +1,68 @@ +require "spec_helper" + +describe Customer do + let(:customer) { Customer.new('george') } + + describe "#statement" do + context "when no activity has taken place" do + it "produces an empty statement" do + statement = customer.statement + statement.should == "Rental Record for george\nAmount owed is 0\nYou earned 0 frequent renter points" + end + end + + context "when a regular movie is rented" do + let(:movie) { Movie.new('star wars', Movie::REGULAR) } + + before { customer.add_rental(Rental.new(movie, days_rented)) } + + context "for one day" do + let(:days_rented) { 1 } + + it "produces the correct statement" do + customer.statement.should == "Rental Record for george\n\tstar wars\t2\nAmount owed is 2\nYou earned 1 frequent renter points" + end + end + + context "for more than two days" do + let(:days_rented) { 3 } + + it "produces the correct statement" do + customer.statement.should == "Rental Record for george\n\tstar wars\t3.5\nAmount owed is 3.5\nYou earned 1 frequent renter points" + end + end + end + + context "when a new release is rented" do + let(:movie) { Movie.new('star wars', Movie::NEW_RELEASE) } + + before { customer.add_rental(Rental.new(movie, 1)) } + + it "produces the correct statement" do + customer.statement.should == "Rental Record for george\n\tstar wars\t3\nAmount owed is 3\nYou earned 1 frequent renter points" + end + end + + context "when a childrens movie is rented" do + let(:movie) { Movie.new('star wars', Movie::NEW_RELEASE) } + + before { customer.add_rental(Rental.new(movie, days_rented)) } + + context "for one day" do + let(:days_rented) { 1 } + + it "produces the correct statement" do + customer.statement.should == "Rental Record for george\n\tstar wars\t3\nAmount owed is 3\nYou earned 1 frequent renter points" + end + end + + context "for more than 3 days" do + let(:days_rented) { 4 } + + it "produces the correct statement" do + customer.statement.should == "Rental Record for george\n\tstar wars\t9\nAmount owed is 9\nYou earned 2 frequent renter points" + end + end + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 8c72aae..bc7d4ff 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -4,9 +4,9 @@ # loaded once. # # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration -require 'customer' require 'movie' require 'rental' +require 'customer' 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 deleted file mode 100644 index 703693e..0000000 --- a/spec/unit/customer_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -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 |
