statemachine 1.2.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (141) hide show
  1. data/.gitignore +12 -0
  2. data/Gemfile +6 -0
  3. data/Gemfile.lock +12 -0
  4. data/Rakefile +21 -20
  5. data/doc/website/README +6 -0
  6. data/doc/website/config.yaml +2 -0
  7. data/doc/website/index.html +39 -0
  8. data/doc/website/src/default.css +110 -0
  9. data/doc/website/src/default.template +41 -0
  10. data/doc/website/src/documentation.page +45 -0
  11. data/doc/website/src/example.page +13 -0
  12. data/doc/website/src/example1.page +59 -0
  13. data/doc/website/src/example2.page +96 -0
  14. data/doc/website/src/example3.page +76 -0
  15. data/doc/website/src/example4.page +65 -0
  16. data/doc/website/src/images/8l_star.png +0 -0
  17. data/doc/website/src/images/bg.png +0 -0
  18. data/doc/website/src/images/bottom_border.png +0 -0
  19. data/doc/website/src/images/bottom_edge.png +0 -0
  20. data/doc/website/src/images/examples/vending_machine.png +0 -0
  21. data/doc/website/src/images/examples/vending_machine2.png +0 -0
  22. data/doc/website/src/images/examples/vending_machine3.png +0 -0
  23. data/doc/website/src/images/examples/vending_machine4a.png +0 -0
  24. data/doc/website/src/images/examples/vending_machine4b.png +0 -0
  25. data/doc/website/src/images/left_edge.png +0 -0
  26. data/doc/website/src/images/logo.png +0 -0
  27. data/doc/website/src/images/right_edge.png +0 -0
  28. data/doc/website/src/images/side_borders.png +0 -0
  29. data/doc/website/src/index.page +20 -0
  30. data/generate_tests/dot_graph/turnstile.rb +29 -0
  31. data/generate_tests/dot_graph/turnstile2.rb +48 -0
  32. data/generate_tests/java/turnstile.rb +54 -0
  33. data/generate_tests/java/turnstile2.rb +72 -0
  34. data/lib/statemachine/action_invokation.rb +0 -19
  35. data/lib/statemachine/version.rb +2 -2
  36. data/rails_plugin/README +183 -0
  37. data/rails_plugin/Rakefile +11 -0
  38. data/rails_plugin/app/controllers/admin_controller.rb +43 -0
  39. data/rails_plugin/app/controllers/application.rb +7 -0
  40. data/rails_plugin/app/controllers/main_controller.rb +34 -0
  41. data/rails_plugin/app/helpers/admin_helper.rb +2 -0
  42. data/rails_plugin/app/helpers/application_helper.rb +3 -0
  43. data/rails_plugin/app/helpers/main_helper.rb +7 -0
  44. data/rails_plugin/app/models/product.rb +21 -0
  45. data/rails_plugin/app/models/vending_machine.rb +36 -0
  46. data/rails_plugin/app/models/vending_machine_interface.rb +101 -0
  47. data/rails_plugin/app/models/vending_statemachine.rb +41 -0
  48. data/rails_plugin/app/views/admin/index.rhtml +45 -0
  49. data/rails_plugin/app/views/layouts/main.rhtml +12 -0
  50. data/rails_plugin/app/views/main/_info.rhtml +13 -0
  51. data/rails_plugin/app/views/main/event.rjs +27 -0
  52. data/rails_plugin/app/views/main/index.rhtml +38 -0
  53. data/rails_plugin/config/boot.rb +45 -0
  54. data/rails_plugin/config/database.yml +21 -0
  55. data/rails_plugin/config/environment.rb +60 -0
  56. data/rails_plugin/config/environments/development.rb +21 -0
  57. data/rails_plugin/config/environments/production.rb +18 -0
  58. data/rails_plugin/config/environments/test.rb +19 -0
  59. data/rails_plugin/config/routes.rb +23 -0
  60. data/rails_plugin/db/migrate/001_create_vending_machines.rb +12 -0
  61. data/rails_plugin/db/migrate/002_create_products.rb +14 -0
  62. data/rails_plugin/db/migrate/003_add_position_to_products.rb +9 -0
  63. data/rails_plugin/db/schema.rb +20 -0
  64. data/rails_plugin/doc/README_FOR_APP +2 -0
  65. data/rails_plugin/lib/tasks/base.rake +5 -0
  66. data/rails_plugin/public/.htaccess +40 -0
  67. data/rails_plugin/public/404.html +30 -0
  68. data/rails_plugin/public/500.html +30 -0
  69. data/rails_plugin/public/dispatch.cgi +10 -0
  70. data/rails_plugin/public/dispatch.fcgi +24 -0
  71. data/rails_plugin/public/dispatch.rb +10 -0
  72. data/rails_plugin/public/favicon.ico +0 -0
  73. data/rails_plugin/public/images/bricks.jpg +0 -0
  74. data/rails_plugin/public/images/cash_release_button.png +0 -0
  75. data/rails_plugin/public/images/change.png +0 -0
  76. data/rails_plugin/public/images/dime.png +0 -0
  77. data/rails_plugin/public/images/dollar.png +0 -0
  78. data/rails_plugin/public/images/money_panel.png +0 -0
  79. data/rails_plugin/public/images/nickel.png +0 -0
  80. data/rails_plugin/public/images/quarter.png +0 -0
  81. data/rails_plugin/public/images/rails.png +0 -0
  82. data/rails_plugin/public/images/vending_machine_body.png +0 -0
  83. data/rails_plugin/public/index.html +277 -0
  84. data/rails_plugin/public/javascripts/application.js +2 -0
  85. data/rails_plugin/public/javascripts/controls.js +833 -0
  86. data/rails_plugin/public/javascripts/dragdrop.js +942 -0
  87. data/rails_plugin/public/javascripts/effects.js +1088 -0
  88. data/rails_plugin/public/javascripts/prototype.js +2515 -0
  89. data/rails_plugin/public/robots.txt +1 -0
  90. data/rails_plugin/public/stylesheets/layout.css +163 -0
  91. data/rails_plugin/script/about +3 -0
  92. data/rails_plugin/script/breakpointer +3 -0
  93. data/rails_plugin/script/console +3 -0
  94. data/rails_plugin/script/destroy +3 -0
  95. data/rails_plugin/script/generate +3 -0
  96. data/rails_plugin/script/performance/benchmarker +3 -0
  97. data/rails_plugin/script/performance/profiler +3 -0
  98. data/rails_plugin/script/plugin +3 -0
  99. data/rails_plugin/script/process/inspector +3 -0
  100. data/rails_plugin/script/process/reaper +3 -0
  101. data/rails_plugin/script/process/spawner +3 -0
  102. data/rails_plugin/script/rails_spec +11 -0
  103. data/rails_plugin/script/rails_spec_server +43 -0
  104. data/rails_plugin/script/runner +3 -0
  105. data/rails_plugin/script/server +3 -0
  106. data/rails_plugin/spec/controllers/admin_controller_spec.rb +7 -0
  107. data/rails_plugin/spec/controllers/main_controller_spec.rb +38 -0
  108. data/rails_plugin/spec/fixtures/products.yml +2 -0
  109. data/rails_plugin/spec/fixtures/vending_machines.yml +2 -0
  110. data/rails_plugin/spec/helpers/admin_helper_spec.rb +5 -0
  111. data/rails_plugin/spec/helpers/main_helper_spec.rb +5 -0
  112. data/rails_plugin/spec/models/product_spec.rb +16 -0
  113. data/rails_plugin/spec/models/vending_machine_interface_spec.rb +168 -0
  114. data/rails_plugin/spec/models/vending_machine_spec.rb +30 -0
  115. data/rails_plugin/spec/models/vending_statemachine_spec.rb +130 -0
  116. data/rails_plugin/spec/plugins/context_support_spec.rb +28 -0
  117. data/rails_plugin/spec/plugins/controller_support_spec.rb +98 -0
  118. data/rails_plugin/spec/spec.opts +1 -0
  119. data/rails_plugin/spec/spec_helper.rb +28 -0
  120. data/rails_plugin/spec/views/main/event_spec.rb +61 -0
  121. data/rails_plugin/vendor/plugins/statemachine/README +4 -0
  122. data/rails_plugin/vendor/plugins/statemachine/Rakefile +22 -0
  123. data/rails_plugin/vendor/plugins/statemachine/init.rb +2 -0
  124. data/rails_plugin/vendor/plugins/statemachine/install.rb +1 -0
  125. data/rails_plugin/vendor/plugins/statemachine/lib/context_support.rb +22 -0
  126. data/rails_plugin/vendor/plugins/statemachine/lib/controller_support.rb +85 -0
  127. data/rails_plugin/vendor/plugins/statemachine/lib/statemachine_on_rails.rb +11 -0
  128. data/rails_plugin/vendor/plugins/statemachine/tasks/statemachine_tasks.rake +4 -0
  129. data/spec/action_invokation_spec.rb +1 -1
  130. data/spec/builder_spec.rb +1 -1
  131. data/spec/default_transition_spec.rb +1 -1
  132. data/spec/generate/dot_graph/dot_graph_stagemachine_spec.rb +1 -1
  133. data/spec/history_spec.rb +1 -1
  134. data/spec/sm_action_parameterization_spec.rb +1 -1
  135. data/spec/sm_entry_exit_actions_spec.rb +1 -1
  136. data/spec/sm_odds_n_ends_spec.rb +1 -1
  137. data/spec/sm_simple_spec.rb +1 -1
  138. data/spec/sm_super_state_spec.rb +1 -1
  139. data/spec/sm_turnstile_spec.rb +1 -1
  140. data/spec/transition_spec.rb +1 -1
  141. metadata +162 -46
@@ -0,0 +1 @@
1
+ # See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
@@ -0,0 +1,163 @@
1
+ body {
2
+ padding: 0px;
3
+ background-image: url('../images/bricks.jpg');
4
+ font-family: "Lucida Grande", "Bitstream Vera Sans", "Verdana";
5
+ font-size: 13px;
6
+ }
7
+
8
+ #vending_machine_body {
9
+ position: absolute;
10
+ top: 0px;
11
+ left: 50px;
12
+ z-index: 1;
13
+ }
14
+
15
+ #money_panel {
16
+ position: absolute;
17
+ top: 100px;
18
+ left: 353px;
19
+ z-index: 2;
20
+ }
21
+
22
+ #cash_release_button {
23
+ position: absolute;
24
+ top: 197px;
25
+ left: 442px;
26
+ border: none;
27
+ z-index: 3;
28
+ }
29
+
30
+ #quartz_screen {
31
+ position: absolute;
32
+ top: 115px;
33
+ left: 359px;
34
+ width: 115px;
35
+ height: 32px;
36
+ text-align: right;
37
+ font-size: 12pt;
38
+ color: #64F847;
39
+ z-index: 100;
40
+ }
41
+
42
+ #dispenser {
43
+ position: absolute;
44
+ top: 577px;
45
+ left: 133px;
46
+ width: 142px;
47
+ height: 70px;
48
+ text-align: center;
49
+ font-size: 12pt;
50
+ z-index: 100;
51
+ }
52
+
53
+ #dispenser p {
54
+ border: 1px solid red;
55
+ margin: 20px 10px 0px 10px;
56
+ padding: 5px;
57
+ background-color: black;
58
+ color: red;
59
+ }
60
+
61
+ #product_list {
62
+ position: absolute;
63
+ top: 235px;
64
+ left: 355px;
65
+ width: 125px;
66
+ height: 440px;
67
+ text-align: center;
68
+ z-index: 100;
69
+ }
70
+
71
+ #product_list a {
72
+ display: block;
73
+ margin: 5px;
74
+ padding: 5px;
75
+ color: black;
76
+ text-decoration: none;
77
+ }
78
+
79
+ #product_list a:hover {
80
+ color: blue;
81
+ background-color: grey;
82
+ }
83
+
84
+
85
+ .non_affordable {
86
+ border: 1px solid black;
87
+ background-color: lightgrey;
88
+ }
89
+
90
+ .affordable {
91
+ border: 1px solid green;
92
+ background-color: lightgreen;
93
+ }
94
+
95
+ #info {
96
+ position: absolute;
97
+ top: 275px;
98
+ left: 525px;
99
+ width: 250px;
100
+ padding: 10px;
101
+ border: 1px solid black;
102
+ z-index: 100;
103
+ }
104
+
105
+ #cash {
106
+ position: absolute;
107
+ top: 50px;
108
+ left: 525px;
109
+ width: 250px;
110
+ padding: 10px;
111
+ border: 1px solid black;
112
+ text-align: center;
113
+ z-index: 100;
114
+ }
115
+
116
+ #links {
117
+ position: absolute;
118
+ top: 25px;
119
+ height: 20px;
120
+ left: 525px;
121
+ width: 250px;
122
+ text-align: center;
123
+ z-index: 2;
124
+ }
125
+
126
+ h3 {
127
+ text-align: center;
128
+ margin: 5px;
129
+ font-size: 20pt;
130
+ }
131
+
132
+ .money_active {
133
+ background-color: yellow;
134
+ }
135
+
136
+ #change {
137
+ position: absolute;
138
+ top: 681px;
139
+ left: 362px;
140
+ z-index: 2;
141
+ }
142
+
143
+ #change_amount {
144
+ position: absolute;
145
+ top: 681px;
146
+ left: 362px;
147
+ width: 109px;
148
+ height: 74px;
149
+ z-index: 100;
150
+ text-align: center;
151
+ }
152
+
153
+ #change_amount p {
154
+ border: 1px solid #64F847;
155
+ margin: 20px 10px 0px 10px;
156
+ padding: 5px;
157
+ background-color: black;
158
+ color: #64F847;
159
+ }
160
+
161
+ th {
162
+ text-align: left;
163
+ }
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../config/boot'
3
+ require 'commands/about'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../config/boot'
3
+ require 'commands/breakpointer'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../config/boot'
3
+ require 'commands/console'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../config/boot'
3
+ require 'commands/destroy'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../config/boot'
3
+ require 'commands/generate'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../../config/boot'
3
+ require 'commands/performance/benchmarker'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../../config/boot'
3
+ require 'commands/performance/profiler'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../config/boot'
3
+ require 'commands/plugin'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../../config/boot'
3
+ require 'commands/process/inspector'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../../config/boot'
3
+ require 'commands/process/reaper'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../../config/boot'
3
+ require 'commands/process/spawner'
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "drb/drb"
4
+
5
+ begin
6
+ DRb.start_service
7
+ rails_spec_server = DRbObject.new_with_uri("druby://localhost:8989")
8
+ rails_spec_server.run(ARGV, STDERR, STDOUT)
9
+ rescue DRb::DRbConnError
10
+ puts "No rails_spec_server is running. Please start one via 'script/rails_spec_server'"
11
+ end
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../../rspec/lib' # For svn
3
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../vendor/plugins/rspec/lib' # For rspec installed as plugin
4
+ require 'rubygems'
5
+ require 'drb/drb'
6
+ require 'rbconfig'
7
+ require 'spec'
8
+
9
+ module Spec
10
+ module Runner
11
+ class RailsSpecServer
12
+ def run(args, stderr, stdout)
13
+ $stdout = stdout
14
+ $stderr = stderr
15
+
16
+ ::Dispatcher.reset_application!
17
+ ::Dependencies.mechanism = :load
18
+ require_dependency('application.rb') unless Object.const_defined?(:ApplicationController)
19
+ load File.dirname(__FILE__) + '/../spec/spec_helper.rb'
20
+
21
+ ::Spec::Runner::CommandLine.run(args, stderr, stdout, false, true)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ puts "Loading Rails environment"
27
+
28
+ ENV["RAILS_ENV"] = "test"
29
+ require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
30
+ require 'dispatcher'
31
+
32
+ def restart_test_server
33
+ puts "restarting"
34
+ config = ::Config::CONFIG
35
+ ruby = File::join(config['bindir'], config['ruby_install_name']) + config['EXEEXT']
36
+ command_line = [ruby, $0, ARGV].flatten.join(' ')
37
+ exec(command_line)
38
+ end
39
+
40
+ trap("USR2") { restart_test_server } if Signal.list.has_key?("USR2")
41
+ puts "Ready"
42
+ DRb.start_service("druby://localhost:8989", Spec::Runner::RailsSpecServer.new)
43
+ DRb.thread.join
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../config/boot'
3
+ require 'commands/runner'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../config/boot'
3
+ require 'commands/server'
@@ -0,0 +1,7 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "The AdminController" do
4
+ # fixtures :admins
5
+ controller_name :admin
6
+
7
+ end
@@ -0,0 +1,38 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "The MainController" do
4
+ controller_name :main
5
+
6
+ end
7
+
8
+ describe "Index View spec" do
9
+ controller_name :main
10
+ integrate_views
11
+
12
+ before(:each) do
13
+ @vm = VendingMachine.new
14
+ @product = @vm.add_product(10, "Glue", 100)
15
+ @vm.save!
16
+
17
+ post :index, :id => @vm.id
18
+ end
19
+
20
+ it "Has required divs" do
21
+ response.should have_tag(:img, :attributes)=> { :id => "vending_machine_body" }
22
+ response.should have_tag(:img, :attributes)=> { :id => "money_panel" }
23
+ response.should have_tag(:a, :attributes)=> { :id => "cash_release_button" }
24
+ response.should have_tag(:div, :attributes)=> { :id => "product_list" }
25
+ response.should have_tag(:img, :attributes)=> { :id => "change" }
26
+ response.should have_tag(:div, :attributes)=> { :id => "change_amount" }
27
+ response.should have_tag(:div, :attributes)=> { :id => "cash" }
28
+ response.should have_tag(:div, :attributes)=> { :id => "quartz_screen" }
29
+ response.should have_tag(:div, :attributes)=> { :id => "dispenser" }
30
+ response.should have_tag(:div, :attributes)=> { :id => "info" }
31
+ end
32
+
33
+ it "products" do
34
+ response.should have_tag(:a, :attributes)=> { :id => "product_#{@product.id}" }
35
+ response.should have_tag(:span, :attributes)=> { :id => "product_#{@product.id}_price" }
36
+ end
37
+
38
+ end
@@ -0,0 +1,2 @@
1
+ # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2
+
@@ -0,0 +1,2 @@
1
+ # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2
+
@@ -0,0 +1,5 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "The AdminHelper" do
4
+ helper_name :admin
5
+ end
@@ -0,0 +1,5 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "The MainHelper" do
4
+ helper_name :main
5
+ end
@@ -0,0 +1,16 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "Product class with fixtures loaded" do
4
+ fixtures :products
5
+
6
+ it "Saved with name and price" do
7
+ saved = Product.new(:name => "Water", :price => 150)
8
+ saved.save!
9
+
10
+ loaded = Product.find(saved.id)
11
+ loaded.name.should eql("Water")
12
+ loaded.price.should equal 150
13
+ end
14
+
15
+
16
+ end
@@ -0,0 +1,168 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "Vending Machine Interface" do
4
+
5
+ before(:each) do
6
+ @display = VendingMachineInterface.new
7
+ @vm = VendingMachine.new
8
+ @water = @vm.add_product(10, "Water", 100)
9
+ @tea = @vm.add_product(10, "Tea", 125)
10
+ @chocolate = @vm.add_product(10, "Chocolate", 135)
11
+ @danish = @vm.add_product(10, "Danish", 140)
12
+ @display.vending_machine = @vm
13
+ end
14
+
15
+ it "message" do
16
+ @display.message.should eql("Insert Money")
17
+ @display.add_dollar
18
+ @display.message.should eql(")$1.00"
19
+ @display.add_quarter
20
+ @display.message.should eql(")$1.25"
21
+ @display.add_dime
22
+ @display.message.should eql(")$1.35"
23
+ @display.add_nickel
24
+ @display.message.should eql(")$1.40"
25
+ end
26
+
27
+ it "message when refusing money" do
28
+ @display.add_dollar
29
+ @display.refuse_money
30
+ @display.message.should eql("Select Item")
31
+ end
32
+
33
+ it "available items" do
34
+ @display.affordable_items.should eql []
35
+ @display.non_affordable_items.should eql [@water, @tea, @chocolate, @danish]
36
+
37
+ @display.add_dollar
38
+ @display.affordable_items.should eql [@water]
39
+ @display.non_affordable_items.should eql [@tea, @chocolate, @danish]
40
+
41
+ @display.add_quarter
42
+ @display.affordable_items.should eql [@water, @tea]
43
+ @display.non_affordable_items.should eql [@chocolate, @danish]
44
+
45
+ @display.add_dime
46
+ @display.affordable_items.should eql [@water, @tea, @chocolate]
47
+ @display.non_affordable_items.should eql [@danish]
48
+
49
+ @display.add_nickel
50
+ @display.affordable_items.should eql [@water, @tea, @chocolate, @danish]
51
+ @display.non_affordable_items.should eql []
52
+ end
53
+
54
+ it "sold out items" do
55
+ @display.sold_out_items.should eql []
56
+ @water.inventory = 0
57
+ @display.sold_out_items.should eql [@water]
58
+ @danish.inventory = 0
59
+ @display.sold_out_items.should eql [@water, @danish]
60
+
61
+ @display.add_dollar
62
+ @display.add_quarter
63
+ @display.affordable_items.should eql [@tea]
64
+ @display.non_affordable_items.should eql [@chocolate]
65
+ end
66
+
67
+ it "dispense change" do
68
+ @display.add_dollar
69
+ @display.dispense_change
70
+
71
+ @display.amount_tendered.should equal 0
72
+ @display.change.should eql(")$1.00"
73
+ end
74
+
75
+ end
76
+
77
+
78
+ describe "Vending Machine Display Spec" do
79
+
80
+ before(:each) do
81
+ @display = VendingMachineInterface.new
82
+ @sm = mock("vending statemachine")
83
+ @display.statemachine = @sm
84
+
85
+ @vending_machine = VendingMachine.new
86
+ @milk = @vending_machine.add_product(10, "Milk", 100)
87
+ @whiskey = @vending_machine.add_product(10, "Whiskey", 200)
88
+ @vending_machine.save!
89
+
90
+ @display.vending_machine = @vending_machine
91
+ end
92
+
93
+ it "start state" do
94
+ @display.amount_tendered.should equal 0
95
+ @display.accepting_money.should equal true
96
+ end
97
+
98
+ it "dollar" do
99
+ @display.add_dollar
100
+ @display.amount_tendered.should equal 100
101
+ @display.accepting_money.should equal true
102
+ end
103
+
104
+ it "quarter" do
105
+ @display.add_quarter
106
+ @display.amount_tendered.should equal 25
107
+ @display.accepting_money.should equal true
108
+ end
109
+
110
+ it "dime" do
111
+ @display.add_dime
112
+ @display.amount_tendered.should equal 10
113
+ @display.accepting_money.should equal true
114
+ end
115
+
116
+ it "nickel" do
117
+ @display.add_nickel
118
+ @display.amount_tendered.should equal 5
119
+ @display.accepting_money.should equal true
120
+ end
121
+
122
+ it "dollar when max price is a dollar" do
123
+ @display.refuse_money
124
+ @display.accepting_money.should equal false
125
+ end
126
+
127
+ it "make sale" do
128
+ @display.add_dollar
129
+ @display.load_product(@milk.id)
130
+ @display.make_sale
131
+
132
+ @display.amount_tendered.should equal 0
133
+ @display.dispensed_item.name.should eql("Milk")
134
+ @display.change.should eql(")$0.00"
135
+ Product.find(@milk.id).inventory.should equal 9
136
+ @vending_machine.cash.should equal 100
137
+ end
138
+
139
+ it "check affordability with inssuficient funds" do
140
+ @display.add_dollar
141
+ @display.load_product(@whiskey.id)
142
+
143
+ @sm.should_receive(:refuse_purchase)
144
+ @display.check_affordability
145
+ end
146
+
147
+ it "check affordability with suficient funds" do
148
+ @display.add_dollar
149
+ @display.add_dollar
150
+ @display.load_product(@whiskey.id)
151
+
152
+ @sm.should_receive(:accept_purchase)
153
+ @display.check_affordability
154
+ end
155
+
156
+ it "check affordability with inssuficient funds" do
157
+ @whiskey.inventory = 0
158
+ @whiskey.save!
159
+
160
+ @display.add_dollar
161
+ @display.add_dollar
162
+ @display.load_product(@whiskey.id)
163
+
164
+ @sm.should_receive(:refuse_purchase)
165
+ @display.check_affordability
166
+ end
167
+
168
+ end