Skip to content

Commit

Permalink
added integration test of drawer in features as an example
Browse files Browse the repository at this point in the history
  • Loading branch information
rwestgeest committed Oct 10, 2011
1 parent 58349e5 commit 353aa64
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 8 deletions.
11 changes: 9 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ desc 'Running all unit tests'
task :default => :test

desc "run feature tests"
Cucumber::Rake::Task.new(:features => :test) do |t|
Cucumber::Rake::Task.new(:features => :deploy) do |t|
t.cucumber_opts = "--format pretty"
end

Expand All @@ -26,9 +26,16 @@ task :coverage do
system("#{rcov} --html test/*test.rb")
end

desc 'run commands'
task :run_commands => :deploy do
require 'lib/command_processor'
CommandProcessor.client.test
end

desc 'deploy code to machine'
task :deploy do
task :deploy => :test do
deploy_code
sleep(1)
end

PACKAGE = 'controlcode.pkg'
Expand Down
8 changes: 4 additions & 4 deletions features/deliver_can.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Feature:
I want have a can of soda delivered
So that i can fix my thirst

Scenario: Deliver for free
Given a machine with cola and sprite
When I choos cola
Then A can of cola is delivered
Scenario: Drop a can (to show how you use the features remotely)
Given a machine
When drawer 0 drops a can
Then it is received by the bin
17 changes: 17 additions & 0 deletions features/step_definitions/deliver_can_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'command_processor'
require 'test/unit/assertions'
include Test::Unit::Assertions
Given /^a machine$/ do
@machine = CommandProcessor.client
end

When /^drawer (\d+) drops a can$/ do |arg1|
@machine.clear_bin_events
@machine.drop_can_from_drawer(arg1.to_i)
end

Then /^it is received by the bin$/ do
sleep(3)
assert @machine.bin_has_received_something
end

13 changes: 13 additions & 0 deletions lib/command_processor.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require 'drb'
module CommandProcessor
URI = "druby://localhost:14567"

def self.run_server(commands)
DRb.start_service(URI,commands)
end

def self.client
DRbObject.new(nil, URI)
end
end

23 changes: 23 additions & 0 deletions lib/control/remote_commands.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require 'devices'
require 'device_wrappers'
module Control

class RemoteCommands
include VMLog
def test
log "works"
end

def clear_bin_events
@bin = PhyscalBin.new
end

def drop_can_from_drawer(drawer)
PhysicalDrawer.new(drawer).drop_can
end

def bin_has_received_something
!@bin.empty?
end
end
end
2 changes: 2 additions & 0 deletions lib/device_wrappers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require 'device_wrappers/bin'
require 'device_wrappers/drawer'
12 changes: 12 additions & 0 deletions lib/device_wrappers/bin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class PhyscalBin
def initialize
@events_received = 0
Devices.on_bin_entry do
@events_received += 1
end
end
def empty?
@events_received == 0
end
end

10 changes: 10 additions & 0 deletions lib/device_wrappers/drawer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class PhysicalDrawer
def initialize(drawer_no)
@drawer_no = drawer_no
end
def drop_can
Devices.drawer_drop_can(@drawer_no)
end
end


8 changes: 6 additions & 2 deletions lib/main.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
require "vmlog"
require 'devices'
require 'command_processor'
require 'control/remote_commands'
require 'control/vending_machine'

module Control
include VMLog

extend VMLog
def self.main
# here, you should load your vending machine control software
CommandProcessor.run_server(RemoteCommands.new)

# as an example of using the actuators and sensors (see doc/actuators_and_sensors)
Devices.display_show(0, 'Choose')
Expand Down

0 comments on commit 353aa64

Please sign in to comment.