Sha256: 6d3a8df88b8094b104f2bbaec7a1b8d3b750becccfcb6c614c77a29a645f7a5d

Contents?: true

Size: 1.29 KB

Versions: 3

Compression:

Stored size: 1.29 KB

Contents

require "spec_helper"
require "mvcli/router"

describe "MVCLI::Router" do
  Given(:Router) {MVCLI::Router}
  Given(:actions) {mock(:Actions)}
  Given(:router) {self.Router.new actions}
  Given do
    actions.stub(:[]) do |action|
      @action = action
      ->(command, bindings) {@command = command; @bindings = bindings}
    end
  end

  context "without any routes" do
    When(:result) {invoke}
    Then {result.should have_failed self.Router::RoutingError}
  end

  context "with a route matched to an action" do
    Given {router.match 'login' => 'logins#create'}
    When {invoke 'login'}
    Then {@action.should eql 'logins#create'}
    And {@command.should_not be_nil}
    Then {@command.argv.should eql ['login']}
  end

  context "with a route matched to a block" do
    Given {router.match bam: ->(command) {@command = command}}
    When {invoke 'bam'}
    Then {@command.argv.should eql ['bam']}
  end

  context "with a route with captures" do
    Given {router.match 'show loadbalancer :id' => 'loadbalancers#show'}
    When {invoke 'show loadbalancer 6'}
    Then {@action.should eql 'loadbalancers#show'}
    And {@command.argv == ['show' 'loadbalancer' '6']}
    And {@bindings[:id].should eql '6'}
  end

  def invoke(route = '')
    router.call mock(:Command, :argv => route.split(/\s+/))
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mvcli-0.0.6 spec/mvcli/router_spec.rb
mvcli-0.0.5 spec/mvcli/router_spec.rb
mvcli-0.0.4 spec/mvcli/router_spec.rb