Sha256: 8645a7f82c328dd84846fa1fabb98561b4214208491bfbd850c1855124a7fc7d

Contents?: true

Size: 1.14 KB

Versions: 5

Compression:

Stored size: 1.14 KB

Contents

describe Ppl::Application::Router do

  before(:each) do
    @suite  = Ppl::Application::CommandSuite.new
    @router = Ppl::Application::Router.new(@suite)

    @cmd_one = Ppl::Application::Command.new
    @cmd_one.name = "one"

    @cmd_two = Ppl::Application::Command.new
    @cmd_two.name = "two"

    @suite.add_command(@cmd_one)
    @suite.add_command(@cmd_two)
  end

  describe "#default=" do
    it "should accept the name of the default command" do
      @router.default = "one"
      @router.default.should eq "one"
    end
  end

  describe "#route" do

    it "should return the command whose name matches the given argument" do
      @router.route("two").should be @cmd_two
    end

    it "should return nil if no matching command can be found" do
      @router.route("three").should be nil
    end

    it "should fall back to the default command if the given one isn't found" do
      @router.default = "one"
      @router.route("three").should be @cmd_one
    end

    it "should apply the aliases if the argument doesn't match a command" do
      @router.aliases = {"t" => "two"}
      @router.route("t").should be @cmd_two
    end

  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ppl-1.13.0 spec/ppl/application/router_spec.rb
ppl-1.12.0 spec/ppl/application/router_spec.rb
ppl-1.11.0 spec/ppl/application/router_spec.rb
ppl-1.10.0 spec/ppl/application/router_spec.rb
ppl-1.9.0 spec/ppl/application/router_spec.rb