flicks 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c9c38367cfaa556b1e96e5346eb160e96a73ebf7d2d77c2daf1660a06db25997
4
+ data.tar.gz: e4e6b31ca66a8995c45f2338554c5160685aebbfe2c663e2dc047a9fe83a79ab
5
+ SHA512:
6
+ metadata.gz: 0714c420bf2963ba9348792f5d2be432c95581f273246b599100e16b6a6e26d27e10ac876dec111b24383c03346531161b351414c71fa6bb59010b53da5142e0
7
+ data.tar.gz: 2f222ec25bf02517f40b32b722a517636a2d0759d03ec3537b56baa2a4797b1ad2d603c8376190183ef10710416f72af22be1f3620609ab87f8f3edb2db1dd4b
@@ -1,4 +1,6 @@
1
- Copyright (c) 2012 The Pragmatic Studio
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 The Pragmatic Studio
2
4
 
3
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
6
  of this software and associated documentation files (the "Software"), to deal
@@ -8,8 +10,8 @@ copies of the Software, and to permit persons to whom the Software is
8
10
  furnished to do so, subject to the following conditions:
9
11
 
10
12
  - You may not use this Software in other training contexts.
11
-
12
- - The above copyright notice and this permission notice shall be
13
+
14
+ - The above copyright notice and this permission notice shall be
13
15
  included in all copies or substantial portions of the Software.
14
16
 
15
17
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
@@ -18,4 +20,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
20
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
21
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
22
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
23
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,22 @@
1
+ # Flicks
2
+
3
+ This is an example application used in The Pragmatic Studio's
4
+ [Ruby video course](https://pragmaticstudio.com/courses/ruby).
5
+
6
+ ## Usage
7
+
8
+ To run the example main program file, use:
9
+
10
+ ```sh
11
+ flicks
12
+ ```
13
+
14
+ You can also specify a CSV file with movie titles and ranks:
15
+
16
+ ```sh
17
+ flicks my_movies.csv
18
+ ```
19
+
20
+ ## License
21
+
22
+ This code is available as open source under the terms of the LICENSE.txt file.
data/bin/flicks CHANGED
@@ -1,24 +1,27 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require_relative '../lib/flicks/playlist'
3
+ require_relative "../lib/flicks/playlist"
4
4
 
5
- playlist = Flicks::Playlist.new("Kermit")
6
- default_movie_file =
7
- File.join(File.dirname(__FILE__), 'movies.csv')
8
- playlist.load(ARGV.shift || default_movie_file)
5
+ playlist_1 = Flicks::Playlist.new("Kermit")
6
+
7
+ movies_file = File.join(__dir__, "movies.csv")
8
+
9
+ playlist_1.load(ARGV.shift || movies_file)
9
10
 
10
11
  loop do
11
- puts "\nHow many viewings? ('quit' to exit)"
12
+ print "\nHow many viewings? ('quit' to exit) "
13
+
12
14
  answer = gets.chomp.downcase
15
+
13
16
  case answer
14
17
  when /^\d+$/
15
- playlist.play(answer.to_i)
16
- when 'quit', 'exit'
17
- playlist.print_stats
18
+ playlist_1.play(answer.to_i)
19
+ when "quit", "exit"
20
+ playlist_1.print_stats
18
21
  break
19
22
  else
20
23
  puts "Please enter a number or 'quit'"
21
24
  end
22
25
  end
23
26
 
24
- playlist.save
27
+ playlist_1.save
data/bin/movies.csv CHANGED
@@ -1,3 +1,3 @@
1
- Goonies,10
2
- Ghostbusters,9
3
- Goldfinger,5
1
+ Arrival,10
2
+ Gravity,9
3
+ Interstellar,8
data/lib/flicks/movie.rb CHANGED
@@ -1,54 +1,45 @@
1
- require_relative 'snack_bar'
2
- require_relative 'rankable'
1
+ require_relative "rankable"
3
2
 
4
3
  module Flicks
5
4
  class Movie
6
5
  include Rankable
7
-
6
+
7
+ attr_reader :snacks_eaten
8
8
  attr_accessor :title, :rank
9
9
 
10
- def initialize(title, rank=0)
10
+ def initialize(title, rank = 5)
11
11
  @title = title.capitalize
12
12
  @rank = rank
13
- @snack_carbs = Hash.new(0)
14
- end
15
-
16
- def ate_snack(snack)
17
- @snack_carbs[snack.name] += snack.carbs
18
- puts "#{@title} led to #{snack.carbs} #{snack.name} carbs being consumed."
13
+ @snacks_eaten = Hash.new(0)
19
14
  end
20
-
21
- def carbs_consumed
22
- @snack_carbs.values.reduce(0, :+)
15
+
16
+ def add_snack(name, price)
17
+ @snacks_eaten[name] += price
23
18
  end
24
-
25
- def each_snack
26
- @snack_carbs.each do |name, carbs|
27
- yield Snack.new(name, carbs)
28
- end
19
+
20
+ def total_snack_price
21
+ @snacks_eaten.values.sum
29
22
  end
30
-
31
- def to_s
32
- "#{@title} has a rank of #{@rank} (#{status})"
23
+
24
+ def self.from_csv(line)
25
+ title, rank = line.split(",")
26
+ Movie.new(title, Integer(rank))
27
+ rescue ArgumentError
28
+ puts "Ignored invalid rank: #{rank}"
29
+ Movie.new(title)
33
30
  end
34
-
31
+
35
32
  def to_csv
36
33
  "#{@title},#{@rank}"
37
34
  end
38
-
39
- def self.from_csv(string)
40
- title, rank = string.split(',')
41
- new(title, Integer(rank))
35
+
36
+ def to_s
37
+ "#{@title} has a rank of #{@rank}"
42
38
  end
43
39
  end
44
40
  end
45
41
 
46
42
  if __FILE__ == $0
47
- movie = Flicks::Movie.new("goonies", 10)
48
- puts movie.title
49
- puts movie.rank
50
- movie.thumbs_up
51
- puts movie.rank
52
- movie.thumbs_down
53
- puts movie.rank
43
+ movie = Movie.new("Star Wars", 10)
44
+ puts movie
54
45
  end
@@ -1,30 +1,38 @@
1
- require_relative 'movie'
1
+ require_relative "movie"
2
2
 
3
3
  module Flicks
4
4
  class Movie3D < Movie
5
- attr_reader :wow_factor
6
-
7
- def initialize(name, rank, wow_factor)
8
- super(name, rank)
5
+
6
+ def initialize(title, rank, wow_factor)
7
+ super(title, rank)
9
8
  @wow_factor = wow_factor
10
9
  end
11
-
10
+
11
+ def show_effect
12
+ puts "Wow! " * @wow_factor
13
+ end
14
+
12
15
  def thumbs_up
13
16
  @wow_factor.times { super }
14
17
  end
15
-
16
- def show_effect
17
- puts "Wow! " * @wow_factor
18
- end
18
+
19
19
  end
20
20
  end
21
21
 
22
22
  if __FILE__ == $0
23
- movie3d = Flicks::Movie3D.new('Glee', 5, 10)
24
- movie3d.thumbs_up
25
- puts movie3d.rank
26
- movie3d.thumbs_down
23
+
24
+ movie3d = Movie3D.new("godzilla", 7, 10)
25
+
26
+ puts movie3d.title
27
27
  puts movie3d.rank
28
- puts movie3d
28
+
29
29
  movie3d.show_effect
30
+
31
+ movie3d.thumbs_up
32
+
33
+ puts movie3d
34
+
35
+ puts Movie3D.superclass
36
+
37
+ p Movie3D.ancestors
30
38
  end
@@ -1,78 +1,98 @@
1
- require_relative 'movie'
2
- require_relative 'movie3d'
3
- require_relative 'waldorf_and_statler'
4
- require_relative 'snack_bar'
1
+ require_relative "snackbar"
2
+ require_relative "movie"
5
3
 
6
4
  module Flicks
7
5
  class Playlist
8
- attr_reader :name
9
-
6
+
7
+ attr_reader :name, :movies
8
+
10
9
  def initialize(name)
11
10
  @name = name
12
11
  @movies = []
13
12
  end
14
-
15
- def add_movie(a_movie)
16
- @movies << a_movie
17
- end
18
-
19
- def play(viewings)
20
- puts "#{@name}'s playlist:"
21
13
 
22
- puts @movies.sort
23
-
24
- snacks = SnackBar::SNACKS
25
- puts "\nThere are #{snacks.size} snacks available in the snack bar:"
26
- snacks.each do |snack|
27
- puts "#{snack.name} has #{snack.carbs} carbs"
14
+ def load(from_file)
15
+ File.readlines(from_file, chomp: true).each do |line|
16
+ movie = Movie.from_csv(line)
17
+ add_movie(movie)
28
18
  end
29
-
30
- 1.upto(viewings) do |count|
31
- puts "\nViewing #{count}:"
32
- @movies.each do |movie|
33
- WaldorfAndStatler.review(movie)
34
- snack = SnackBar.random
35
- movie.ate_snack(snack)
36
- puts movie
19
+ rescue Errno::ENOENT
20
+ puts "Whoops, #{from_file} not found!"
21
+ exit 1
22
+ end
23
+
24
+ def save(to_file = "movie_rankings.csv")
25
+ File.open(to_file, "w") do |file|
26
+ sorted_movies.each do |movie|
27
+ file.puts movie.to_csv
37
28
  end
38
29
  end
39
30
  end
40
-
41
- def total_carbs_consumed
42
- @movies.reduce(0) { |sum, movie| sum + movie.carbs_consumed }
31
+
32
+ def add_movie(movie)
33
+ @movies << movie
34
+ end
35
+
36
+ def roll_die
37
+ rand(1..6)
43
38
  end
44
-
39
+
40
+ def sorted_movies
41
+ @movies.sort_by { |movie| movie.rank }.reverse
42
+ end
43
+
45
44
  def print_stats
46
- puts "\n#{@name}'s Stats:"
47
-
48
- hits, flops = @movies.partition {|movie| movie.hit? }
49
-
50
- puts "\nHits:"
51
- puts hits.sort
52
-
53
- puts "\nFlops:"
54
- puts flops.sort
55
-
56
- puts "\n#{total_carbs_consumed} total carbs consumed"
57
- @movies.sort.each do |movie|
58
- puts "\n#{movie.title}'s snack totals:"
59
- movie.each_snack do |snack|
60
- puts "#{snack.carbs} total #{snack.name} carbs"
45
+ puts "\n#{@name}'s Playlist Stats:"
46
+ puts "-" * 30
47
+
48
+ puts sorted_movies
49
+
50
+ @movies.each do |movie|
51
+ puts "\n#{movie.title} snack totals:"
52
+ movie.snacks_eaten.each do |name, total_price|
53
+ puts "#{name}: $#{total_price}"
61
54
  end
62
- puts "#{movie.carbs_consumed} grand total carbs"
55
+ puts "total: $#{movie.total_snack_price}"
63
56
  end
64
57
  end
65
-
66
- def load(from_file)
67
- File.readlines(from_file).each do |line|
68
- add_movie(Movie.from_csv(line))
69
- end
70
- end
71
-
72
- def save(to_file="movie_rankings.csv")
73
- File.open(to_file, "w") do |file|
74
- file.puts @movies.sort.map { |movie| movie.to_csv }
58
+
59
+ def play(viewings = 3)
60
+ puts "*" * 30
61
+ puts "#{@name}'s playlist:"
62
+
63
+ puts "\nThe snackbar has:"
64
+ menu_items = Snackbar.menu_items
65
+ puts menu_items
66
+
67
+ puts "\nBefore watching:"
68
+ puts @movies
69
+
70
+ 1.upto(viewings) do |viewing_number|
71
+ puts "\nViewing #{viewing_number}:"
72
+
73
+ @movies.each do |movie|
74
+ number_rolled = roll_die
75
+
76
+ case number_rolled
77
+ when 1..2
78
+ movie.thumbs_down
79
+ puts "#{movie.title} got a 👎"
80
+ when 3..4
81
+ puts "#{movie.title} got skipped"
82
+ else
83
+ movie.thumbs_up
84
+ puts "#{movie.title} got a 👍"
85
+ end
86
+
87
+ snack = Snackbar.random_snack
88
+ movie.add_snack(snack.name, snack.price)
89
+ puts "During #{movie.title}, #{@name} at #{snack.name} for $#{snack.price}."
90
+ end
75
91
  end
92
+
93
+ puts "\nAfter watching:"
94
+ puts @movies
76
95
  end
96
+
77
97
  end
78
- end
98
+ end
@@ -3,21 +3,9 @@ module Flicks
3
3
  def thumbs_up
4
4
  self.rank += 1
5
5
  end
6
-
6
+
7
7
  def thumbs_down
8
8
  self.rank -= 1
9
9
  end
10
-
11
- def hit?
12
- self.rank >= 10
13
- end
14
-
15
- def status
16
- hit? ? "Hit": "Flop"
17
- end
18
-
19
- def <=>(other)
20
- other.rank <=> self.rank
21
- end
22
10
  end
23
- end
11
+ end
@@ -0,0 +1,21 @@
1
+ module Flicks
2
+ module Snackbar
3
+ Snack = Data.define(:name, :price)
4
+
5
+ SNACKS = [
6
+ Snack.new("popcorn", 3),
7
+ Snack.new("candy", 1),
8
+ Snack.new("nachos", 4),
9
+ Snack.new("pretzels", 2)
10
+ ]
11
+
12
+ def self.random_snack
13
+ SNACKS.sample
14
+ end
15
+
16
+ def self.menu_items
17
+ SNACKS.map { |snack| "#{snack.name} for $#{snack.price}" }
18
+ end
19
+
20
+ end
21
+ end
metadata CHANGED
@@ -1,76 +1,52 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flicks
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
5
- prerelease:
4
+ version: 2.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - The Pragmatic Studio
9
- autorequire:
8
+ autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-02-11 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: rspec
16
- requirement: &70102011883120 !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
22
- type: :development
23
- prerelease: false
24
- version_requirements: *70102011883120
25
- description: ! "This is an example application used in The Pragmatic Studio's \nRuby
26
- Programming course, as described at\n\n http://pragmaticstudio.com\n\nThis code
27
- is Copyright 2012 The Pragmatic Studio. See the LICENSE file."
11
+ date: 2023-07-27 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
28
14
  email: support@pragmaticstudio.com
29
15
  executables:
30
16
  - flicks
31
17
  extensions: []
32
18
  extra_rdoc_files: []
33
19
  files:
20
+ - LICENSE.txt
21
+ - README.md
34
22
  - bin/flicks
35
23
  - bin/movies.csv
36
24
  - lib/flicks/movie.rb
37
25
  - lib/flicks/movie3d.rb
38
26
  - lib/flicks/playlist.rb
39
27
  - lib/flicks/rankable.rb
40
- - lib/flicks/snack_bar.rb
41
- - lib/flicks/waldorf_and_statler.rb
42
- - spec/flicks/movie3d_spec.rb
43
- - spec/flicks/movie_spec.rb
44
- - spec/flicks/playlist_spec.rb
45
- - spec/flicks/snack_bar_spec.rb
46
- - LICENSE
47
- - README
48
- homepage: http://pragmaticstudio.com
49
- licenses: []
50
- post_install_message:
28
+ - lib/flicks/snackbar.rb
29
+ homepage: https://pragmaticstudio.com
30
+ licenses:
31
+ - MIT
32
+ metadata: {}
33
+ post_install_message:
51
34
  rdoc_options: []
52
35
  require_paths:
53
36
  - lib
54
37
  required_ruby_version: !ruby/object:Gem::Requirement
55
- none: false
56
38
  requirements:
57
- - - ! '>='
39
+ - - ">="
58
40
  - !ruby/object:Gem::Version
59
- version: '1.9'
41
+ version: 3.2.0
60
42
  required_rubygems_version: !ruby/object:Gem::Requirement
61
- none: false
62
43
  requirements:
63
- - - ! '>='
44
+ - - ">="
64
45
  - !ruby/object:Gem::Version
65
46
  version: '0'
66
47
  requirements: []
67
- rubyforge_project:
68
- rubygems_version: 1.8.10
69
- signing_key:
70
- specification_version: 3
71
- summary: Plays and reviews movies
72
- test_files:
73
- - spec/flicks/movie3d_spec.rb
74
- - spec/flicks/movie_spec.rb
75
- - spec/flicks/playlist_spec.rb
76
- - spec/flicks/snack_bar_spec.rb
48
+ rubygems_version: 3.4.17
49
+ signing_key:
50
+ specification_version: 4
51
+ summary: A command-line, randomized movie reviewer.
52
+ test_files: []
data/README DELETED
@@ -1,6 +0,0 @@
1
- This is an example application used in The Pragmatic Studio's
2
- Ruby Programming course, as described at
3
-
4
- http://pragmaticstudio.com
5
-
6
- This code is Copyright 2012 The Pragmatic Studio. See the LICENSE file.
@@ -1,22 +0,0 @@
1
- module Flicks
2
- Snack = Struct.new(:name, :carbs)
3
-
4
- module SnackBar
5
- SNACKS = [
6
- Snack.new(:nachos, 40),
7
- Snack.new(:popcorn, 20),
8
- Snack.new(:candy, 15),
9
- Snack.new(:pretzel, 10),
10
- Snack.new(:soda, 5)
11
- ]
12
-
13
- def self.random
14
- SNACKS.sample
15
- end
16
- end
17
- end
18
-
19
- if __FILE__ == $0
20
- puts Flicks::SnackBar::SNACKS
21
- puts Flicks::SnackBar.random
22
- end
@@ -1,20 +0,0 @@
1
- module Flicks
2
- module WaldorfAndStatler
3
- def self.roll_die
4
- rand(1..6)
5
- end
6
-
7
- def self.review(movie)
8
- case roll_die
9
- when 1..2
10
- movie.thumbs_down
11
- puts "#{movie.title} got a thumbs down."
12
- when 3..4
13
- puts "#{movie.title} was skipped."
14
- else
15
- movie.thumbs_up
16
- puts "#{movie.title} got a thumbs up!"
17
- end
18
- end
19
- end
20
- end
@@ -1,35 +0,0 @@
1
- require 'flicks/movie3d'
2
-
3
- module Flicks
4
- describe Movie3D do
5
- before do
6
- @initial_rank = 10
7
- @wow_factor = 5
8
- @movie = Movie3D.new('Glee', @initial_rank, @wow_factor)
9
- end
10
-
11
- it "has a title" do
12
- @movie.title.should == "Glee"
13
- end
14
-
15
- it "has a rank" do
16
- @movie.rank.should == 10
17
- end
18
-
19
- it "has a wow factor" do
20
- @movie.wow_factor.should == 5
21
- end
22
-
23
- it "increases rank by 1 times the wow factor when given a thumbs up" do
24
- @movie.thumbs_up
25
-
26
- @movie.rank.should == @initial_rank + (1 * @wow_factor)
27
- end
28
-
29
- it "decreases rank by 1 when given a thumbs down" do
30
- @movie.thumbs_down
31
-
32
- @movie.rank.should == @initial_rank - 1
33
- end
34
- end
35
- end
@@ -1,124 +0,0 @@
1
- require 'flicks/movie'
2
-
3
- module Flicks
4
- describe Movie do
5
- before do
6
- @initial_rank = 10
7
- @movie = Movie.new("goonies", @initial_rank)
8
- end
9
-
10
- it "has a capitalized title" do
11
- @movie.title.should == "Goonies"
12
- end
13
-
14
- it "has an initial rank" do
15
- @movie.rank.should == 10
16
- end
17
-
18
- it "has a string representation" do
19
- @movie.to_s.should == "Goonies has a rank of 10 (Hit)"
20
- end
21
-
22
- it "increases rank by 1 when given a thumbs up" do
23
- @movie.thumbs_up
24
-
25
- @movie.rank.should == @initial_rank + 1
26
- end
27
-
28
- it "decreases rank by 1 when given a thumbs down" do
29
- @movie.thumbs_down
30
-
31
- @movie.rank.should == @initial_rank - 1
32
- end
33
-
34
- context "created with a default rank" do
35
- before do
36
- @movie = Movie.new("goonies")
37
- end
38
-
39
- it "has a rank of 0" do
40
- @movie.rank.should == 0
41
- end
42
- end
43
-
44
- context "with a rank of at least 10" do
45
- before do
46
- @movie = Movie.new("goonies", 10)
47
- end
48
-
49
- it "is a hit" do
50
- @movie.should be_hit
51
- end
52
-
53
- it "has a hit status" do
54
- @movie.status.should == "Hit"
55
- end
56
- end
57
-
58
- context "with a rank less than 10" do
59
- before do
60
- @movie = Movie.new("goonies", 9)
61
- end
62
-
63
- it "is not a hit" do
64
- @movie.should_not be_hit
65
- end
66
-
67
- it "has a flop status" do
68
- @movie.status.should == "Flop"
69
- end
70
- end
71
-
72
- it "is sorted by decreasing rank" do
73
- movie1 = Movie.new("goonies", 100)
74
- movie2 = Movie.new("ghostbusters", 200)
75
- movie3 = Movie.new("goldfinger", 300)
76
-
77
- movies = [movie1, movie2, movie3]
78
-
79
- movies.sort.should == [movie3, movie2, movie1]
80
- end
81
-
82
- it "computes carbs consumed as the sum of all snack carbs consumed" do
83
- @movie.carbs_consumed.should == 0
84
-
85
- @movie.ate_snack(Snack.new(:popcorn, 10))
86
-
87
- @movie.carbs_consumed.should == 10
88
-
89
- @movie.ate_snack(Snack.new(:popcorn, 10))
90
-
91
- @movie.carbs_consumed.should == 20
92
-
93
- @movie.ate_snack(Snack.new(:soda, 5))
94
-
95
- @movie.carbs_consumed.should == 25
96
- end
97
-
98
- it "yields each snack" do
99
- @movie.ate_snack(Snack.new(:popcorn, 10))
100
- @movie.ate_snack(Snack.new(:popcorn, 10))
101
- @movie.ate_snack(Snack.new(:soda, 5))
102
-
103
- yielded = []
104
- @movie.each_snack do |snack|
105
- yielded << snack
106
- end
107
-
108
- yielded.should == [Snack.new(:popcorn, 20), Snack.new(:soda, 5)]
109
- end
110
-
111
- it "can be instantiated from a CSV string" do
112
- movie = Movie.from_csv("goonies,10")
113
-
114
- movie.title.should == "Goonies"
115
- movie.rank.should == 10
116
- end
117
-
118
- it "can be serialized to a CSV string" do
119
- movie = Movie.new("Goonies", 10)
120
-
121
- movie.to_csv.should == "Goonies,10"
122
- end
123
- end
124
- end
@@ -1,82 +0,0 @@
1
- require 'flicks/playlist'
2
-
3
- module Flicks
4
- describe Playlist do
5
- before do
6
- @playlist = Playlist.new("Kermit")
7
- end
8
-
9
- it "has a name" do
10
- @playlist.name.should == "Kermit"
11
- end
12
-
13
- context "being played with one movie" do
14
- before do
15
- @initial_rank = 10
16
- @movie = Movie.new("Goonies", @initial_rank)
17
-
18
- @playlist.add_movie(@movie)
19
- end
20
-
21
- it "gives the movie a thumbs up if a high number is rolled" do
22
- WaldorfAndStatler.stub(:roll_die).and_return(6)
23
-
24
- @playlist.play(2)
25
-
26
- @movie.rank.should == @initial_rank + 2
27
-
28
- WaldorfAndStatler.stub(:roll_die).and_return(5)
29
-
30
- @playlist.play(2)
31
-
32
- @movie.rank.should == @initial_rank + 4
33
- end
34
-
35
- it "skips the movie if a medium number is rolled" do
36
- WaldorfAndStatler.stub(:roll_die).and_return(4)
37
-
38
- @playlist.play(2)
39
-
40
- @movie.rank.should == @initial_rank
41
-
42
- WaldorfAndStatler.stub(:roll_die).and_return(3)
43
-
44
- @playlist.play(2)
45
-
46
- @movie.rank.should == @initial_rank
47
- end
48
-
49
- it "gives the movie a thumbs down if a low number is rolled" do
50
- WaldorfAndStatler.stub(:roll_die).and_return(2)
51
-
52
- @playlist.play(2)
53
-
54
- @movie.rank.should == @initial_rank - 2
55
-
56
- WaldorfAndStatler.stub(:roll_die).and_return(1)
57
-
58
- @playlist.play(2)
59
-
60
- @movie.rank.should == @initial_rank - 4
61
- end
62
- end
63
-
64
- context "with movies that have caused snacks to be consumed" do
65
- before do
66
- movie1 = Movie.new("goonies")
67
- movie2 = Movie.new("ghostbusters")
68
-
69
- @playlist.add_movie(movie1)
70
- @playlist.add_movie(movie2)
71
-
72
- movie1.ate_snack(Snack.new(:popcorn, 10))
73
- movie1.ate_snack(Snack.new(:popcorn, 10))
74
- movie2.ate_snack(Snack.new(:soda, 5))
75
- end
76
-
77
- it "computes total carbs consumed as the sum of all movie carbs consumed" do
78
- @playlist.total_carbs_consumed.should == 25
79
- end
80
- end
81
- end
82
- end
@@ -1,31 +0,0 @@
1
- require 'flicks/snack_bar'
2
-
3
- module Flicks
4
- describe Snack do
5
- before do
6
- @snack = Snack.new(:pretzel, 10)
7
- end
8
-
9
- it "has a name attribute" do
10
- @snack.name.should == :pretzel
11
- end
12
-
13
- it "has a carbs attribute" do
14
- @snack.carbs.should == 10
15
- end
16
-
17
- end
18
-
19
- describe SnackBar do
20
-
21
- it "has a trove of treasures" do
22
- SnackBar::SNACKS.should_not be_empty
23
- end
24
-
25
- it "returns a random treasure" do
26
- snack = SnackBar.random
27
-
28
- SnackBar::SNACKS.should include(snack)
29
- end
30
- end
31
- end