rack-test 0.5.4 → 0.5.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore CHANGED
@@ -3,3 +3,4 @@ doc
3
3
  coverage
4
4
  VERSION
5
5
  *.rbc
6
+ .bundle
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source :rubygems
2
+
3
+ gem 'rspec'
4
+ gem "rack"
5
+ gem "sinatra"
data/Gemfile.lock ADDED
@@ -0,0 +1,23 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.2)
5
+ rack (1.2.1)
6
+ rspec (2.3.0)
7
+ rspec-core (~> 2.3.0)
8
+ rspec-expectations (~> 2.3.0)
9
+ rspec-mocks (~> 2.3.0)
10
+ rspec-core (2.3.1)
11
+ rspec-expectations (2.3.0)
12
+ diff-lcs (~> 1.1.2)
13
+ rspec-mocks (2.3.0)
14
+ sinatra (1.0)
15
+ rack (>= 1.0)
16
+
17
+ PLATFORMS
18
+ ruby
19
+
20
+ DEPENDENCIES
21
+ rack
22
+ rspec
23
+ sinatra
data/History.txt CHANGED
@@ -1,4 +1,25 @@
1
- == Git
1
+ == 0.5.7 / 2011-01-01
2
+
3
+ * Bug fixes
4
+
5
+ * If no URI is present, include all cookies (Pratik Naik)
6
+
7
+ == 0.5.6 / 2010-09-25
8
+
9
+ * Bug fixes
10
+
11
+ * Use parse_nested_query for parsing URI like Rack does (Eugene Bolshakov)
12
+ * Don't depend on ActiveSupport extension to String (Bryan Helmkamp)
13
+ * Do not overwrite HTTP_HOST if it is set (Krekoten' Marjan)
14
+
15
+ == 0.5.5 / 2010-09-22
16
+
17
+ * Bug fixes
18
+
19
+ * Fix encoding of file uploads on Ruby 1.9 (Alan Kennedy)
20
+ * Set env["HTTP_HOST"] when making requests (Istvan Hoka)
21
+
22
+ == 0.5.4 / 2010-05-26
2
23
 
3
24
  * Bug fixes
4
25
 
data/Rakefile CHANGED
@@ -1,31 +1,25 @@
1
1
  require "rubygems"
2
2
 
3
- begin
4
- require "spec/rake/spectask"
5
- rescue LoadError
6
- desc "Run specs"
7
- task(:spec) { $stderr.puts '`gem install rspec` to run specs' }
8
- else
9
- Spec::Rake::SpecTask.new do |t|
10
- t.spec_opts = ['--options', "\"#{File.dirname(__FILE__)}/spec/spec.opts\""]
11
- t.libs << 'lib'
12
- t.libs << 'spec'
13
- t.warning = true
14
- end
15
3
 
16
- task :default => :spec
4
+ require 'rspec/core'
5
+ require "rspec/core/rake_task"
17
6
 
18
- desc "Run all specs in spec directory with RCov"
19
- Spec::Rake::SpecTask.new(:rcov) do |t|
20
- t.spec_opts = ['--options', "\"#{File.dirname(__FILE__)}/spec/spec.opts\""]
21
- t.libs << 'lib'
22
- t.libs << 'spec'
23
- t.warning = true
24
- t.rcov = true
25
- t.rcov_opts = ['-x spec']
26
- end
7
+ RSpec::Core::RakeTask.new do |t|
8
+ t.pattern = "./**/*_spec.rb"
9
+ t.ruby_opts = "-w"
27
10
  end
28
11
 
12
+ task :default => :spec
13
+
14
+ # desc "Run all specs in spec directory with RCov"
15
+ # RSpec::Core::RakeTask.new(:rcov) do |t|
16
+ # t.libs << 'lib'
17
+ # t.libs << 'spec'
18
+ # t.warning = true
19
+ # t.rcov = true
20
+ # t.rcov_opts = ['-x spec']
21
+ # end
22
+
29
23
  desc "Generate RDoc"
30
24
  task :docs do
31
25
  FileUtils.rm_rf("doc")
@@ -164,7 +164,7 @@ module Rack
164
164
  # so that when we are done, the cookies will be unique by name and
165
165
  # we'll have grabbed the most specific to the URI.
166
166
  @cookies.each do |cookie|
167
- cookies[cookie.name] = cookie if cookie.matches?(uri)
167
+ cookies[cookie.name] = cookie if !uri || cookie.matches?(uri)
168
168
  end
169
169
 
170
170
  return cookies
@@ -95,7 +95,8 @@ module Rack
95
95
  end.join
96
96
 
97
97
  else
98
- build_primitive_part(name, value)
98
+ primitive_part = build_primitive_part(name, value)
99
+ Rack::Test.encoding_aware_strings? ? primitive_part.force_encoding('BINARY') : primitive_part
99
100
  end
100
101
 
101
102
  }.join + "--#{MULTIPART_BOUNDARY}--\r"
data/lib/rack/test.rb CHANGED
@@ -9,7 +9,7 @@ require "rack/test/uploaded_file"
9
9
 
10
10
  module Rack
11
11
  module Test
12
- VERSION = "0.5.4"
12
+ VERSION = "0.5.7"
13
13
 
14
14
  DEFAULT_HOST = "example.org"
15
15
  MULTIPART_BOUNDARY = "----------XnJLe9ZIbbGUYtzPQJ16u1"
@@ -161,6 +161,8 @@ module Rack
161
161
  uri.path = "/#{uri.path}" unless uri.path[0] == ?/
162
162
  uri.host ||= @default_host
163
163
 
164
+ env["HTTP_HOST"] ||= [uri.host, uri.port].compact.join(":")
165
+
164
166
  env = default_env.merge(env)
165
167
 
166
168
  env.update("HTTPS" => "on") if URI::HTTPS === uri
@@ -173,7 +175,7 @@ module Rack
173
175
  if env["REQUEST_METHOD"] == "GET"
174
176
  params = env[:params] || {}
175
177
  params = parse_nested_query(params) if params.is_a?(String)
176
- params.update(parse_query(uri.query))
178
+ params.update(parse_nested_query(uri.query))
177
179
  uri.query = build_nested_query(params)
178
180
  elsif !env.has_key?(:input)
179
181
  env["CONTENT_TYPE"] ||= "application/x-www-form-urlencoded"
@@ -273,5 +275,9 @@ module Rack
273
275
 
274
276
  end
275
277
 
278
+ def self.encoding_aware_strings?
279
+ defined?(Encoding) && "".respond_to?(:encode)
280
+ end
281
+
276
282
  end
277
283
  end
data/rack-test.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{rack-test}
5
- s.version = "0.5.4"
5
+ s.version = "0.5.7"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Bryan Helmkamp"]
9
- s.date = %q{2010-05-26}
9
+ s.date = %q{2011-01-01}
10
10
  s.description = %q{Rack::Test is a small, simple testing API for Rack apps. It can be used on its
11
11
  own or as a reusable starting point for Web frameworks and testing libraries
12
12
  to build on. Most of its initial functionality is an extraction of Merb 1.0's
@@ -19,6 +19,8 @@ request helpers feature.}
19
19
  s.files = [
20
20
  ".document",
21
21
  ".gitignore",
22
+ "Gemfile",
23
+ "Gemfile.lock",
22
24
  "History.txt",
23
25
  "MIT-LICENSE.txt",
24
26
  "README.rdoc",
@@ -41,8 +43,9 @@ request helpers feature.}
41
43
  "spec/rack/test/multipart_spec.rb",
42
44
  "spec/rack/test/utils_spec.rb",
43
45
  "spec/rack/test_spec.rb",
44
- "spec/spec.opts",
45
- "spec/spec_helper.rb"
46
+ "spec/spec_helper.rb",
47
+ "spec/support/matchers/body.rb",
48
+ "spec/support/matchers/challenge.rb"
46
49
  ]
47
50
  s.homepage = %q{http://github.com/brynary/rack-test}
48
51
  s.require_paths = ["lib"]
@@ -56,7 +59,9 @@ request helpers feature.}
56
59
  "spec/rack/test/multipart_spec.rb",
57
60
  "spec/rack/test/utils_spec.rb",
58
61
  "spec/rack/test_spec.rb",
59
- "spec/spec_helper.rb"
62
+ "spec/spec_helper.rb",
63
+ "spec/support/matchers/body.rb",
64
+ "spec/support/matchers/challenge.rb"
60
65
  ]
61
66
 
62
67
  if s.respond_to? :specification_version then
@@ -1,3 +1,4 @@
1
+ require "rubygems"
1
2
  require "sinatra/base"
2
3
 
3
4
  module Rack
@@ -1,11 +1,6 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Rack::Test::Session do
4
- def have_body(string)
5
- simple_matcher "have body #{string.inspect}" do |response|
6
- response.body.should == string
7
- end
8
- end
9
4
 
10
5
  context "cookies" do
11
6
  it "keeps a cookie jar" do
@@ -118,6 +113,7 @@ describe Rack::Test::Session do
118
113
 
119
114
  get "https://example.com/cookies/show"
120
115
  last_request.cookies.should == { "secure-cookie" => "set" }
116
+ rack_mock_session.cookie_jar['secure-cookie'].should == 'set'
121
117
  end
122
118
 
123
119
  it "keeps separate cookie jars for different domains" do
@@ -12,14 +12,6 @@ describe Rack::Test::Session do
12
12
  app
13
13
  end
14
14
 
15
- def be_challenge
16
- simple_matcher "a HTTP Digest challenge response" do |response|
17
- response.status == 401 &&
18
- response['WWW-Authenticate'] =~ /^Digest / &&
19
- response.body.empty?
20
- end
21
- end
22
-
23
15
  it 'incorrectly authenticates GETs' do
24
16
  digest_authorize 'foo', 'bar'
25
17
  get '/'
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require "spec_helper"
2
4
 
3
5
  describe Rack::Test::Session do
@@ -51,6 +53,17 @@ describe Rack::Test::Session do
51
53
  last_request.POST["foo"].should == "bar? baz"
52
54
  end
53
55
 
56
+ it "sends params encoded as ISO-8859-1" do
57
+ post "/", "photo" => uploaded_file, "foo" => "bar", "utf8" => "☃"
58
+ last_request.POST["foo"].should == "bar"
59
+
60
+ if Rack::Test.encoding_aware_strings?
61
+ last_request.POST["utf8"].should == "\xE2\x98\x83".force_encoding("BINARY")
62
+ else
63
+ last_request.POST["utf8"].should == "\xE2\x98\x83"
64
+ end
65
+ end
66
+
54
67
  it "sends params with parens in names" do
55
68
  post "/", "photo" => uploaded_file, "foo(1i)" => "bar"
56
69
  last_request.POST["foo(1i)"].should == "bar"
@@ -103,7 +103,7 @@ describe Rack::Test::Utils do
103
103
  params["people"][0]["files"][:tempfile].read.should == "bar\n"
104
104
  end
105
105
 
106
- it "should return nil if no UploadedFiles were used" do
106
+ it "returns nil if no UploadedFiles were used" do
107
107
  data = build_multipart("people" => [{"submit-name" => "Larry", "files" => "contents"}])
108
108
  data.should be_nil
109
109
  end
@@ -29,6 +29,11 @@ describe Rack::Test::Session do
29
29
  last_request.env["X-Foo"].should == "bar"
30
30
  end
31
31
 
32
+ it "allows HTTP_HOST to be set" do
33
+ request "/", "HTTP_HOST" => "www.example.ua"
34
+ last_request.env['HTTP_HOST'].should == "www.example.ua"
35
+ end
36
+
32
37
  it "defaults to GET" do
33
38
  request "/"
34
39
  last_request.env["REQUEST_METHOD"].should == "GET"
@@ -91,6 +96,11 @@ describe Rack::Test::Session do
91
96
  last_request.GET.should == { "baz" => "2", "foo" => { "bar" => "1" }}
92
97
  end
93
98
 
99
+ it "parses query strings with repeated variable names correctly" do
100
+ request "/foo?bar=2&bar=3"
101
+ last_request.GET.should == { "bar" => "3" }
102
+ end
103
+
94
104
  it "accepts raw input in params for GET requests" do
95
105
  request "/foo?baz=2", :params => "foo[bar]=1"
96
106
  last_request.GET.should == { "baz" => "2", "foo" => { "bar" => "1" }}
@@ -146,12 +156,12 @@ describe Rack::Test::Session do
146
156
  end
147
157
 
148
158
  context "when input is given" do
149
- it "should send the input" do
159
+ it "sends the input" do
150
160
  request "/", :method => "POST", :input => "foo"
151
161
  last_request.env["rack.input"].read.should == "foo"
152
162
  end
153
163
 
154
- it "should not send a multipart request" do
164
+ it "does not send a multipart request" do
155
165
  request "/", :method => "POST", :input => "foo"
156
166
  last_request.env["CONTENT_TYPE"].should_not == "application/x-www-form-urlencoded"
157
167
  end
data/spec/spec_helper.rb CHANGED
@@ -1,12 +1,16 @@
1
1
  require "rubygems"
2
- require "spec"
2
+ require "bundler/setup"
3
3
 
4
- gem "rack", "~> 1.0.0"
4
+ require "rack"
5
+ require "rspec"
6
+
7
+ Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f}
5
8
 
6
9
  require "rack/test"
7
10
  require File.dirname(__FILE__) + "/fixtures/fake_app"
8
11
 
9
- Spec::Runner.configure do |config|
12
+ Rspec.configure do |config|
13
+ config.mock_with :rspec
10
14
  config.include Rack::Test::Methods
11
15
 
12
16
  def app
@@ -18,7 +22,7 @@ Spec::Runner.configure do |config|
18
22
 
19
23
  end
20
24
 
21
- describe "any #verb methods", :shared => true do
25
+ shared_examples_for "any #verb methods" do
22
26
  it "requests the URL using VERB" do
23
27
  send(verb, "/")
24
28
 
@@ -42,6 +46,16 @@ describe "any #verb methods", :shared => true do
42
46
  yielded.should be_true
43
47
  end
44
48
 
49
+ it "sets the HTTP_HOST header with port" do
50
+ send(verb, "http://example.org:8080/uri")
51
+ last_request.env["HTTP_HOST"].should == "example.org:8080"
52
+ end
53
+
54
+ it "sets the HTTP_HOST header without port" do
55
+ send(verb, "/uri")
56
+ last_request.env["HTTP_HOST"].should == "example.org"
57
+ end
58
+
45
59
  context "for a XHR" do
46
60
  it "sends XMLHttpRequest for the X-Requested-With header" do
47
61
  send(verb, "/", {}, { :xhr => true })
@@ -0,0 +1,9 @@
1
+ RSpec::Matchers.define :have_body do |expected|
2
+ match do |response|
3
+ response.body.should == expected
4
+ end
5
+
6
+ description do
7
+ "have body #{expected.inspect}"
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ RSpec::Matchers.define :be_challenge do
2
+ match do |actual_response|
3
+ actual_response.status == 401 &&
4
+ actual_response['WWW-Authenticate'] =~ /^Digest / &&
5
+ actual_response.body.empty?
6
+ end
7
+
8
+ description do
9
+ "a HTTP Digest challenge response"
10
+ end
11
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-test
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
4
+ hash: 5
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 5
9
- - 4
10
- version: 0.5.4
9
+ - 7
10
+ version: 0.5.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - Bryan Helmkamp
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-05-26 00:00:00 -04:00
18
+ date: 2011-01-01 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -49,6 +49,8 @@ extra_rdoc_files:
49
49
  files:
50
50
  - .document
51
51
  - .gitignore
52
+ - Gemfile
53
+ - Gemfile.lock
52
54
  - History.txt
53
55
  - MIT-LICENSE.txt
54
56
  - README.rdoc
@@ -71,8 +73,9 @@ files:
71
73
  - spec/rack/test/multipart_spec.rb
72
74
  - spec/rack/test/utils_spec.rb
73
75
  - spec/rack/test_spec.rb
74
- - spec/spec.opts
75
76
  - spec/spec_helper.rb
77
+ - spec/support/matchers/body.rb
78
+ - spec/support/matchers/challenge.rb
76
79
  has_rdoc: true
77
80
  homepage: http://github.com/brynary/rack-test
78
81
  licenses: []
@@ -115,3 +118,5 @@ test_files:
115
118
  - spec/rack/test/utils_spec.rb
116
119
  - spec/rack/test_spec.rb
117
120
  - spec/spec_helper.rb
121
+ - spec/support/matchers/body.rb
122
+ - spec/support/matchers/challenge.rb
data/spec/spec.opts DELETED
@@ -1,2 +0,0 @@
1
- --color
2
- -fs