summaryrefslogtreecommitdiff
path: root/spec/integration/customer_spec.rb
blob: 474308599d92a3a5e837728184348fd1203d2df9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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