diff options
author | Gibheer <gibheer@gmail.com> | 2012-11-16 10:50:49 +0100 |
---|---|---|
committer | Gibheer <gibheer@gmail.com> | 2012-11-16 10:50:49 +0100 |
commit | a138da7e848a626aa054d3100f4e6332d3fa84b1 (patch) | |
tree | 18b166d9766d0522a8136b747ff94e7c8f121625 /spec/unit/router | |
parent | 75ccc3195d8dc2fcf77189d6bf50ef822d59cce0 (diff) |
add unit specs for router
Diffstat (limited to 'spec/unit/router')
-rw-r--r-- | spec/unit/router/call_spec.rb | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/spec/unit/router/call_spec.rb b/spec/unit/router/call_spec.rb new file mode 100644 index 0000000..c242dbd --- /dev/null +++ b/spec/unit/router/call_spec.rb @@ -0,0 +1,42 @@ +require 'spec_helper' + +describe Zero::Router, '#call' do + subject { Zero::Router.new(routes) } + let(:result) { ['success'] } + + let(:wrong_app) do + lambda {|env| [200, {'Content-Type' => 'text/html'}, 'Wrong'] } + end + let(:app) { SpecApp } + + shared_examples_for "a sample app" do + it "returns a response" do + subject.call(env).to_a[2].should eq(result) + end + end + + context "with a single route" do + let(:routes) {{ '/' => app }} + let(:env) { EnvGenerator.get('/') } + it_behaves_like "a sample app" + end + + context "with multiple routes" do + let(:routes) {{ '/foo' => app, '/wrong' => wrong_app }} + let(:env) { EnvGenerator.get('/foo') } + it_behaves_like "a sample app" + end + + context "with nested routes" do + let(:routes) {{ '/' => wrong_app, '/foo' => app, '/foo/bar' => wrong_app }} + let(:env) { EnvGenerator.get('/foo') } + it_behaves_like "a sample app" + end + + context "with a route not found" do + let(:routes) {{ '/foo' => wrong_app, '/foo/bar/baz' => app }} + let(:env) { EnvGenerator.get('/foo/bar') } + let(:result) { ['Not found!'] } + it_behaves_like "a sample app" + end +end |