main
 1require "spec_helper"
 2
 3module Nasty
 4  describe Command do
 5    class SimpleCommand
 6      include Command
 7      def run; @ran = true; end
 8      def ran?; @ran; end
 9    end
10
11    class ComplexCommand < SimpleCommand
12      attr_accessor :arguments
13
14      def run(*args)
15        super()
16        self.arguments = args
17      end
18    end
19
20    context "without parameters" do
21      let(:first_command) { SimpleCommand.new }
22      let(:second_command) { SimpleCommand.new }
23      let(:third_command) { SimpleCommand.new }
24
25      it "chains multiple commands together" do
26        first_command.then(second_command).then(third_command).run
27        first_command.ran?.should be_true
28        second_command.ran?.should be_true
29        third_command.ran?.should be_true
30      end
31    end
32
33    context "with parameters" do
34      let(:first_command) { ComplexCommand.new }
35      let(:second_command) { ComplexCommand.new }
36
37      it "forwards the input to each command" do
38        result = first_command.then(second_command)
39        result.run("hello world", 29)
40        first_command.ran?.should be_true
41        first_command.arguments.should include("hello world")
42        first_command.arguments.should include(29)
43        second_command.arguments.should include("hello world")
44        second_command.arguments.should include(29)
45      end
46    end
47  end
48end