Commit 0ca2c64
Changed files (4)
lib
spec
unit
lib/nasty/command.rb
@@ -1,17 +1,7 @@
-module Command
- def then(next_command)
- CompositeCommand.new(self, next_command)
- end
-end
-
-class CompositeCommand
- def initialize(first, last)
- @first = first
- @last = last
- end
-
- def run(*args)
- @first.run(*args)
- @last.run(*args)
+module Nasty
+ module Command
+ def then(next_command)
+ CompositeCommand.new(self, next_command)
+ end
end
end
lib/nasty/composite_command.rb
@@ -0,0 +1,13 @@
+module Nasty
+ class CompositeCommand
+ def initialize(first, last)
+ @first = first
+ @last = last
+ end
+
+ def run(*args)
+ @first.run(*args)
+ @last.run(*args)
+ end
+ end
+end
lib/nasty.rb
@@ -1,4 +1,5 @@
require "nasty/command"
+require "nasty/composite_command"
require "nasty/version"
module Nasty
spec/unit/command_spec.rb
@@ -1,45 +1,47 @@
require "spec_helper"
-describe Command do
- class SimpleCommand
- include Command
- def run; @ran = true; end
- def ran?; @ran; end
- end
+module Nasty
+ describe Command do
+ class SimpleCommand
+ include Command
+ def run; @ran = true; end
+ def ran?; @ran; end
+ end
- class ComplexCommand < SimpleCommand
- attr_accessor :arguments
+ class ComplexCommand < SimpleCommand
+ attr_accessor :arguments
- def run(*args)
- super()
- self.arguments = args
+ def run(*args)
+ super()
+ self.arguments = args
+ end
end
- end
- context "without parameters" do
- let(:first_command) { SimpleCommand.new }
- let(:second_command) { SimpleCommand.new }
+ context "without parameters" do
+ let(:first_command) { SimpleCommand.new }
+ let(:second_command) { SimpleCommand.new }
- it "chains two commands together" do
- result = first_command.then(second_command)
- result.run
- first_command.ran?.should be_true
- second_command.ran?.should be_true
+ it "chains two commands together" do
+ result = first_command.then(second_command)
+ result.run
+ first_command.ran?.should be_true
+ second_command.ran?.should be_true
+ end
end
- end
- context "with parameters" do
- let(:first_command) { ComplexCommand.new }
- let(:second_command) { ComplexCommand.new }
+ context "with parameters" do
+ let(:first_command) { ComplexCommand.new }
+ let(:second_command) { ComplexCommand.new }
- it "forwards the input to each command" do
- result = first_command.then(second_command)
- result.run("hello world", 29)
- first_command.ran?.should be_true
- first_command.arguments.should include("hello world")
- first_command.arguments.should include(29)
- second_command.arguments.should include("hello world")
- second_command.arguments.should include(29)
+ it "forwards the input to each command" do
+ result = first_command.then(second_command)
+ result.run("hello world", 29)
+ first_command.ran?.should be_true
+ first_command.arguments.should include("hello world")
+ first_command.arguments.should include(29)
+ second_command.arguments.should include("hello world")
+ second_command.arguments.should include(29)
+ end
end
end
end