spec/webmachine/request_spec.rb in webmachine-1.3.1 vs spec/webmachine/request_spec.rb in webmachine-1.4.0

- old
+ new

@@ -1,15 +1,17 @@ require 'spec_helper' describe Webmachine::Request do subject { request } - let(:uri) { URI.parse("http://localhost:8080/some/resource") } - let(:http_method) { "GET" } - let(:headers) { Webmachine::Headers.new } - let(:body) { "" } - let(:request) { Webmachine::Request.new(http_method, uri, headers, body) } + let(:uri) { URI.parse("http://localhost:8080/some/resource") } + let(:http_method) { "GET" } + let(:headers) { Webmachine::Headers.new } + let(:body) { "" } + let(:routing_tokens) { nil } + let(:base_uri) { nil } + let(:request) { Webmachine::Request.new(http_method, uri, headers, body, routing_tokens, base_uri) } it "should provide access to the headers via brackets" do subject.headers['Accept'] = "*/*" expect(subject["accept"]).to eq("*/*") end @@ -28,12 +30,21 @@ subject.headers["Accept-Encoding"] = "identity" expect(subject.accept_encoding).to eq("identity") expect(subject.content_md5).to be_nil end - it "should calculate a base URI" do - expect(subject.base_uri).to eq(URI.parse("http://localhost:8080/")) + context "base_uri" do + it "should calculate a base URI" do + expect(subject.base_uri).to eq(URI.parse("http://localhost:8080/")) + end + + context "when base_uri has been explicitly set" do + let(:base_uri) { URI.parse("http://localhost:8080/some_base_uri/here") } + it "should use the provided base_uri" do + expect(subject.base_uri).to eq(URI.parse("http://localhost:8080/some_base_uri/here")) + end + end end it "should provide a hash of query parameters" do subject.uri.query = "foo=bar&baz=bam" expect(subject.query).to eq({"foo" => "bar", "baz" => "bam"}) @@ -235,8 +246,28 @@ context "when the request method is not OPTIONS" do let(:http_method) { "GET" } it { is_expected.to be(false) } end + end + + describe '#routing_tokens' do + subject { request.routing_tokens } + + context "haven't been explicitly set" do + let(:routing_tokens) { nil } + it "extracts the routing tokens from the path portion of the uri" do + expect(subject).to eq(["some", "resource"]) + end + end + + context "have been explicitly set" do + let(:routing_tokens) { ["foo", "bar"] } + + it "uses the specified routing_tokens" do + expect(subject).to eq(["foo", "bar"]) + end + end + end end