Commit 940c8c0

mo k <mo@mokhan.ca>
2012-08-12 23:30:53
create command processor.
1 parent 5253193
lib/command_processor.rb
@@ -0,0 +1,13 @@
+class CommandProcessor
+  def initialize
+    @commands = []
+  end
+  def add(command)
+    @commands << command
+  end
+  def run
+    while @commands.length > 0 do
+      @commands.shift.run
+    end
+  end
+end
spec/unit/command_processor_spec.rb
@@ -0,0 +1,29 @@
+require "spec_helper"
+
+describe CommandProcessor do
+  let(:sut) {CommandProcessor.new }
+
+  context "when run" do
+    let(:first_command) { fake }
+    let(:second_command) { fake }
+    it "should run each command added to the queue" do
+      first_command.should have_received(:run)
+      second_command.should have_received(:run)
+    end
+    before(:each) do
+      sut.add(first_command)
+      sut.add(second_command)
+      sut.run
+    end
+    describe "when run again" do
+      it "should have nothing to run" do
+        first_command.should have_received(:run).once
+        first_command.should have_received(:run).once
+        second_command.should have_received(:run).once
+      end
+      before(:each) do
+        sut.run
+      end
+    end
+  end
+end