Skip to content

Commit

Permalink
Update to latest rspec version and syntax.
Browse files Browse the repository at this point in the history
In order to make it easier to merge other pull requests,
we should update to rspec 3.
This PR updats the Gemfile.lock to use rspec 3.4, it also
updats the test syntax to match the new rspec testing style.

This Change has been ported from
[this contribution](https://github.com/brynary/rack-test/pull/134/commits)
  • Loading branch information
Dennis Sivia authored and perlun committed Apr 21, 2017
1 parent 0cd8537 commit 7536f85
Show file tree
Hide file tree
Showing 9 changed files with 243 additions and 237 deletions.
26 changes: 17 additions & 9 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,26 @@ GEM
specs:
codeclimate-test-reporter (0.3.0)
simplecov (>= 0.7.1, < 1.0.0)
diff-lcs (1.2.3)
diff-lcs (1.2.5)
docile (1.1.3)
multi_json (1.9.0)
rack (1.5.2)
rack-protection (1.5.0)
rack
rake (10.0.4)
rspec (2.13.0)
rspec-core (~> 2.13.0)
rspec-expectations (~> 2.13.0)
rspec-mocks (~> 2.13.0)
rspec-core (2.13.1)
rspec-expectations (2.13.0)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.13.1)
rspec (3.4.0)
rspec-core (~> 3.4.0)
rspec-expectations (~> 3.4.0)
rspec-mocks (~> 3.4.0)
rspec-core (3.4.3)
rspec-support (~> 3.4.0)
rspec-expectations (3.4.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.4.0)
rspec-mocks (3.4.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.4.0)
rspec-support (3.4.1)
simplecov (0.8.2)
docile (~> 1.1.0)
multi_json
Expand All @@ -39,3 +44,6 @@ DEPENDENCIES
rake
rspec
sinatra

BUNDLED WITH
1.11.2
98 changes: 48 additions & 50 deletions spec/rack/test/cookie_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,215 +5,213 @@
context "cookies" do
it "keeps a cookie jar" do
get "/cookies/show"
check last_request.cookies.should == {}
check expect(last_request.cookies).to eq({})

get "/cookies/set", "value" => "1"
get "/cookies/show"
last_request.cookies.should == { "value" => "1" }
expect(last_request.cookies).to eq({ "value" => "1" })
end

it "doesn't send expired cookies" do
get "/cookies/set", "value" => "1"
now = Time.now
Time.stub!(:now => now + 60)
allow(Time).to receive_messages(:now => now + 60)
get "/cookies/show"
last_request.cookies.should == {}
expect(last_request.cookies).to eq({})
end

it "cookie path defaults to the uri of the document that was requested" do
pending "See issue rack-test github issue #50" do
post "/cookies/default-path", "value" => "cookie"
get "/cookies/default-path"
check last_request.cookies.should == { "simple"=>"cookie" }
get "/cookies/show"
check last_request.cookies.should == { }
end
skip "See issue rack-test github issue #50"
post "/cookies/default-path", "value" => "cookie"
get "/cookies/default-path"
expect(last_request.cookies).to eq({ "simple"=>"cookie" })
get "/cookies/show"
expect(last_request.cookies).to eq({})
end

it "escapes cookie values" do
jar = Rack::Test::CookieJar.new
jar["value"] = "foo;abc"
jar["value"].should == "foo;abc"
expect(jar["value"]).to eq("foo;abc")
end

it "deletes cookies directly from the CookieJar" do
jar = Rack::Test::CookieJar.new
jar["abcd"] = "1234"
jar["abcd"].should == "1234"
expect(jar["abcd"]).to eq("1234")
jar.delete("abcd")
jar["abcd"].should == nil
expect(jar["abcd"]).to eq(nil)
end

it "doesn't send cookies with the wrong domain" do
get "http://www.example.com/cookies/set", "value" => "1"
get "http://www.other.example/cookies/show"
last_request.cookies.should == {}
expect(last_request.cookies).to eq({})
end

it "doesn't send cookies with the wrong path" do
get "/cookies/set", "value" => "1"
get "/not-cookies/show"
last_request.cookies.should == {}
expect(last_request.cookies).to eq({})
end

it "persists cookies across requests that don't return any cookie headers" do
get "/cookies/set", "value" => "1"
get "/void"
get "/cookies/show"
last_request.cookies.should == { "value" => "1" }
expect(last_request.cookies).to eq({ "value" => "1" })
end

it "deletes cookies" do
get "/cookies/set", "value" => "1"
get "/cookies/delete"
get "/cookies/show"
last_request.cookies.should == { }
expect(last_request.cookies).to eq({ })
end

it "respects cookie domains when no domain is explicitly set" do
pending "FIXME: www.example.org should not get the first cookie" do
request("http://example.org/cookies/count").should have_body("1")
request("http://www.example.org/cookies/count").should have_body("1")
request("http://example.org/cookies/count").should have_body("2")
request("http://www.example.org/cookies/count").should have_body("2")
end
skip "FIXME: www.example.org should not get the first cookie"
expect(request("http://example.org/cookies/count")).to have_body("1")
expect(request("http://www.example.org/cookies/count")).to have_body("1")
expect(request("http://example.org/cookies/count")).to have_body("2")
expect(request("http://www.example.org/cookies/count")).to have_body("2")
end

it "treats domains case insensitively" do
get "http://example.com/cookies/set", "value" => "1"
get "http://EXAMPLE.COM/cookies/show"
last_request.cookies.should == { "value" => "1" }
expect(last_request.cookies).to eq({ "value" => "1" })
end

it "treats paths case sensitively" do
get "/cookies/set", "value" => "1"
get "/COOKIES/show"
last_request.cookies.should == {}
expect(last_request.cookies).to eq({})
end

it "prefers more specific cookies" do
get "http://example.com/cookies/set", "value" => "domain"
get "http://sub.example.com/cookies/set", "value" => "sub"

get "http://sub.example.com/cookies/show"
check last_request.cookies.should == { "value" => "sub" }
check expect(last_request.cookies).to eq({ "value" => "sub" })

get "http://example.com/cookies/show"
last_request.cookies.should == { "value" => "domain" }
expect(last_request.cookies).to eq({ "value" => "domain" })
end

it "treats cookie names case insensitively" do
get "/cookies/set", "value" => "lowercase"
get "/cookies/set-uppercase", "value" => "UPPERCASE"
get "/cookies/show"
last_request.cookies.should == { "VALUE" => "UPPERCASE" }
expect(last_request.cookies).to eq({ "VALUE" => "UPPERCASE" })
end

it "defaults the domain to the request domain" do
get "http://example.com/cookies/set-simple", "value" => "cookie"
get "http://example.com/cookies/show"
check last_request.cookies.should == { "simple" => "cookie" }
check expect(last_request.cookies).to eq({ "simple" => "cookie" })

get "http://other.example/cookies/show"
last_request.cookies.should == {}
expect(last_request.cookies).to eq({})
end

it "defaults the domain to the request path up to the last slash" do
get "/cookies/set-simple", "value" => "1"
get "/not-cookies/show"
last_request.cookies.should == {}
expect(last_request.cookies).to eq({})
end

it "supports secure cookies" do
get "https://example.com/cookies/set-secure", "value" => "set"
get "http://example.com/cookies/show"
check last_request.cookies.should == {}
check expect(last_request.cookies).to eq({})

get "https://example.com/cookies/show"
last_request.cookies.should == { "secure-cookie" => "set" }
rack_mock_session.cookie_jar['secure-cookie'].should == 'set'
expect(last_request.cookies).to eq({ "secure-cookie" => "set" })
expect(rack_mock_session.cookie_jar['secure-cookie']).to eq('set')
end

it "keeps separate cookie jars for different domains" do
get "http://example.com/cookies/set", "value" => "example"
get "http://example.com/cookies/show"
check last_request.cookies.should == { "value" => "example" }
check expect(last_request.cookies).to eq({ "value" => "example" })

get "http://other.example/cookies/set", "value" => "other"
get "http://other.example/cookies/show"
check last_request.cookies.should == { "value" => "other" }
check expect(last_request.cookies).to eq({ "value" => "other" })

get "http://example.com/cookies/show"
last_request.cookies.should == { "value" => "example" }
expect(last_request.cookies).to eq({ "value" => "example" })
end

it "keeps one cookie jar for domain and its subdomains" do
get "http://example.org/cookies/subdomain"
get "http://example.org/cookies/subdomain"
last_request.cookies.should == { "count" => "1" }
expect(last_request.cookies).to eq({ "count" => "1" })

get "http://foo.example.org/cookies/subdomain"
last_request.cookies.should == { "count" => "2" }
expect(last_request.cookies).to eq({ "count" => "2" })
end

it "allows cookies to be cleared" do
get "/cookies/set", "value" => "1"
clear_cookies
get "/cookies/show"
last_request.cookies.should == {}
expect(last_request.cookies).to eq({})
end

it "allow cookies to be set" do
set_cookie "value=10"
get "/cookies/show"
last_request.cookies.should == { "value" => "10" }
expect(last_request.cookies).to eq({ "value" => "10" })
end

it "allows an array of cookies to be set" do
set_cookie ["value=10", "foo=bar"]
get "/cookies/show"
last_request.cookies.should == { "value" => "10", "foo" => "bar" }
expect(last_request.cookies).to eq({ "value" => "10", "foo" => "bar" })
end

it "skips emtpy string cookies" do
set_cookie "value=10\n\nfoo=bar"
get "/cookies/show"
last_request.cookies.should == { "value" => "10", "foo" => "bar" }
expect(last_request.cookies).to eq({ "value" => "10", "foo" => "bar" })
end

it "parses multiple cookies properly" do
get "/cookies/set-multiple"
get "/cookies/show"
last_request.cookies.should == { "key1" => "value1", "key2" => "value2" }
expect(last_request.cookies).to eq({ "key1" => "value1", "key2" => "value2" })
end

it "supports multiple sessions" do
with_session(:first) do
get "/cookies/set", "value" => "1"
get "/cookies/show"
last_request.cookies.should == { "value" => "1" }
expect(last_request.cookies).to eq({ "value" => "1" })
end

with_session(:second) do
get "/cookies/show"
last_request.cookies.should == { }
expect(last_request.cookies).to eq({ })
end
end

it "uses :default as the default session name" do
get "/cookies/set", "value" => "1"
get "/cookies/show"
check last_request.cookies.should == { "value" => "1" }
check expect(last_request.cookies).to eq({ "value" => "1" })

with_session(:default) do
get "/cookies/show"
last_request.cookies.should == { "value" => "1" }
expect(last_request.cookies).to eq({ "value" => "1" })
end
end

it "accepts explicitly provided cookies" do
request "/cookies/show", :cookie => "value=1"
last_request.cookies.should == { "value" => "1" }
expect(last_request.cookies).to eq({ "value" => "1" })
end
end
end
10 changes: 5 additions & 5 deletions spec/rack/test/digest_auth_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,31 @@ def app
it 'incorrectly authenticates GETs' do
digest_authorize 'foo', 'bar'
get '/'
last_response.should be_challenge
expect(last_response).to be_challenge
end

it "correctly authenticates GETs" do
digest_authorize "alice", "correct-password"
response = get "/"
response.should be_ok
expect(response).to be_ok
end

it "correctly authenticates GETs with params" do
digest_authorize "alice", "correct-password"
response = get "/", "foo" => "bar"
response.should be_ok
expect(response).to be_ok
end

it "correctly authenticates POSTs" do
digest_authorize "alice", "correct-password"
response = post "/"
response.should be_ok
expect(response).to be_ok
end

it "returns a re-challenge if authenticating incorrectly" do
digest_authorize "alice", "incorrect-password"
response = get "/"
response.should be_challenge
expect(response).to be_challenge
end

end
Expand Down
Loading

0 comments on commit 7536f85

Please sign in to comment.