Sha256: ea5b1d0d6450c89a154b1e63a92bac9227fbef7ba906861e3a05e8f33a6e128c
Contents?: true
Size: 1.71 KB
Versions: 1
Compression:
Stored size: 1.71 KB
Contents
require "spec_helper" require "mvcli/router" describe "MVCLI::Router" do use_natural_assertions 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 def invoke(route = '') router.call mock(:Command, :argv => route.split(/\s+/)) 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 == 'logins#create' } And { not @command.nil? } Then { @command.argv == ['login'] } end context "when there are command line options, it does not interfere" do Given { router.match 'login' => 'logins#create' } When { invoke 'login --then --go-away -f 6 -p' } Then { not @command.nil? } end context "with a route matched to a block" do Given { router.match bam: ->(command) {@command = command} } When { invoke 'bam' } Then { @command.argv == ['bam'] } end context "with a route with captures" do Given { router.match 'show loadbalancer :id' => 'loadbalancers#show' } When { invoke 'show loadbalancer 6' } Then {@action == 'loadbalancers#show'} And { @command.argv == ['show', 'loadbalancer', '6'] } And { @bindings[:id] == '6' } end context "with macros" do Given { router.macro /(-h|--help) (.*)/ => "help \\2" } Given { router.match "help me" => "help#me"} When { invoke "--help me" } Then { @action == 'help#me' } end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
mvcli-0.0.16 | spec/mvcli/router_spec.rb |