This repository has been archived by the owner on Sep 30, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit using rspec (opal-rspec)
- Loading branch information
1 parent
1fc9329
commit f2371e9
Showing
13 changed files
with
95 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,62 @@ | ||
require 'spec_helper' | ||
|
||
describe Vienna::Router::Route do | ||
describe "#initialize" do | ||
let(:route) { Vienna::Router::Route } | ||
subject { described_class } | ||
|
||
describe "#initialize" do | ||
it "creates a regexp from the given pattern" do | ||
route.new('foo').regexp.should eq(/^foo$/) | ||
subject.new('foo').regexp.should eq(/^foo$/) | ||
end | ||
|
||
it "escapes slashes in the pattern" do | ||
route.new('/foo/bar/').regexp.should eq(/^\/foo\/bar\/$/) | ||
subject.new('/foo/bar/').regexp.should eq(/^\/foo\/bar\/$/) | ||
end | ||
|
||
it "finds named params in pattern" do | ||
r = route.new('/foo/:bar') | ||
r = subject.new('/foo/:bar') | ||
r.named.should eq(['bar']) | ||
|
||
p = route.new('/:woosh/:kapow') | ||
p = subject.new('/:woosh/:kapow') | ||
p.named.should eq(['woosh', 'kapow']) | ||
end | ||
|
||
it "finds splatted params in pattern" do | ||
route.new('/foo/*baz').named.should eq(['baz']) | ||
subject.new('/foo/*baz').named.should eq(['baz']) | ||
end | ||
|
||
it "produces a regexp to match given pattern" do | ||
route.new('/foo').regexp.match('/bar').should be_nil | ||
route.new('/foo').regexp.match('/foo').should be_kind_of(MatchData) | ||
subject.new('/foo').regexp.match('/bar').should be_nil | ||
subject.new('/foo').regexp.match('/foo').should be_kind_of(MatchData) | ||
end | ||
end | ||
|
||
describe "#match" do | ||
let(:route) { Vienna::Router::Route } | ||
|
||
it "returns false for a non matching route" do | ||
route.new('/foo').match('/a/b/c').should be_false | ||
subject.new('/foo').match('/a/b/c').should eq(false) | ||
end | ||
|
||
it "returns true for a matching route" do | ||
route.new('/foo').match('/foo').should be_true | ||
subject.new('/foo').match('/foo').should eq(true) | ||
end | ||
|
||
it "calls block given to #initialize on matching a route" do | ||
called = false | ||
route.new('/foo') { called = true }.match('/foo') | ||
called.should be_true | ||
subject.new('/foo') { called = true }.match('/foo') | ||
called.should eq(true) | ||
end | ||
|
||
it "calls handler with an empty hash for a simple route" do | ||
route.new('/foo') { |params| params.should eq({}) }.match('/foo') | ||
subject.new('/foo') { |params| params.should eq({}) }.match('/foo') | ||
end | ||
|
||
it "returns a hash of named params for matching route" do | ||
route.new('/foo/:first') { |params| | ||
subject.new('/foo/:first') { |params| | ||
params.should eq({'first' => '123' }) | ||
}.match('/foo/123') | ||
|
||
route.new('/:first/:second') { |params| | ||
subject.new('/:first/:second') { |params| | ||
params.should eq({ 'first' => 'woosh', 'second' => 'kapow' }) | ||
}.match('/woosh/kapow') | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.