|
|
c6149d |
diff --git a/spec/rack/test/cookie_spec.rb b/spec/rack/test/cookie_spec.rb
|
|
|
c6149d |
index e4bce5a..e0839e5 100644
|
|
|
c6149d |
--- a/spec/rack/test/cookie_spec.rb
|
|
|
c6149d |
+++ b/spec/rack/test/cookie_spec.rb
|
|
|
c6149d |
@@ -5,90 +5,88 @@
|
|
|
c6149d |
context "cookies" do
|
|
|
c6149d |
it "keeps a cookie jar" do
|
|
|
c6149d |
get "/cookies/show"
|
|
|
c6149d |
- check last_request.cookies.should == {}
|
|
|
c6149d |
+ check expect(last_request.cookies).to eq({})
|
|
|
c6149d |
|
|
|
c6149d |
get "/cookies/set", "value" => "1"
|
|
|
c6149d |
get "/cookies/show"
|
|
|
c6149d |
- last_request.cookies.should == { "value" => "1" }
|
|
|
c6149d |
+ expect(last_request.cookies).to eq({ "value" => "1" })
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "doesn't send expired cookies" do
|
|
|
c6149d |
get "/cookies/set", "value" => "1"
|
|
|
c6149d |
now = Time.now
|
|
|
c6149d |
- Time.stub!(:now => now + 60)
|
|
|
c6149d |
+ allow(Time).to receive_messages(:now => now + 60)
|
|
|
c6149d |
get "/cookies/show"
|
|
|
c6149d |
- last_request.cookies.should == {}
|
|
|
c6149d |
+ expect(last_request.cookies).to eq({})
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "cookie path defaults to the uri of the document that was requested" do
|
|
|
c6149d |
- pending "See issue rack-test github issue #50" do
|
|
|
c6149d |
- post "/cookies/default-path", "value" => "cookie"
|
|
|
c6149d |
- get "/cookies/default-path"
|
|
|
c6149d |
- check last_request.cookies.should == { "simple"=>"cookie" }
|
|
|
c6149d |
- get "/cookies/show"
|
|
|
c6149d |
- check last_request.cookies.should == { }
|
|
|
c6149d |
- end
|
|
|
c6149d |
+ pending "See issue rack-test github issue #50"
|
|
|
c6149d |
+ post "/cookies/default-path", "value" => "cookie"
|
|
|
c6149d |
+ get "/cookies/default-path"
|
|
|
c6149d |
+ expect(last_request.cookies).to eq({ "simple"=>"cookie" })
|
|
|
c6149d |
+ get "/cookies/show"
|
|
|
c6149d |
+ expect(last_request.cookies).to eq({})
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "escapes cookie values" do
|
|
|
c6149d |
jar = Rack::Test::CookieJar.new
|
|
|
c6149d |
jar["value"] = "foo;abc"
|
|
|
c6149d |
- jar["value"].should == "foo;abc"
|
|
|
c6149d |
+ expect(jar["value"]).to eq("foo;abc")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "deletes cookies directly from the CookieJar" do
|
|
|
c6149d |
jar = Rack::Test::CookieJar.new
|
|
|
c6149d |
jar["abcd"] = "1234"
|
|
|
c6149d |
- jar["abcd"].should == "1234"
|
|
|
c6149d |
+ expect(jar["abcd"]).to eq("1234")
|
|
|
c6149d |
jar.delete("abcd")
|
|
|
c6149d |
- jar["abcd"].should == nil
|
|
|
c6149d |
+ expect(jar["abcd"]).to eq(nil)
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "doesn't send cookies with the wrong domain" do
|
|
|
c6149d |
get "http://www.example.com/cookies/set", "value" => "1"
|
|
|
c6149d |
get "http://www.other.example/cookies/show"
|
|
|
c6149d |
- last_request.cookies.should == {}
|
|
|
c6149d |
+ expect(last_request.cookies).to eq({})
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "doesn't send cookies with the wrong path" do
|
|
|
c6149d |
get "/cookies/set", "value" => "1"
|
|
|
c6149d |
get "/not-cookies/show"
|
|
|
c6149d |
- last_request.cookies.should == {}
|
|
|
c6149d |
+ expect(last_request.cookies).to eq({})
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "persists cookies across requests that don't return any cookie headers" do
|
|
|
c6149d |
get "/cookies/set", "value" => "1"
|
|
|
c6149d |
get "/void"
|
|
|
c6149d |
get "/cookies/show"
|
|
|
c6149d |
- last_request.cookies.should == { "value" => "1" }
|
|
|
c6149d |
+ expect(last_request.cookies).to eq({ "value" => "1" })
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "deletes cookies" do
|
|
|
c6149d |
get "/cookies/set", "value" => "1"
|
|
|
c6149d |
get "/cookies/delete"
|
|
|
c6149d |
get "/cookies/show"
|
|
|
c6149d |
- last_request.cookies.should == { }
|
|
|
c6149d |
+ expect(last_request.cookies).to eq({ })
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "respects cookie domains when no domain is explicitly set" do
|
|
|
c6149d |
- pending "FIXME: www.example.org should not get the first cookie" do
|
|
|
c6149d |
- request("http://example.org/cookies/count").should have_body("1")
|
|
|
c6149d |
- request("http://www.example.org/cookies/count").should have_body("1")
|
|
|
c6149d |
- request("http://example.org/cookies/count").should have_body("2")
|
|
|
c6149d |
- request("http://www.example.org/cookies/count").should have_body("2")
|
|
|
c6149d |
- end
|
|
|
c6149d |
+ pending "FIXME: www.example.org should not get the first cookie"
|
|
|
c6149d |
+ expect(request("http://example.org/cookies/count")).to have_body("1")
|
|
|
c6149d |
+ expect(request("http://www.example.org/cookies/count")).to have_body("1")
|
|
|
c6149d |
+ expect(request("http://example.org/cookies/count")).to have_body("2")
|
|
|
c6149d |
+ expect(request("http://www.example.org/cookies/count")).to have_body("2")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "treats domains case insensitively" do
|
|
|
c6149d |
get "http://example.com/cookies/set", "value" => "1"
|
|
|
c6149d |
get "http://EXAMPLE.COM/cookies/show"
|
|
|
c6149d |
- last_request.cookies.should == { "value" => "1" }
|
|
|
c6149d |
+ expect(last_request.cookies).to eq({ "value" => "1" })
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "treats paths case sensitively" do
|
|
|
c6149d |
get "/cookies/set", "value" => "1"
|
|
|
c6149d |
get "/COOKIES/show"
|
|
|
c6149d |
- last_request.cookies.should == {}
|
|
|
c6149d |
+ expect(last_request.cookies).to eq({})
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "prefers more specific cookies" do
|
|
|
c6149d |
@@ -96,124 +94,124 @@
|
|
|
c6149d |
get "http://sub.example.com/cookies/set", "value" => "sub"
|
|
|
c6149d |
|
|
|
c6149d |
get "http://sub.example.com/cookies/show"
|
|
|
c6149d |
- check last_request.cookies.should == { "value" => "sub" }
|
|
|
c6149d |
+ check expect(last_request.cookies).to eq({ "value" => "sub" })
|
|
|
c6149d |
|
|
|
c6149d |
get "http://example.com/cookies/show"
|
|
|
c6149d |
- last_request.cookies.should == { "value" => "domain" }
|
|
|
c6149d |
+ expect(last_request.cookies).to eq({ "value" => "domain" })
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "treats cookie names case insensitively" do
|
|
|
c6149d |
get "/cookies/set", "value" => "lowercase"
|
|
|
c6149d |
get "/cookies/set-uppercase", "value" => "UPPERCASE"
|
|
|
c6149d |
get "/cookies/show"
|
|
|
c6149d |
- last_request.cookies.should == { "VALUE" => "UPPERCASE" }
|
|
|
c6149d |
+ expect(last_request.cookies).to eq({ "VALUE" => "UPPERCASE" })
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "defaults the domain to the request domain" do
|
|
|
c6149d |
get "http://example.com/cookies/set-simple", "value" => "cookie"
|
|
|
c6149d |
get "http://example.com/cookies/show"
|
|
|
c6149d |
- check last_request.cookies.should == { "simple" => "cookie" }
|
|
|
c6149d |
+ check expect(last_request.cookies).to eq({ "simple" => "cookie" })
|
|
|
c6149d |
|
|
|
c6149d |
get "http://other.example/cookies/show"
|
|
|
c6149d |
- last_request.cookies.should == {}
|
|
|
c6149d |
+ expect(last_request.cookies).to eq({})
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "defaults the domain to the request path up to the last slash" do
|
|
|
c6149d |
get "/cookies/set-simple", "value" => "1"
|
|
|
c6149d |
get "/not-cookies/show"
|
|
|
c6149d |
- last_request.cookies.should == {}
|
|
|
c6149d |
+ expect(last_request.cookies).to eq({})
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "supports secure cookies" do
|
|
|
c6149d |
get "https://example.com/cookies/set-secure", "value" => "set"
|
|
|
c6149d |
get "http://example.com/cookies/show"
|
|
|
c6149d |
- check last_request.cookies.should == {}
|
|
|
c6149d |
+ check expect(last_request.cookies).to eq({})
|
|
|
c6149d |
|
|
|
c6149d |
get "https://example.com/cookies/show"
|
|
|
c6149d |
- last_request.cookies.should == { "secure-cookie" => "set" }
|
|
|
c6149d |
- rack_mock_session.cookie_jar['secure-cookie'].should == 'set'
|
|
|
c6149d |
+ expect(last_request.cookies).to eq({ "secure-cookie" => "set" })
|
|
|
c6149d |
+ expect(rack_mock_session.cookie_jar['secure-cookie']).to eq('set')
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "keeps separate cookie jars for different domains" do
|
|
|
c6149d |
get "http://example.com/cookies/set", "value" => "example"
|
|
|
c6149d |
get "http://example.com/cookies/show"
|
|
|
c6149d |
- check last_request.cookies.should == { "value" => "example" }
|
|
|
c6149d |
+ check expect(last_request.cookies).to eq({ "value" => "example" })
|
|
|
c6149d |
|
|
|
c6149d |
get "http://other.example/cookies/set", "value" => "other"
|
|
|
c6149d |
get "http://other.example/cookies/show"
|
|
|
c6149d |
- check last_request.cookies.should == { "value" => "other" }
|
|
|
c6149d |
+ check expect(last_request.cookies).to eq({ "value" => "other" })
|
|
|
c6149d |
|
|
|
c6149d |
get "http://example.com/cookies/show"
|
|
|
c6149d |
- last_request.cookies.should == { "value" => "example" }
|
|
|
c6149d |
+ expect(last_request.cookies).to eq({ "value" => "example" })
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "keeps one cookie jar for domain and its subdomains" do
|
|
|
c6149d |
get "http://example.org/cookies/subdomain"
|
|
|
c6149d |
get "http://example.org/cookies/subdomain"
|
|
|
c6149d |
- last_request.cookies.should == { "count" => "1" }
|
|
|
c6149d |
+ expect(last_request.cookies).to eq({ "count" => "1" })
|
|
|
c6149d |
|
|
|
c6149d |
get "http://foo.example.org/cookies/subdomain"
|
|
|
c6149d |
- last_request.cookies.should == { "count" => "2" }
|
|
|
c6149d |
+ expect(last_request.cookies).to eq({ "count" => "2" })
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "allows cookies to be cleared" do
|
|
|
c6149d |
get "/cookies/set", "value" => "1"
|
|
|
c6149d |
clear_cookies
|
|
|
c6149d |
get "/cookies/show"
|
|
|
c6149d |
- last_request.cookies.should == {}
|
|
|
c6149d |
+ expect(last_request.cookies).to eq({})
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "allow cookies to be set" do
|
|
|
c6149d |
set_cookie "value=10"
|
|
|
c6149d |
get "/cookies/show"
|
|
|
c6149d |
- last_request.cookies.should == { "value" => "10" }
|
|
|
c6149d |
+ expect(last_request.cookies).to eq({ "value" => "10" })
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "allows an array of cookies to be set" do
|
|
|
c6149d |
set_cookie ["value=10", "foo=bar"]
|
|
|
c6149d |
get "/cookies/show"
|
|
|
c6149d |
- last_request.cookies.should == { "value" => "10", "foo" => "bar" }
|
|
|
c6149d |
+ expect(last_request.cookies).to eq({ "value" => "10", "foo" => "bar" })
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "skips emtpy string cookies" do
|
|
|
c6149d |
set_cookie "value=10\n\nfoo=bar"
|
|
|
c6149d |
get "/cookies/show"
|
|
|
c6149d |
- last_request.cookies.should == { "value" => "10", "foo" => "bar" }
|
|
|
c6149d |
+ expect(last_request.cookies).to eq({ "value" => "10", "foo" => "bar" })
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "parses multiple cookies properly" do
|
|
|
c6149d |
get "/cookies/set-multiple"
|
|
|
c6149d |
get "/cookies/show"
|
|
|
c6149d |
- last_request.cookies.should == { "key1" => "value1", "key2" => "value2" }
|
|
|
c6149d |
+ expect(last_request.cookies).to eq({ "key1" => "value1", "key2" => "value2" })
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "supports multiple sessions" do
|
|
|
c6149d |
with_session(:first) do
|
|
|
c6149d |
get "/cookies/set", "value" => "1"
|
|
|
c6149d |
get "/cookies/show"
|
|
|
c6149d |
- last_request.cookies.should == { "value" => "1" }
|
|
|
c6149d |
+ expect(last_request.cookies).to eq({ "value" => "1" })
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
with_session(:second) do
|
|
|
c6149d |
get "/cookies/show"
|
|
|
c6149d |
- last_request.cookies.should == { }
|
|
|
c6149d |
+ expect(last_request.cookies).to eq({ })
|
|
|
c6149d |
end
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "uses :default as the default session name" do
|
|
|
c6149d |
get "/cookies/set", "value" => "1"
|
|
|
c6149d |
get "/cookies/show"
|
|
|
c6149d |
- check last_request.cookies.should == { "value" => "1" }
|
|
|
c6149d |
+ check expect(last_request.cookies).to eq({ "value" => "1" })
|
|
|
c6149d |
|
|
|
c6149d |
with_session(:default) do
|
|
|
c6149d |
get "/cookies/show"
|
|
|
c6149d |
- last_request.cookies.should == { "value" => "1" }
|
|
|
c6149d |
+ expect(last_request.cookies).to eq({ "value" => "1" })
|
|
|
c6149d |
end
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "accepts explicitly provided cookies" do
|
|
|
c6149d |
request "/cookies/show", :cookie => "value=1"
|
|
|
c6149d |
- last_request.cookies.should == { "value" => "1" }
|
|
|
c6149d |
+ expect(last_request.cookies).to eq({ "value" => "1" })
|
|
|
c6149d |
end
|
|
|
c6149d |
end
|
|
|
c6149d |
end
|
|
|
c6149d |
diff --git a/spec/rack/test/digest_auth_spec.rb b/spec/rack/test/digest_auth_spec.rb
|
|
|
c6149d |
index 7b966e6..cccf1d6 100644
|
|
|
c6149d |
--- a/spec/rack/test/digest_auth_spec.rb
|
|
|
c6149d |
+++ b/spec/rack/test/digest_auth_spec.rb
|
|
|
c6149d |
@@ -15,31 +15,31 @@ def app
|
|
|
c6149d |
it 'incorrectly authenticates GETs' do
|
|
|
c6149d |
digest_authorize 'foo', 'bar'
|
|
|
c6149d |
get '/'
|
|
|
c6149d |
- last_response.should be_challenge
|
|
|
c6149d |
+ expect(last_response).to be_challenge
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "correctly authenticates GETs" do
|
|
|
c6149d |
digest_authorize "alice", "correct-password"
|
|
|
c6149d |
response = get "/"
|
|
|
c6149d |
- response.should be_ok
|
|
|
c6149d |
+ expect(response).to be_ok
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "correctly authenticates GETs with params" do
|
|
|
c6149d |
digest_authorize "alice", "correct-password"
|
|
|
c6149d |
response = get "/", "foo" => "bar"
|
|
|
c6149d |
- response.should be_ok
|
|
|
c6149d |
+ expect(response).to be_ok
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "correctly authenticates POSTs" do
|
|
|
c6149d |
digest_authorize "alice", "correct-password"
|
|
|
c6149d |
response = post "/"
|
|
|
c6149d |
- response.should be_ok
|
|
|
c6149d |
+ expect(response).to be_ok
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "returns a re-challenge if authenticating incorrectly" do
|
|
|
c6149d |
digest_authorize "alice", "incorrect-password"
|
|
|
c6149d |
response = get "/"
|
|
|
c6149d |
- response.should be_challenge
|
|
|
c6149d |
+ expect(response).to be_challenge
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
end
|
|
|
c6149d |
diff --git a/spec/rack/test/multipart_spec.rb b/spec/rack/test/multipart_spec.rb
|
|
|
c6149d |
index ad6c3ae..2e7bf16 100644
|
|
|
c6149d |
--- a/spec/rack/test/multipart_spec.rb
|
|
|
c6149d |
+++ b/spec/rack/test/multipart_spec.rb
|
|
|
c6149d |
@@ -23,83 +23,83 @@ def second_uploaded_file
|
|
|
c6149d |
context "uploading a file" do
|
|
|
c6149d |
it "sends the multipart/form-data content type" do
|
|
|
c6149d |
post "/", "photo" => uploaded_file
|
|
|
c6149d |
- last_request.env["CONTENT_TYPE"].should include("multipart/form-data;")
|
|
|
c6149d |
+ expect(last_request.env["CONTENT_TYPE"]).to include("multipart/form-data;")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "sends regular params" do
|
|
|
c6149d |
post "/", "photo" => uploaded_file, "foo" => "bar"
|
|
|
c6149d |
- last_request.POST["foo"].should == "bar"
|
|
|
c6149d |
+ expect(last_request.POST["foo"]).to eq("bar")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "sends nested params" do
|
|
|
c6149d |
post "/", "photo" => uploaded_file, "foo" => {"bar" => "baz"}
|
|
|
c6149d |
- last_request.POST["foo"]["bar"].should == "baz"
|
|
|
c6149d |
+ expect(last_request.POST["foo"]["bar"]).to eq("baz")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "sends multiple nested params" do
|
|
|
c6149d |
post "/", "photo" => uploaded_file, "foo" => {"bar" => {"baz" => "bop"}}
|
|
|
c6149d |
- last_request.POST["foo"]["bar"]["baz"].should == "bop"
|
|
|
c6149d |
+ expect(last_request.POST["foo"]["bar"]["baz"]).to eq("bop")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "sends params with arrays" do
|
|
|
c6149d |
post "/", "photo" => uploaded_file, "foo" => ["1", "2"]
|
|
|
c6149d |
- last_request.POST["foo"].should == ["1", "2"]
|
|
|
c6149d |
+ expect(last_request.POST["foo"]).to eq(["1", "2"])
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "sends params with encoding sensitive values" do
|
|
|
c6149d |
post "/", "photo" => uploaded_file, "foo" => "bar? baz"
|
|
|
c6149d |
- last_request.POST["foo"].should == "bar? baz"
|
|
|
c6149d |
+ expect(last_request.POST["foo"]).to eq("bar? baz")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "sends params encoded as ISO-8859-1" do
|
|
|
c6149d |
post "/", "photo" => uploaded_file, "foo" => "bar", "utf8" => "☃"
|
|
|
c6149d |
- last_request.POST["foo"].should == "bar"
|
|
|
c6149d |
+ expect(last_request.POST["foo"]).to eq("bar")
|
|
|
c6149d |
|
|
|
c6149d |
if Rack::Test.encoding_aware_strings?
|
|
|
c6149d |
- last_request.POST["utf8"].should == "☃"
|
|
|
c6149d |
+ expect(last_request.POST["utf8"]).to eq("☃")
|
|
|
c6149d |
else
|
|
|
c6149d |
- last_request.POST["utf8"].should == "\xE2\x98\x83"
|
|
|
c6149d |
+ expect(last_request.POST["utf8"]).to eq("\xE2\x98\x83")
|
|
|
c6149d |
end
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "sends params with parens in names" do
|
|
|
c6149d |
post "/", "photo" => uploaded_file, "foo(1i)" => "bar"
|
|
|
c6149d |
- last_request.POST["foo(1i)"].should == "bar"
|
|
|
c6149d |
+ expect(last_request.POST["foo(1i)"]).to eq("bar")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "sends params with encoding sensitive names" do
|
|
|
c6149d |
post "/", "photo" => uploaded_file, "foo bar" => "baz"
|
|
|
c6149d |
- last_request.POST["foo bar"].should == "baz"
|
|
|
c6149d |
+ expect(last_request.POST["foo bar"]).to eq("baz")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "sends files with the filename" do
|
|
|
c6149d |
post "/", "photo" => uploaded_file
|
|
|
c6149d |
- last_request.POST["photo"][:filename].should == "foo.txt"
|
|
|
c6149d |
+ expect(last_request.POST["photo"][:filename]).to eq("foo.txt")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "sends files with the text/plain MIME type by default" do
|
|
|
c6149d |
post "/", "photo" => uploaded_file
|
|
|
c6149d |
- last_request.POST["photo"][:type].should == "text/plain"
|
|
|
c6149d |
+ expect(last_request.POST["photo"][:type]).to eq("text/plain")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "sends files with the right name" do
|
|
|
c6149d |
post "/", "photo" => uploaded_file
|
|
|
c6149d |
- last_request.POST["photo"][:name].should == "photo"
|
|
|
c6149d |
+ expect(last_request.POST["photo"][:name]).to eq("photo")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "allows overriding the content type" do
|
|
|
c6149d |
post "/", "photo" => Rack::Test::UploadedFile.new(test_file_path, "image/jpeg")
|
|
|
c6149d |
- last_request.POST["photo"][:type].should == "image/jpeg"
|
|
|
c6149d |
+ expect(last_request.POST["photo"][:type]).to eq("image/jpeg")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "sends files with a Content-Length in the header" do
|
|
|
c6149d |
post "/", "photo" => uploaded_file
|
|
|
c6149d |
- last_request.POST["photo"][:head].should include("Content-Length: 4")
|
|
|
c6149d |
+ expect(last_request.POST["photo"][:head]).to include("Content-Length: 4")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "sends files as Tempfiles" do
|
|
|
c6149d |
post "/", "photo" => uploaded_file
|
|
|
c6149d |
- last_request.POST["photo"][:tempfile].should be_a(::Tempfile)
|
|
|
c6149d |
+ expect(last_request.POST["photo"][:tempfile]).to be_a(::Tempfile)
|
|
|
c6149d |
end
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
@@ -107,39 +107,39 @@ def second_uploaded_file
|
|
|
c6149d |
context "uploading two files" do
|
|
|
c6149d |
it "sends the multipart/form-data content type" do
|
|
|
c6149d |
post "/", "photos" => [uploaded_file, second_uploaded_file]
|
|
|
c6149d |
- last_request.env["CONTENT_TYPE"].should include("multipart/form-data;")
|
|
|
c6149d |
+ expect(last_request.env["CONTENT_TYPE"]).to include("multipart/form-data;")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "sends files with the filename" do
|
|
|
c6149d |
post "/", "photos" => [uploaded_file, second_uploaded_file]
|
|
|
c6149d |
- last_request.POST["photos"].collect{|photo| photo[:filename]}.should == ["foo.txt", "bar.txt"]
|
|
|
c6149d |
+ expect(last_request.POST["photos"].collect{|photo| photo[:filename]}).to eq(["foo.txt", "bar.txt"])
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "sends files with the text/plain MIME type by default" do
|
|
|
c6149d |
post "/", "photos" => [uploaded_file, second_uploaded_file]
|
|
|
c6149d |
- last_request.POST["photos"].collect{|photo| photo[:type]}.should == ["text/plain", "text/plain"]
|
|
|
c6149d |
+ expect(last_request.POST["photos"].collect{|photo| photo[:type]}).to eq(["text/plain", "text/plain"])
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "sends files with the right names" do
|
|
|
c6149d |
post "/", "photos" => [uploaded_file, second_uploaded_file]
|
|
|
c6149d |
- last_request.POST["photos"].all?{|photo| photo[:name].should == "photos[]" }
|
|
|
c6149d |
+ last_request.POST["photos"].all?{|photo| expect(photo[:name]).to eq("photos[]") }
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "allows mixed content types" do
|
|
|
c6149d |
image_file = Rack::Test::UploadedFile.new(test_file_path, "image/jpeg")
|
|
|
c6149d |
|
|
|
c6149d |
post "/", "photos" => [uploaded_file, image_file]
|
|
|
c6149d |
- last_request.POST["photos"].collect{|photo| photo[:type]}.should == ["text/plain", "image/jpeg"]
|
|
|
c6149d |
+ expect(last_request.POST["photos"].collect{|photo| photo[:type]}).to eq(["text/plain", "image/jpeg"])
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "sends files with a Content-Length in the header" do
|
|
|
c6149d |
post "/", "photos" => [uploaded_file, second_uploaded_file]
|
|
|
c6149d |
- last_request.POST["photos"].all?{|photo| photo[:head].should include("Content-Length: 4") }
|
|
|
c6149d |
+ last_request.POST["photos"].all?{|photo| expect(photo[:head]).to include("Content-Length: 4") }
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "sends both files as Tempfiles" do
|
|
|
c6149d |
post "/", "photos" => [uploaded_file, second_uploaded_file]
|
|
|
c6149d |
- last_request.POST["photos"].all?{|photo| photo[:tempfile].should be_a(::Tempfile) }
|
|
|
c6149d |
+ last_request.POST["photos"].all?{|photo| expect(photo[:tempfile]).to be_a(::Tempfile) }
|
|
|
c6149d |
end
|
|
|
c6149d |
end
|
|
|
c6149d |
end
|
|
|
c6149d |
diff --git a/spec/rack/test/uploaded_file_spec.rb b/spec/rack/test/uploaded_file_spec.rb
|
|
|
c6149d |
index cde4856..5c1e462 100644
|
|
|
c6149d |
--- a/spec/rack/test/uploaded_file_spec.rb
|
|
|
c6149d |
+++ b/spec/rack/test/uploaded_file_spec.rb
|
|
|
c6149d |
@@ -8,17 +8,22 @@ def test_file_path
|
|
|
c6149d |
it "responds to things that Tempfile responds to" do
|
|
|
c6149d |
uploaded_file = Rack::Test::UploadedFile.new(test_file_path)
|
|
|
c6149d |
|
|
|
c6149d |
- uploaded_file.should respond_to(:close)
|
|
|
c6149d |
- uploaded_file.should respond_to(:close!)
|
|
|
c6149d |
- uploaded_file.should respond_to(:delete)
|
|
|
c6149d |
- uploaded_file.should respond_to(:length)
|
|
|
c6149d |
- uploaded_file.should respond_to(:open)
|
|
|
c6149d |
- uploaded_file.should respond_to(:path)
|
|
|
c6149d |
- uploaded_file.should respond_to(:size)
|
|
|
c6149d |
- uploaded_file.should respond_to(:unlink)
|
|
|
c6149d |
- uploaded_file.should respond_to(:read)
|
|
|
c6149d |
- uploaded_file.should respond_to(:original_filename)
|
|
|
c6149d |
- uploaded_file.should respond_to(:tempfile) # Allows calls to params[:file].tempfile
|
|
|
c6149d |
+ expect(uploaded_file).to respond_to(:close)
|
|
|
c6149d |
+ expect(uploaded_file).to respond_to(:close!)
|
|
|
c6149d |
+ expect(uploaded_file).to respond_to(:delete)
|
|
|
c6149d |
+ expect(uploaded_file).to respond_to(:length)
|
|
|
c6149d |
+ expect(uploaded_file).to respond_to(:open)
|
|
|
c6149d |
+ expect(uploaded_file).to respond_to(:path)
|
|
|
c6149d |
+ expect(uploaded_file).to respond_to(:size)
|
|
|
c6149d |
+ expect(uploaded_file).to respond_to(:unlink)
|
|
|
c6149d |
+ expect(uploaded_file).to respond_to(:read)
|
|
|
c6149d |
+ expect(uploaded_file).to respond_to(:original_filename)
|
|
|
c6149d |
+ expect(uploaded_file).to respond_to(:tempfile) # Allows calls to params[:file].tempfile
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
+ it "creates Tempfiles with original file's extension" do
|
|
|
c6149d |
+ uploaded_file = Rack::Test::UploadedFile.new(test_file_path)
|
|
|
c6149d |
+
|
|
|
c6149d |
+ expect(File.extname(uploaded_file.path)).to eq(".txt")
|
|
|
c6149d |
+ end
|
|
|
c6149d |
end
|
|
|
c6149d |
diff --git a/spec/rack/test/utils_spec.rb b/spec/rack/test/utils_spec.rb
|
|
|
c6149d |
index 4557c5b..b3d764d 100644
|
|
|
c6149d |
--- a/spec/rack/test/utils_spec.rb
|
|
|
c6149d |
+++ b/spec/rack/test/utils_spec.rb
|
|
|
c6149d |
@@ -5,48 +5,48 @@
|
|
|
c6149d |
|
|
|
c6149d |
describe "build_nested_query" do
|
|
|
c6149d |
it "converts empty strings to =" do
|
|
|
c6149d |
- build_nested_query("").should == "="
|
|
|
c6149d |
+ expect(build_nested_query("")).to eq("=")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "converts nil to an empty string" do
|
|
|
c6149d |
- build_nested_query(nil).should == ""
|
|
|
c6149d |
+ expect(build_nested_query(nil)).to eq("")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "converts hashes with nil values" do
|
|
|
c6149d |
- build_nested_query(:a => nil).should == "a"
|
|
|
c6149d |
+ expect(build_nested_query(:a => nil)).to eq("a")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "converts hashes" do
|
|
|
c6149d |
- build_nested_query(:a => 1).should == "a=1"
|
|
|
c6149d |
+ expect(build_nested_query(:a => 1)).to eq("a=1")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "converts hashes with multiple keys" do
|
|
|
c6149d |
hash = { :a => 1, :b => 2 }
|
|
|
c6149d |
- ["a=1&b=2", "b=2&a=1"].should include(build_nested_query(hash))
|
|
|
c6149d |
+ expect(["a=1&b=2", "b=2&a=1"]).to include(build_nested_query(hash))
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "converts arrays with one element" do
|
|
|
c6149d |
- build_nested_query(:a => [1]).should == "a[]=1"
|
|
|
c6149d |
+ expect(build_nested_query(:a => [1])).to eq("a[]=1")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "converts arrays with multiple elements" do
|
|
|
c6149d |
- build_nested_query(:a => [1, 2]).should == "a[]=1&a[]=2"
|
|
|
c6149d |
+ expect(build_nested_query(:a => [1, 2])).to eq("a[]=1&a[]=2")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "converts arrays with brackets '[]' in the name" do
|
|
|
c6149d |
- build_nested_query("a[]" => [1, 2]).should == "a%5B%5D=1&a%5B%5D=2"
|
|
|
c6149d |
+ expect(build_nested_query("a[]" => [1, 2])).to eq("a%5B%5D=1&a%5B%5D=2")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "converts nested hashes" do
|
|
|
c6149d |
- build_nested_query(:a => { :b => 1 }).should == "a[b]=1"
|
|
|
c6149d |
+ expect(build_nested_query(:a => { :b => 1 })).to eq("a[b]=1")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "converts arrays nested in a hash" do
|
|
|
c6149d |
- build_nested_query(:a => { :b => [1, 2] }).should == "a[b][]=1&a[b][]=2"
|
|
|
c6149d |
+ expect(build_nested_query(:a => { :b => [1, 2] })).to eq("a[b][]=1&a[b][]=2")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "converts arrays of hashes" do
|
|
|
c6149d |
- build_nested_query(:a => [{ :b => 2}, { :c => 3}]).should == "a[][b]=2&a[][c]=3"
|
|
|
c6149d |
+ expect(build_nested_query(:a => [{ :b => 2}, { :c => 3}])).to eq("a[][b]=2&a[][c]=3")
|
|
|
c6149d |
end
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
@@ -62,9 +62,9 @@
|
|
|
c6149d |
}
|
|
|
c6149d |
env = Rack::MockRequest.env_for("/", options)
|
|
|
c6149d |
params = Rack::Multipart.parse_multipart(env)
|
|
|
c6149d |
- check params["submit-name"].should == "Larry"
|
|
|
c6149d |
- check params["files"][:filename].should == "foo.txt"
|
|
|
c6149d |
- params["files"][:tempfile].read.should == "bar\n"
|
|
|
c6149d |
+ check expect(params["submit-name"]).to eq("Larry")
|
|
|
c6149d |
+ check expect(params["files"][:filename]).to eq("foo.txt")
|
|
|
c6149d |
+ expect(params["files"][:tempfile].read).to eq("bar\n")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "builds multipart bodies from array of files" do
|
|
|
c6149d |
@@ -78,13 +78,13 @@
|
|
|
c6149d |
}
|
|
|
c6149d |
env = Rack::MockRequest.env_for("/", options)
|
|
|
c6149d |
params = Rack::Multipart.parse_multipart(env)
|
|
|
c6149d |
- check params["submit-name"].should == "Larry"
|
|
|
c6149d |
+ check expect(params["submit-name"]).to eq("Larry")
|
|
|
c6149d |
|
|
|
c6149d |
- check params["files"][0][:filename].should == "foo.txt"
|
|
|
c6149d |
- params["files"][0][:tempfile].read.should == "bar\n"
|
|
|
c6149d |
+ check expect(params["files"][0][:filename]).to eq("foo.txt")
|
|
|
c6149d |
+ expect(params["files"][0][:tempfile].read).to eq("bar\n")
|
|
|
c6149d |
|
|
|
c6149d |
- check params["files"][1][:filename].should == "bar.txt"
|
|
|
c6149d |
- params["files"][1][:tempfile].read.should == "baz\n"
|
|
|
c6149d |
+ check expect(params["files"][1][:filename]).to eq("bar.txt")
|
|
|
c6149d |
+ expect(params["files"][1][:tempfile].read).to eq("baz\n")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "builds nested multipart bodies" do
|
|
|
c6149d |
@@ -98,10 +98,10 @@
|
|
|
c6149d |
}
|
|
|
c6149d |
env = Rack::MockRequest.env_for("/", options)
|
|
|
c6149d |
params = Rack::Multipart.parse_multipart(env)
|
|
|
c6149d |
- check params["people"][0]["submit-name"].should == "Larry"
|
|
|
c6149d |
- check params["people"][0]["files"][:filename].should == "foo.txt"
|
|
|
c6149d |
- params["people"][0]["files"][:tempfile].read.should == "bar\n"
|
|
|
c6149d |
- check params["foo"].should == ["1", "2"]
|
|
|
c6149d |
+ check expect(params["people"][0]["submit-name"]).to eq("Larry")
|
|
|
c6149d |
+ check expect(params["people"][0]["files"][:filename]).to eq("foo.txt")
|
|
|
c6149d |
+ expect(params["people"][0]["files"][:tempfile].read).to eq("bar\n")
|
|
|
c6149d |
+ check expect(params["foo"]).to eq(["1", "2"])
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "builds nested multipart bodies with an array of hashes" do
|
|
|
c6149d |
@@ -115,9 +115,9 @@
|
|
|
c6149d |
}
|
|
|
c6149d |
env = Rack::MockRequest.env_for("/", options)
|
|
|
c6149d |
params = Rack::Multipart.parse_multipart(env)
|
|
|
c6149d |
- check params["files"][:filename].should == "foo.txt"
|
|
|
c6149d |
- params["files"][:tempfile].read.should == "bar\n"
|
|
|
c6149d |
- check params["foo"].should == [{"id" => "1", "name" => "Dave"}, {"id" => "2", "name" => "Steve"}]
|
|
|
c6149d |
+ check expect(params["files"][:filename]).to eq("foo.txt")
|
|
|
c6149d |
+ expect(params["files"][:tempfile].read).to eq("bar\n")
|
|
|
c6149d |
+ check expect(params["foo"]).to eq([{"id" => "1", "name" => "Dave"}, {"id" => "2", "name" => "Steve"}])
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "builds nested multipart bodies with arbitrarily nested array of hashes" do
|
|
|
c6149d |
@@ -133,11 +133,11 @@
|
|
|
c6149d |
}
|
|
|
c6149d |
env = Rack::MockRequest.env_for("/", options)
|
|
|
c6149d |
params = Rack::Multipart.parse_multipart(env)
|
|
|
c6149d |
- check params["files"][:filename].should == "foo.txt"
|
|
|
c6149d |
- params["files"][:tempfile].read.should == "bar\n"
|
|
|
c6149d |
- check params["foo"].should == {"bar" => [{"id" => "1", "name" => "Dave"},
|
|
|
c6149d |
+ check expect(params["files"][:filename]).to eq("foo.txt")
|
|
|
c6149d |
+ expect(params["files"][:tempfile].read).to eq("bar\n")
|
|
|
c6149d |
+ check expect(params["foo"]).to eq({"bar" => [{"id" => "1", "name" => "Dave"},
|
|
|
c6149d |
{"id" => "2", "name" => "Steve", "qux" => [{"id" => '3', "name" => 'mike'},
|
|
|
c6149d |
- {"id" => '4', "name" => 'Joan'}]}]}
|
|
|
c6149d |
+ {"id" => '4', "name" => 'Joan'}]}]})
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it 'does not break with params that look nested, but are not' do
|
|
|
c6149d |
@@ -151,10 +151,10 @@
|
|
|
c6149d |
}
|
|
|
c6149d |
env = Rack::MockRequest.env_for("/", options)
|
|
|
c6149d |
params = Rack::Multipart.parse_multipart(env)
|
|
|
c6149d |
- check params["files"][0][:filename].should == "foo.txt"
|
|
|
c6149d |
- params["files"][0][:tempfile].read.should == "bar\n"
|
|
|
c6149d |
- check params["foo"][0].should == "1"
|
|
|
c6149d |
- check params["bar"][0].should == {"qux" => "2"}
|
|
|
c6149d |
+ check expect(params["files"][0][:filename]).to eq("foo.txt")
|
|
|
c6149d |
+ expect(params["files"][0][:tempfile].read).to eq("bar\n")
|
|
|
c6149d |
+ check expect(params["foo"][0]).to eq("1")
|
|
|
c6149d |
+ check expect(params["bar"][0]).to eq({"qux" => "2"})
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it 'allows for nested files' do
|
|
|
c6149d |
@@ -169,21 +169,21 @@
|
|
|
c6149d |
}
|
|
|
c6149d |
env = Rack::MockRequest.env_for("/", options)
|
|
|
c6149d |
params = Rack::Multipart.parse_multipart(env)
|
|
|
c6149d |
- check params["foo"][0]["id"].should == "1"
|
|
|
c6149d |
- check params["foo"][0]["data"][:filename].should == "foo.txt"
|
|
|
c6149d |
- params["foo"][0]["data"][:tempfile].read.should == "bar\n"
|
|
|
c6149d |
- check params["foo"][1].should == {"id" => "2", "data" => ["3", "4"]}
|
|
|
c6149d |
+ check expect(params["foo"][0]["id"]).to eq("1")
|
|
|
c6149d |
+ check expect(params["foo"][0]["data"][:filename]).to eq("foo.txt")
|
|
|
c6149d |
+ expect(params["foo"][0]["data"][:tempfile].read).to eq("bar\n")
|
|
|
c6149d |
+ check expect(params["foo"][1]).to eq({"id" => "2", "data" => ["3", "4"]})
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "returns nil if no UploadedFiles were used" do
|
|
|
c6149d |
data = build_multipart("people" => [{"submit-name" => "Larry", "files" => "contents"}])
|
|
|
c6149d |
- data.should be_nil
|
|
|
c6149d |
+ expect(data).to be_nil
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "raises ArgumentErrors if params is not a Hash" do
|
|
|
c6149d |
- lambda {
|
|
|
c6149d |
+ expect {
|
|
|
c6149d |
build_multipart("foo=bar")
|
|
|
c6149d |
- }.should raise_error(ArgumentError, "value must be a Hash")
|
|
|
c6149d |
+ }.to raise_error(ArgumentError, "value must be a Hash")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
def multipart_file(name)
|
|
|
c6149d |
diff --git a/spec/rack/test_spec.rb b/spec/rack/test_spec.rb
|
|
|
c6149d |
index ba862b2..a9e2136 100644
|
|
|
c6149d |
--- a/spec/rack/test_spec.rb
|
|
|
c6149d |
+++ b/spec/rack/test_spec.rb
|
|
|
c6149d |
@@ -4,137 +4,142 @@
|
|
|
c6149d |
describe "initialization" do
|
|
|
c6149d |
it "supports being initialized with a Rack::MockSession app" do
|
|
|
c6149d |
session = Rack::Test::Session.new(Rack::MockSession.new(app))
|
|
|
c6149d |
- session.request("/").should be_ok
|
|
|
c6149d |
+ expect(session.request("/")).to be_ok
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "supports being initialized with an app" do
|
|
|
c6149d |
session = Rack::Test::Session.new(app)
|
|
|
c6149d |
- session.request("/").should be_ok
|
|
|
c6149d |
+ expect(session.request("/")).to be_ok
|
|
|
c6149d |
end
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
describe "#request" do
|
|
|
c6149d |
it "requests the URI using GET by default" do
|
|
|
c6149d |
request "/"
|
|
|
c6149d |
- last_request.should be_get
|
|
|
c6149d |
- last_response.should be_ok
|
|
|
c6149d |
+ expect(last_request).to be_get
|
|
|
c6149d |
+ expect(last_response).to be_ok
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "returns a response" do
|
|
|
c6149d |
- request("/").should be_ok
|
|
|
c6149d |
+ expect(request("/")).to be_ok
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "uses the provided env" do
|
|
|
c6149d |
request "/", "X-Foo" => "bar"
|
|
|
c6149d |
- last_request.env["X-Foo"].should == "bar"
|
|
|
c6149d |
+ expect(last_request.env["X-Foo"]).to eq("bar")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "allows HTTP_HOST to be set" do
|
|
|
c6149d |
request "/", "HTTP_HOST" => "www.example.ua"
|
|
|
c6149d |
- last_request.env['HTTP_HOST'].should == "www.example.ua"
|
|
|
c6149d |
+ expect(last_request.env['HTTP_HOST']).to eq("www.example.ua")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "sets HTTP_HOST with port for non-default ports" do
|
|
|
c6149d |
request "http://foo.com:8080"
|
|
|
c6149d |
- last_request.env["HTTP_HOST"].should == "foo.com:8080"
|
|
|
c6149d |
+ expect(last_request.env["HTTP_HOST"]).to eq("foo.com:8080")
|
|
|
c6149d |
request "https://foo.com:8443"
|
|
|
c6149d |
- last_request.env["HTTP_HOST"].should == "foo.com:8443"
|
|
|
c6149d |
+ expect(last_request.env["HTTP_HOST"]).to eq("foo.com:8443")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "sets HTTP_HOST without port for default ports" do
|
|
|
c6149d |
request "http://foo.com"
|
|
|
c6149d |
- last_request.env["HTTP_HOST"].should == "foo.com"
|
|
|
c6149d |
+ expect(last_request.env["HTTP_HOST"]).to eq("foo.com")
|
|
|
c6149d |
request "http://foo.com:80"
|
|
|
c6149d |
- last_request.env["HTTP_HOST"].should == "foo.com"
|
|
|
c6149d |
+ expect(last_request.env["HTTP_HOST"]).to eq("foo.com")
|
|
|
c6149d |
request "https://foo.com:443"
|
|
|
c6149d |
- last_request.env["HTTP_HOST"].should == "foo.com"
|
|
|
c6149d |
+ expect(last_request.env["HTTP_HOST"]).to eq("foo.com")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "defaults to GET" do
|
|
|
c6149d |
request "/"
|
|
|
c6149d |
- last_request.env["REQUEST_METHOD"].should == "GET"
|
|
|
c6149d |
+ expect(last_request.env["REQUEST_METHOD"]).to eq("GET")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "defaults the REMOTE_ADDR to 127.0.0.1" do
|
|
|
c6149d |
request "/"
|
|
|
c6149d |
- last_request.env["REMOTE_ADDR"].should == "127.0.0.1"
|
|
|
c6149d |
+ expect(last_request.env["REMOTE_ADDR"]).to eq("127.0.0.1")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "sets rack.test to true in the env" do
|
|
|
c6149d |
request "/"
|
|
|
c6149d |
- last_request.env["rack.test"].should == true
|
|
|
c6149d |
+ expect(last_request.env["rack.test"]).to eq(true)
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "defaults to port 80" do
|
|
|
c6149d |
request "/"
|
|
|
c6149d |
- last_request.env["SERVER_PORT"].should == "80"
|
|
|
c6149d |
+ expect(last_request.env["SERVER_PORT"]).to eq("80")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "defaults to example.org" do
|
|
|
c6149d |
request "/"
|
|
|
c6149d |
- last_request.env["SERVER_NAME"].should == "example.org"
|
|
|
c6149d |
+ expect(last_request.env["SERVER_NAME"]).to eq("example.org")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "yields the response to a given block" do
|
|
|
c6149d |
request "/" do |response|
|
|
|
c6149d |
- response.should be_ok
|
|
|
c6149d |
+ expect(response).to be_ok
|
|
|
c6149d |
end
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "supports sending :params" do
|
|
|
c6149d |
request "/", :params => { "foo" => "bar" }
|
|
|
c6149d |
- last_request.GET["foo"].should == "bar"
|
|
|
c6149d |
+ expect(last_request.GET["foo"]).to eq("bar")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "doesn't follow redirects by default" do
|
|
|
c6149d |
request "/redirect"
|
|
|
c6149d |
- last_response.should be_redirect
|
|
|
c6149d |
- last_response.body.should be_empty
|
|
|
c6149d |
+ expect(last_response).to be_redirect
|
|
|
c6149d |
+ expect(last_response.body).to be_empty
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "allows passing :input in for POSTs" do
|
|
|
c6149d |
request "/", :method => :post, :input => "foo"
|
|
|
c6149d |
- last_request.env["rack.input"].read.should == "foo"
|
|
|
c6149d |
+ expect(last_request.env["rack.input"].read).to eq("foo")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "converts method names to a uppercase strings" do
|
|
|
c6149d |
request "/", :method => :put
|
|
|
c6149d |
- last_request.env["REQUEST_METHOD"].should == "PUT"
|
|
|
c6149d |
+ expect(last_request.env["REQUEST_METHOD"]).to eq("PUT")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "prepends a slash to the URI path" do
|
|
|
c6149d |
request "foo"
|
|
|
c6149d |
- last_request.env["PATH_INFO"].should == "/foo"
|
|
|
c6149d |
+ expect(last_request.env["PATH_INFO"]).to eq("/foo")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "accepts params and builds query strings for GET requests" do
|
|
|
c6149d |
request "/foo?baz=2", :params => {:foo => {:bar => "1"}}
|
|
|
c6149d |
- last_request.GET.should == { "baz" => "2", "foo" => { "bar" => "1" }}
|
|
|
c6149d |
+ expect(last_request.GET).to eq({ "baz" => "2", "foo" => { "bar" => "1" }})
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "parses query strings with repeated variable names correctly" do
|
|
|
c6149d |
request "/foo?bar=2&bar=3"
|
|
|
c6149d |
- last_request.GET.should == { "bar" => "3" }
|
|
|
c6149d |
+ expect(last_request.GET).to eq({ "bar" => "3" })
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "accepts raw input in params for GET requests" do
|
|
|
c6149d |
request "/foo?baz=2", :params => "foo[bar]=1"
|
|
|
c6149d |
- last_request.GET.should == { "baz" => "2", "foo" => { "bar" => "1" }}
|
|
|
c6149d |
+ expect(last_request.GET).to eq({ "baz" => "2", "foo" => { "bar" => "1" }})
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "does not rewrite a GET query string when :params is not supplied" do
|
|
|
c6149d |
request "/foo?a=1&b=2&c=3&e=4&d=5+%20"
|
|
|
c6149d |
- last_request.query_string.should == "a=1&b=2&c=3&e=4&d=5+%20"
|
|
|
c6149d |
+ expect(last_request.query_string).to eq("a=1&b=2&c=3&e=4&d=5+%20")
|
|
|
c6149d |
+ end
|
|
|
c6149d |
+
|
|
|
c6149d |
+ it "does not overwrite multiple query string keys" do
|
|
|
c6149d |
+ request "/foo?a=1&a=2", :params => { :bar => 1 }
|
|
|
c6149d |
+ expect(last_request.query_string).to eq("a=1&a=2&bar=1")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "accepts params and builds url encoded params for POST requests" do
|
|
|
c6149d |
request "/foo", :method => :post, :params => {:foo => {:bar => "1"}}
|
|
|
c6149d |
- last_request.env["rack.input"].read.should == "foo[bar]=1"
|
|
|
c6149d |
+ expect(last_request.env["rack.input"].read).to eq("foo[bar]=1")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "accepts raw input in params for POST requests" do
|
|
|
c6149d |
request "/foo", :method => :post, :params => "foo[bar]=1"
|
|
|
c6149d |
- last_request.env["rack.input"].read.should == "foo[bar]=1"
|
|
|
c6149d |
+ expect(last_request.env["rack.input"].read).to eq("foo[bar]=1")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
context "when the response body responds_to?(:close)" do
|
|
|
c6149d |
@@ -155,7 +160,7 @@ def close
|
|
|
c6149d |
|
|
|
c6149d |
it "closes response's body" do
|
|
|
c6149d |
body = CloseableBody.new
|
|
|
c6149d |
- body.should_receive(:close)
|
|
|
c6149d |
+ expect(body).to receive(:close)
|
|
|
c6149d |
|
|
|
c6149d |
app = lambda do |env|
|
|
|
c6149d |
[200, {"Content-Type" => "text/html", "Content-Length" => "13"}, body]
|
|
|
c6149d |
@@ -172,65 +177,65 @@ def close
|
|
|
c6149d |
|
|
|
c6149d |
session = Rack::Test::Session.new(Rack::MockSession.new(app))
|
|
|
c6149d |
session.request("/")
|
|
|
c6149d |
- session.last_response.body.should == "Hello, World!"
|
|
|
c6149d |
+ expect(session.last_response.body).to eq("Hello, World!")
|
|
|
c6149d |
end
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
context "when input is given" do
|
|
|
c6149d |
it "sends the input" do
|
|
|
c6149d |
request "/", :method => "POST", :input => "foo"
|
|
|
c6149d |
- last_request.env["rack.input"].read.should == "foo"
|
|
|
c6149d |
+ expect(last_request.env["rack.input"].read).to eq("foo")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "does not send a multipart request" do
|
|
|
c6149d |
request "/", :method => "POST", :input => "foo"
|
|
|
c6149d |
- last_request.env["CONTENT_TYPE"].should_not == "application/x-www-form-urlencoded"
|
|
|
c6149d |
+ expect(last_request.env["CONTENT_TYPE"]).not_to eq("application/x-www-form-urlencoded")
|
|
|
c6149d |
end
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
context "for a POST specified with :method" do
|
|
|
c6149d |
it "uses application/x-www-form-urlencoded as the CONTENT_TYPE" do
|
|
|
c6149d |
request "/", :method => "POST"
|
|
|
c6149d |
- last_request.env["CONTENT_TYPE"].should == "application/x-www-form-urlencoded"
|
|
|
c6149d |
+ expect(last_request.env["CONTENT_TYPE"]).to eq("application/x-www-form-urlencoded")
|
|
|
c6149d |
end
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
context "for a POST specified with REQUEST_METHOD" do
|
|
|
c6149d |
it "uses application/x-www-form-urlencoded as the CONTENT_TYPE" do
|
|
|
c6149d |
request "/", "REQUEST_METHOD" => "POST"
|
|
|
c6149d |
- last_request.env["CONTENT_TYPE"].should == "application/x-www-form-urlencoded"
|
|
|
c6149d |
+ expect(last_request.env["CONTENT_TYPE"]).to eq("application/x-www-form-urlencoded")
|
|
|
c6149d |
end
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
context "when CONTENT_TYPE is specified in the env" do
|
|
|
c6149d |
it "does not overwrite the CONTENT_TYPE" do
|
|
|
c6149d |
request "/", "CONTENT_TYPE" => "application/xml"
|
|
|
c6149d |
- last_request.env["CONTENT_TYPE"].should == "application/xml"
|
|
|
c6149d |
+ expect(last_request.env["CONTENT_TYPE"]).to eq("application/xml")
|
|
|
c6149d |
end
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
context "when the URL is https://" do
|
|
|
c6149d |
it "sets rack.url_scheme to https" do
|
|
|
c6149d |
get "https://example.org/"
|
|
|
c6149d |
- last_request.env["rack.url_scheme"].should == "https"
|
|
|
c6149d |
+ expect(last_request.env["rack.url_scheme"]).to eq("https")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "sets SERVER_PORT to 443" do
|
|
|
c6149d |
get "https://example.org/"
|
|
|
c6149d |
- last_request.env["SERVER_PORT"].should == "443"
|
|
|
c6149d |
+ expect(last_request.env["SERVER_PORT"]).to eq("443")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "sets HTTPS to on" do
|
|
|
c6149d |
get "https://example.org/"
|
|
|
c6149d |
- last_request.env["HTTPS"].should == "on"
|
|
|
c6149d |
+ expect(last_request.env["HTTPS"]).to eq("on")
|
|
|
c6149d |
end
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
context "for a XHR" do
|
|
|
c6149d |
it "sends XMLHttpRequest for the X-Requested-With header" do
|
|
|
c6149d |
request "/", :xhr => true
|
|
|
c6149d |
- last_request.env["HTTP_X_REQUESTED_WITH"].should == "XMLHttpRequest"
|
|
|
c6149d |
- last_request.should be_xhr
|
|
|
c6149d |
+ expect(last_request.env["HTTP_X_REQUESTED_WITH"]).to eq("XMLHttpRequest")
|
|
|
c6149d |
+ expect(last_request).to be_xhr
|
|
|
c6149d |
end
|
|
|
c6149d |
end
|
|
|
c6149d |
end
|
|
|
c6149d |
@@ -240,21 +245,21 @@ def close
|
|
|
c6149d |
header "User-Agent", "Firefox"
|
|
|
c6149d |
request "/"
|
|
|
c6149d |
|
|
|
c6149d |
- last_request.env["HTTP_USER_AGENT"].should == "Firefox"
|
|
|
c6149d |
+ expect(last_request.env["HTTP_USER_AGENT"]).to eq("Firefox")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "sets a Content-Type to be sent with requests" do
|
|
|
c6149d |
header "Content-Type", "application/json"
|
|
|
c6149d |
request "/"
|
|
|
c6149d |
|
|
|
c6149d |
- last_request.env["CONTENT_TYPE"].should == "application/json"
|
|
|
c6149d |
+ expect(last_request.env["CONTENT_TYPE"]).to eq("application/json")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "sets a Host to be sent with requests" do
|
|
|
c6149d |
header "Host", "www.example.ua"
|
|
|
c6149d |
request "/"
|
|
|
c6149d |
|
|
|
c6149d |
- last_request.env["HTTP_HOST"].should == "www.example.ua"
|
|
|
c6149d |
+ expect(last_request.env["HTTP_HOST"]).to eq("www.example.ua")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "persists across multiple requests" do
|
|
|
c6149d |
@@ -262,7 +267,7 @@ def close
|
|
|
c6149d |
request "/"
|
|
|
c6149d |
request "/"
|
|
|
c6149d |
|
|
|
c6149d |
- last_request.env["HTTP_USER_AGENT"].should == "Firefox"
|
|
|
c6149d |
+ expect(last_request.env["HTTP_USER_AGENT"]).to eq("Firefox")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "overwrites previously set headers" do
|
|
|
c6149d |
@@ -270,7 +275,7 @@ def close
|
|
|
c6149d |
header "User-Agent", "Safari"
|
|
|
c6149d |
request "/"
|
|
|
c6149d |
|
|
|
c6149d |
- last_request.env["HTTP_USER_AGENT"].should == "Safari"
|
|
|
c6149d |
+ expect(last_request.env["HTTP_USER_AGENT"]).to eq("Safari")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "can be used to clear a header" do
|
|
|
c6149d |
@@ -278,14 +283,14 @@ def close
|
|
|
c6149d |
header "User-Agent", nil
|
|
|
c6149d |
request "/"
|
|
|
c6149d |
|
|
|
c6149d |
- last_request.env.should_not have_key("HTTP_USER_AGENT")
|
|
|
c6149d |
+ expect(last_request.env).not_to have_key("HTTP_USER_AGENT")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "is overridden by headers sent during the request" do
|
|
|
c6149d |
header "User-Agent", "Firefox"
|
|
|
c6149d |
request "/", "HTTP_USER_AGENT" => "Safari"
|
|
|
c6149d |
|
|
|
c6149d |
- last_request.env["HTTP_USER_AGENT"].should == "Safari"
|
|
|
c6149d |
+ expect(last_request.env["HTTP_USER_AGENT"]).to eq("Safari")
|
|
|
c6149d |
end
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
@@ -294,7 +299,7 @@ def close
|
|
|
c6149d |
env "rack.session", {:csrf => 'token'}
|
|
|
c6149d |
request "/"
|
|
|
c6149d |
|
|
|
c6149d |
- last_request.env["rack.session"].should == {:csrf => 'token'}
|
|
|
c6149d |
+ expect(last_request.env["rack.session"]).to eq({:csrf => 'token'})
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "persists across multiple requests" do
|
|
|
c6149d |
@@ -302,7 +307,7 @@ def close
|
|
|
c6149d |
request "/"
|
|
|
c6149d |
request "/"
|
|
|
c6149d |
|
|
|
c6149d |
- last_request.env["rack.session"].should == {:csrf => 'token'}
|
|
|
c6149d |
+ expect(last_request.env["rack.session"]).to eq({:csrf => 'token'})
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "overwrites previously set envs" do
|
|
|
c6149d |
@@ -310,7 +315,7 @@ def close
|
|
|
c6149d |
env "rack.session", {:some => :thing}
|
|
|
c6149d |
request "/"
|
|
|
c6149d |
|
|
|
c6149d |
- last_request.env["rack.session"].should == {:some => :thing}
|
|
|
c6149d |
+ expect(last_request.env["rack.session"]).to eq({:some => :thing})
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "can be used to clear a env" do
|
|
|
c6149d |
@@ -318,14 +323,14 @@ def close
|
|
|
c6149d |
env "rack.session", nil
|
|
|
c6149d |
request "/"
|
|
|
c6149d |
|
|
|
c6149d |
- last_request.env.should_not have_key("X_CSRF_TOKEN")
|
|
|
c6149d |
+ expect(last_request.env).not_to have_key("X_CSRF_TOKEN")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "is overridden by envs sent during the request" do
|
|
|
c6149d |
env "rack.session", {:csrf => 'token'}
|
|
|
c6149d |
request "/", "rack.session" => {:some => :thing}
|
|
|
c6149d |
|
|
|
c6149d |
- last_request.env["rack.session"].should == {:some => :thing}
|
|
|
c6149d |
+ expect(last_request.env["rack.session"]).to eq({:some => :thing})
|
|
|
c6149d |
end
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
@@ -334,7 +339,7 @@ def close
|
|
|
c6149d |
authorize "bryan", "secret"
|
|
|
c6149d |
request "/"
|
|
|
c6149d |
|
|
|
c6149d |
- last_request.env["HTTP_AUTHORIZATION"].should == "Basic YnJ5YW46c2VjcmV0\n"
|
|
|
c6149d |
+ expect(last_request.env["HTTP_AUTHORIZATION"]).to eq("Basic YnJ5YW46c2VjcmV0\n")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "includes the header for subsequent requests" do
|
|
|
c6149d |
@@ -342,7 +347,7 @@ def close
|
|
|
c6149d |
request "/"
|
|
|
c6149d |
request "/"
|
|
|
c6149d |
|
|
|
c6149d |
- last_request.env["HTTP_AUTHORIZATION"].should == "Basic YnJ5YW46c2VjcmV0\n"
|
|
|
c6149d |
+ expect(last_request.env["HTTP_AUTHORIZATION"]).to eq("Basic YnJ5YW46c2VjcmV0\n")
|
|
|
c6149d |
end
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
@@ -351,56 +356,56 @@ def close
|
|
|
c6149d |
get "/redirect"
|
|
|
c6149d |
follow_redirect!
|
|
|
c6149d |
|
|
|
c6149d |
- last_response.should_not be_redirect
|
|
|
c6149d |
- last_response.body.should == "You've been redirected"
|
|
|
c6149d |
- last_request.env["HTTP_REFERER"].should eql("http://example.org/redirect")
|
|
|
c6149d |
+ expect(last_response).not_to be_redirect
|
|
|
c6149d |
+ expect(last_response.body).to eq("You've been redirected")
|
|
|
c6149d |
+ expect(last_request.env["HTTP_REFERER"]).to eql("http://example.org/redirect")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "does not include params when following the redirect" do
|
|
|
c6149d |
get "/redirect", { "foo" => "bar" }
|
|
|
c6149d |
follow_redirect!
|
|
|
c6149d |
|
|
|
c6149d |
- last_request.GET.should == {}
|
|
|
c6149d |
+ expect(last_request.GET).to eq({})
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "raises an error if the last_response is not set" do
|
|
|
c6149d |
- lambda {
|
|
|
c6149d |
+ expect {
|
|
|
c6149d |
follow_redirect!
|
|
|
c6149d |
- }.should raise_error(Rack::Test::Error)
|
|
|
c6149d |
+ }.to raise_error(Rack::Test::Error)
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "raises an error if the last_response is not a redirect" do
|
|
|
c6149d |
get "/"
|
|
|
c6149d |
|
|
|
c6149d |
- lambda {
|
|
|
c6149d |
+ expect {
|
|
|
c6149d |
follow_redirect!
|
|
|
c6149d |
- }.should raise_error(Rack::Test::Error)
|
|
|
c6149d |
+ }.to raise_error(Rack::Test::Error)
|
|
|
c6149d |
end
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
describe "#last_request" do
|
|
|
c6149d |
it "returns the most recent request" do
|
|
|
c6149d |
request "/"
|
|
|
c6149d |
- last_request.env["PATH_INFO"].should == "/"
|
|
|
c6149d |
+ expect(last_request.env["PATH_INFO"]).to eq("/")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "raises an error if no requests have been issued" do
|
|
|
c6149d |
- lambda {
|
|
|
c6149d |
+ expect {
|
|
|
c6149d |
last_request
|
|
|
c6149d |
- }.should raise_error(Rack::Test::Error)
|
|
|
c6149d |
+ }.to raise_error(Rack::Test::Error)
|
|
|
c6149d |
end
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
describe "#last_response" do
|
|
|
c6149d |
it "returns the most recent response" do
|
|
|
c6149d |
request "/"
|
|
|
c6149d |
- last_response["Content-Type"].should == "text/html;charset=utf-8"
|
|
|
c6149d |
+ expect(last_response["Content-Type"]).to eq("text/html;charset=utf-8")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "raises an error if no requests have been issued" do
|
|
|
c6149d |
- lambda {
|
|
|
c6149d |
+ expect {
|
|
|
c6149d |
last_response
|
|
|
c6149d |
- }.should raise_error
|
|
|
c6149d |
+ }.to raise_error(Rack::Test::Error)
|
|
|
c6149d |
end
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
@@ -413,7 +418,7 @@ def close
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
get "/"
|
|
|
c6149d |
- ran.should == true
|
|
|
c6149d |
+ expect(ran).to eq(true)
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "runs multiple callbacks" do
|
|
|
c6149d |
@@ -426,7 +431,7 @@ def close
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
get "/"
|
|
|
c6149d |
- count.should == 2
|
|
|
c6149d |
+ expect(count).to eq(2)
|
|
|
c6149d |
end
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
@@ -439,27 +444,27 @@ def verb
|
|
|
c6149d |
|
|
|
c6149d |
it "uses the provided params hash" do
|
|
|
c6149d |
get "/", :foo => "bar"
|
|
|
c6149d |
- last_request.GET.should == { "foo" => "bar" }
|
|
|
c6149d |
+ expect(last_request.GET).to eq({ "foo" => "bar" })
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "sends params with parens in names" do
|
|
|
c6149d |
get "/", "foo(1i)" => "bar"
|
|
|
c6149d |
- last_request.GET["foo(1i)"].should == "bar"
|
|
|
c6149d |
+ expect(last_request.GET["foo(1i)"]).to eq("bar")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "supports params with encoding sensitive names" do
|
|
|
c6149d |
get "/", "foo bar" => "baz"
|
|
|
c6149d |
- last_request.GET["foo bar"].should == "baz"
|
|
|
c6149d |
+ expect(last_request.GET["foo bar"]).to eq("baz")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "supports params with nested encoding sensitive names" do
|
|
|
c6149d |
get "/", "boo" => {"foo bar" => "baz"}
|
|
|
c6149d |
- last_request.GET.should == {"boo" => {"foo bar" => "baz"}}
|
|
|
c6149d |
+ expect(last_request.GET).to eq({"boo" => {"foo bar" => "baz"}})
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "accepts params in the path" do
|
|
|
c6149d |
get "/?foo=bar"
|
|
|
c6149d |
- last_request.GET.should == { "foo" => "bar" }
|
|
|
c6149d |
+ expect(last_request.GET).to eq({ "foo" => "bar" })
|
|
|
c6149d |
end
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
@@ -480,28 +485,28 @@ def verb
|
|
|
c6149d |
|
|
|
c6149d |
it "uses the provided params hash" do
|
|
|
c6149d |
post "/", :foo => "bar"
|
|
|
c6149d |
- last_request.POST.should == { "foo" => "bar" }
|
|
|
c6149d |
+ expect(last_request.POST).to eq({ "foo" => "bar" })
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "supports params with encoding sensitive names" do
|
|
|
c6149d |
post "/", "foo bar" => "baz"
|
|
|
c6149d |
- last_request.POST["foo bar"].should == "baz"
|
|
|
c6149d |
+ expect(last_request.POST["foo bar"]).to eq("baz")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "uses application/x-www-form-urlencoded as the CONTENT_TYPE" do
|
|
|
c6149d |
post "/"
|
|
|
c6149d |
- last_request.env["CONTENT_TYPE"].should == "application/x-www-form-urlencoded"
|
|
|
c6149d |
+ expect(last_request.env["CONTENT_TYPE"]).to eq("application/x-www-form-urlencoded")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "accepts a body" do
|
|
|
c6149d |
post "/", "Lobsterlicious!"
|
|
|
c6149d |
- last_request.body.read.should == "Lobsterlicious!"
|
|
|
c6149d |
+ expect(last_request.body.read).to eq("Lobsterlicious!")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
context "when CONTENT_TYPE is specified in the env" do
|
|
|
c6149d |
it "does not overwrite the CONTENT_TYPE" do
|
|
|
c6149d |
post "/", {}, { "CONTENT_TYPE" => "application/xml" }
|
|
|
c6149d |
- last_request.env["CONTENT_TYPE"].should == "application/xml"
|
|
|
c6149d |
+ expect(last_request.env["CONTENT_TYPE"]).to eq("application/xml")
|
|
|
c6149d |
end
|
|
|
c6149d |
end
|
|
|
c6149d |
end
|
|
|
c6149d |
@@ -515,7 +520,7 @@ def verb
|
|
|
c6149d |
|
|
|
c6149d |
it "accepts a body" do
|
|
|
c6149d |
put "/", "Lobsterlicious!"
|
|
|
c6149d |
- last_request.body.read.should == "Lobsterlicious!"
|
|
|
c6149d |
+ expect(last_request.body.read).to eq("Lobsterlicious!")
|
|
|
c6149d |
end
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
@@ -528,7 +533,7 @@ def verb
|
|
|
c6149d |
|
|
|
c6149d |
it "accepts a body" do
|
|
|
c6149d |
patch "/", "Lobsterlicious!"
|
|
|
c6149d |
- last_request.body.read.should == "Lobsterlicious!"
|
|
|
c6149d |
+ expect(last_request.body.read).to eq("Lobsterlicious!")
|
|
|
c6149d |
end
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
|
|
|
c6149d |
index 0666c42..de84ddf 100644
|
|
|
c6149d |
--- a/spec/spec_helper.rb
|
|
|
c6149d |
+++ b/spec/spec_helper.rb
|
|
|
c6149d |
@@ -29,41 +29,41 @@ def check(*args)
|
|
|
c6149d |
it "requests the URL using VERB" do
|
|
|
c6149d |
send(verb, "/")
|
|
|
c6149d |
|
|
|
c6149d |
- check last_request.env["REQUEST_METHOD"].should == verb.upcase
|
|
|
c6149d |
- last_response.should be_ok
|
|
|
c6149d |
+ check expect(last_request.env["REQUEST_METHOD"]).to eq(verb.upcase)
|
|
|
c6149d |
+ expect(last_response).to be_ok
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "uses the provided env" do
|
|
|
c6149d |
send(verb, "/", {}, { "HTTP_USER_AGENT" => "Rack::Test" })
|
|
|
c6149d |
- last_request.env["HTTP_USER_AGENT"].should == "Rack::Test"
|
|
|
c6149d |
+ expect(last_request.env["HTTP_USER_AGENT"]).to eq("Rack::Test")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "yields the response to a given block" do
|
|
|
c6149d |
yielded = false
|
|
|
c6149d |
|
|
|
c6149d |
send(verb, "/") do |response|
|
|
|
c6149d |
- response.should be_ok
|
|
|
c6149d |
+ expect(response).to be_ok
|
|
|
c6149d |
yielded = true
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
- yielded.should be_true
|
|
|
c6149d |
+ expect(yielded).to be_truthy
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "sets the HTTP_HOST header with port" do
|
|
|
c6149d |
send(verb, "http://example.org:8080/uri")
|
|
|
c6149d |
- last_request.env["HTTP_HOST"].should == "example.org:8080"
|
|
|
c6149d |
+ expect(last_request.env["HTTP_HOST"]).to eq("example.org:8080")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
it "sets the HTTP_HOST header without port" do
|
|
|
c6149d |
send(verb, "/uri")
|
|
|
c6149d |
- last_request.env["HTTP_HOST"].should == "example.org"
|
|
|
c6149d |
+ expect(last_request.env["HTTP_HOST"]).to eq("example.org")
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
context "for a XHR" do
|
|
|
c6149d |
it "sends XMLHttpRequest for the X-Requested-With header" do
|
|
|
c6149d |
send(verb, "/", {}, { :xhr => true })
|
|
|
c6149d |
- last_request.env["HTTP_X_REQUESTED_WITH"].should == "XMLHttpRequest"
|
|
|
c6149d |
- last_request.should be_xhr
|
|
|
c6149d |
+ expect(last_request.env["HTTP_X_REQUESTED_WITH"]).to eq("XMLHttpRequest")
|
|
|
c6149d |
+ expect(last_request).to be_xhr
|
|
|
c6149d |
end
|
|
|
c6149d |
end
|
|
|
c6149d |
end
|
|
|
c6149d |
diff --git a/spec/support/matchers/body.rb b/spec/support/matchers/body.rb
|
|
|
c6149d |
index 0c83348..a79c1ff 100644
|
|
|
c6149d |
--- a/spec/support/matchers/body.rb
|
|
|
c6149d |
+++ b/spec/support/matchers/body.rb
|
|
|
c6149d |
@@ -1,6 +1,6 @@
|
|
|
c6149d |
RSpec::Matchers.define :have_body do |expected|
|
|
|
c6149d |
match do |response|
|
|
|
c6149d |
- response.body.should == expected
|
|
|
c6149d |
+ expect(response.body).to eq(expected)
|
|
|
c6149d |
end
|
|
|
c6149d |
|
|
|
c6149d |
description do
|