Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests should not depent on set order #298

Merged
merged 2 commits into from
Jan 7, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions test/spec_response.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require 'set'
require 'rack/response'
require 'stringio'

Expand Down Expand Up @@ -125,7 +124,6 @@
response = Rack::Response.new
response.redirect "/foo"
status, header, body = response.finish

status.should.equal 302
header["Location"].should.equal "/foo"

Expand All @@ -147,7 +145,12 @@
str = ""; body.each { |part| str << part }
str.should.equal "foobar"

r = Rack::Response.new(["foo", "bar"].to_set)
object_with_each = Object.new
def object_with_each.each
yield "foo"
yield "bar"
end
r = Rack::Response.new(object_with_each)
r.write "foo"
status, header, body = r.finish
str = ""; body.each { |part| str << part }
Expand Down
21 changes: 15 additions & 6 deletions test/spec_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
require 'rack/mock'

describe Rack::Utils do

# A helper method which checks
# if certain query parameters
# are equal.
def equal_query_to(query)
parts = query.split('&')
lambda{|other| (parts & other.split('&')) == parts }
end

def kcodeu
one8 = RUBY_VERSION.to_f < 1.9
default_kcode, $KCODE = $KCODE, 'U' if one8
Expand Down Expand Up @@ -187,13 +196,13 @@ def kcodeu
end

should "build query strings correctly" do
Rack::Utils.build_query("foo" => "bar").should.equal "foo=bar"
Rack::Utils.build_query("foo" => "bar").should.be equal_query_to("foo=bar")
Rack::Utils.build_query("foo" => ["bar", "quux"]).
should.equal "foo=bar&foo=quux"
should.be equal_query_to("foo=bar&foo=quux")
Rack::Utils.build_query("foo" => "1", "bar" => "2").
should.equal "foo=1&bar=2"
should.be equal_query_to("foo=1&bar=2")
Rack::Utils.build_query("my weird field" => "q1!2\"'w$5&7/z8)?").
should.equal "my+weird+field=q1%212%22%27w%245%267%2Fz8%29%3F"
should.be equal_query_to("my+weird+field=q1%212%22%27w%245%267%2Fz8%29%3F")
end

should "build nested query strings correctly" do
Expand All @@ -202,9 +211,9 @@ def kcodeu
Rack::Utils.build_nested_query("foo" => "bar").should.equal "foo=bar"

Rack::Utils.build_nested_query("foo" => "1", "bar" => "2").
should.equal "foo=1&bar=2"
should.be equal_query_to("foo=1&bar=2")
Rack::Utils.build_nested_query("my weird field" => "q1!2\"'w$5&7/z8)?").
should.equal "my+weird+field=q1%212%22%27w%245%267%2Fz8%29%3F"
should.be equal_query_to("my+weird+field=q1%212%22%27w%245%267%2Fz8%29%3F")

Rack::Utils.build_nested_query("foo" => [nil]).
should.equal "foo[]"
Expand Down