-
Notifications
You must be signed in to change notification settings - Fork 1
/
movie_spec.rb
117 lines (86 loc) · 3.18 KB
/
movie_spec.rb
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
require './movie.rb'
require './movie_printer.rb'
describe Movie do
it "returns its title" do
movie = Movie.new("Life Aquatic")
movie.title.should == "Life Aquatic"
end
it "accepts an optional year" do
movie = Movie.new("Groundhog Day", {year: 1993})
movie.title.should == "Groundhog Day (1993)"
end
it "returns the number of years since it was released" do
Time.stub_chain(:now, :year).and_return(2011) # Time.now.year => 2011
movie = Movie.new("Ghostbusters", {year: 1984})
movie.released_years_ago.should == 27
Time.stub_chain(:now, :year).and_return(2020) # Time.now.year => 2020
movie = Movie.new("Ghostbusters", {year: 1984})
movie.released_years_ago.should == 36
movie = Movie.new("Ghostbusters")
movie.released_years_ago.should be_nil
end
it "accepts hash for available formats" do
movie = Movie.new("Life Aquatic")
movie.vhs?.should be_false
movie.dvd?.should be_false
movie.bluray?.should be_false
movie = Movie.new("Life Aquatic", {vhs: true})
movie.vhs?.should be_true
movie.dvd?.should be_false
movie.bluray?.should be_false
movie = Movie.new("Life Aquatic", {dvd: true, bluray: true, year: 2004})
movie.vhs?.should be_false
movie.dvd?.should be_true
movie.bluray?.should be_true
end
it "returns title and formats info" do
movie = Movie.new("Life Aquatic", {dvd: true})
movie.info.should == "Life Aquatic. Available in: DVD"
movie = Movie.new("Life Aquatic", {vhs: true, dvd: true, bluray: true})
movie.info.should == "Life Aquatic. Available in: VHS, DVD and Blu-ray"
movie = Movie.new("Life Aquatic", {dvd: true, vhs: true})
movie.info.should == "Life Aquatic. Available in: VHS and DVD"
movie = Movie.new("Life Aquatic")
movie.info.should == "Life Aquatic. Not available"
end
it "allows rating from 1 to 5" do
movie = Movie.new("Life Aquatic")
movie.rating.should be_nil
movie.rate(4)
movie.rating.should == 4
movie.rate(10)
movie.rating.should == 5
movie.rate(-2)
movie.rating.should == 1
end
it "shows rating as: Bad, Good, Excelent" do
movie = Movie.new("Life Aquatic")
movie.in_one_word.should == "Unknown"
movie.rate(1)
movie.in_one_word.should == "Bad"
movie.rate(2)
movie.in_one_word.should == "Bad"
movie.rate(3)
movie.in_one_word.should == "Good"
movie.rate(4)
movie.in_one_word.should == "Good"
movie.rate(5)
movie.in_one_word.should == "Excelent"
# Tip: Use a case statement
end
context "Pretty printing" do
it "prints a nice box" do
movie = Movie.new("Rushmore", {year: 1998, vhs: true})
movie.rate(4)
movie_printer = MoviePrinter.new(movie)
box = movie_printer.print_box
lines = box.split("\n")
lines[0].should == '----------------------------------------'
lines[1].should == '| Rushmore (1998) |'
lines[2].should == '| |'
lines[3].should == '| Review: Good |'
lines[4].should == '| Available in: VHS |'
lines[5].should == '----------------------------------------'
end
end
end