Sha256: 1f5e6fb98d62a27fa17d4cc77db4bce02ccb858069e5fb7749d4ffca29277c92

Contents?: true

Size: 1.31 KB

Versions: 1

Compression:

Stored size: 1.31 KB

Contents

require "spec_helper"

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

      def run(*args)
        super()
        self.arguments = args
      end
    end

    context "without parameters" do
      let(:first_command) { SimpleCommand.new }
      let(:second_command) { SimpleCommand.new }
      let(:third_command) { SimpleCommand.new }

      it "chains multiple commands together" do
        first_command.then(second_command).then(third_command).run
        first_command.ran?.should be_true
        second_command.ran?.should be_true
        third_command.ran?.should be_true
      end
    end

    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)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nasty-0.0.1395464273 spec/unit/command_spec.rb