spec/webmachine/dispatcher/route_spec.rb in webmachine-1.3.1 vs spec/webmachine/dispatcher/route_spec.rb in webmachine-1.4.0
- old
+ new
@@ -5,22 +5,21 @@
end
describe Webmachine::Dispatcher::Route do
let(:method) { "GET" }
let(:uri) { URI.parse("http://localhost:8080/") }
- let(:request){ Webmachine::Request.new(method, uri, Webmachine::Headers.new, "") }
+ let(:routing_tokens) { nil }
+ let(:request){ Webmachine::Request.new(method, uri, Webmachine::Headers.new, "", routing_tokens) }
let(:resource){ Class.new(Webmachine::Resource) }
describe '#apply' do
let(:route) {
Webmachine::Dispatcher::Route.new ['hello', :string], resource, {}
}
describe 'a path_info fragment' do
- before do
- uri.path = '/hello/planet%20earth%20++'
- end
+ let(:uri) { URI.parse("http://localhost:8080/hello/planet%20earth%20++") }
it 'should decode the value' do
route.apply(request)
expect(request.path_info).to eq({:string => 'planet earth ++'})
end
@@ -28,12 +27,14 @@
end
matcher :match_route do |*expected|
route = Webmachine::Dispatcher::Route.new(expected[0], Class.new(Webmachine::Resource), expected[1] || {})
match do |actual|
- request.uri.path = actual if String === actual
- route.match?(request)
+ uri = URI.parse("http://localhost:8080")
+ uri.path = actual
+ req = Webmachine::Request.new("GET", uri, Webmachine::Headers.new, "", routing_tokens)
+ route.match?(req)
end
failure_message do |_|
"expected route #{expected[0].inspect} to match path #{request.uri.path}"
end
@@ -122,10 +123,22 @@
# let(:method){ "GET" }
it { is_expected.not_to be_match(request) }
end
end
end
+
+ context "with a request with explicitly specified routing tokens" do
+ subject { "/some/route/foo/bar" }
+ let(:routing_tokens) { ["foo", "bar"] }
+ it { is_expected.to match_route(["foo", "bar"]) }
+ it { is_expected.to match_route(["foo", :id]) }
+ it { is_expected.to match_route ['*'] }
+ it { is_expected.to match_route [:*] }
+ it { is_expected.not_to match_route(["some", "route", "foo", "bar"]) }
+ it { is_expected.not_to match_route %w{foo} }
+ it { is_expected.not_to match_route [:id] }
+ end
end
context "applying bindings" do
context "on the root path" do
subject { described_class.new([], resource) }
@@ -168,10 +181,11 @@
end
end
context "on a deep path" do
subject { described_class.new(%w{foo bar baz}, resource) }
- before { request.uri.path = "/foo/bar/baz"; subject.apply(request) }
+ let(:uri) { URI.parse("http://localhost:8080/foo/bar/baz") }
+ before { subject.apply(request) }
it "should assign the dispatched path as the path past the initial slash" do
expect(request.disp_path).to eq("foo/bar/baz")
end