rack-test 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
1
  pkg
2
2
  doc
3
3
  coverage
4
+ VERSION
@@ -1,3 +1,11 @@
1
+ == 0.5.0 / 2009-09-19
2
+
3
+ * Bug fixes
4
+
5
+ * Set HTTP_X_REQUESTED_WITH in the Rack env when a request is made with :xhr => true (Ben Sales)
6
+ * Set headers in the Rack env in HTTP_USER_AGENT form
7
+ * Rack::Test now generates no Ruby warnings
8
+
1
9
  == 0.4.2 / 2009-09-01
2
10
 
3
11
  * Minor enhancements
@@ -1,7 +1,7 @@
1
1
  = Rack::Test
2
2
 
3
- - http://gitrdoc.com/brynary/rack-test
4
- - http://github.com/brynary/rack-test
3
+ - Code: http://github.com/brynary/rack-test
4
+ - Build: http://runcoderun.com/brynary/rack-test
5
5
 
6
6
  == Description
7
7
 
@@ -20,23 +20,23 @@ request helpers feature.
20
20
  == Example
21
21
 
22
22
  require "rack/test"
23
-
23
+
24
24
  class HomepageTest < Test::Unit::TestCase
25
25
  include Rack::Test::Methods
26
-
26
+
27
27
  def app
28
28
  MyApp.new
29
29
  end
30
-
30
+
31
31
  def test_redirect_logged_in_users_to_dashboard
32
32
  authorize "bryan", "secret"
33
33
  get "/"
34
34
  follow_redirect!
35
-
35
+
36
36
  assert_equal "http://example.org/redirected", last_request.url
37
37
  assert last_response.ok?
38
38
  end
39
-
39
+
40
40
  end
41
41
 
42
42
  == Install
data/Rakefile CHANGED
@@ -1,44 +1,87 @@
1
1
  require "rubygems"
2
- require "rake/rdoctask"
3
- require "spec/rake/spectask"
4
2
 
5
3
  begin
6
4
  require "jeweler"
7
-
5
+ rescue LoadError
6
+ desc "Install gem using sudo"
7
+ task(:install) do
8
+ $stderr.puts "Jeweler not available. `gem install jeweler` to install this gem"
9
+ end
10
+ else
8
11
  Jeweler::Tasks.new do |s|
9
12
  s.name = "rack-test"
10
13
  s.author = "Bryan Helmkamp"
11
14
  s.email = "bryan" + "@" + "brynary.com"
12
15
  s.homepage = "http://github.com/brynary/rack-test"
13
16
  s.summary = "Simple testing API built on Rack"
14
- # s.description = "TODO"
17
+ s.description = <<-EOS.strip
18
+ Rack::Test is a small, simple testing API for Rack apps. It can be used on its
19
+ own or as a reusable starting point for Web frameworks and testing libraries
20
+ to build on. Most of its initial functionality is an extraction of Merb 1.0's
21
+ request helpers feature.
22
+ EOS
15
23
  s.rubyforge_project = "rack-test"
16
24
  s.extra_rdoc_files = %w[README.rdoc MIT-LICENSE.txt]
17
25
  end
18
26
 
19
27
  Jeweler::RubyforgeTasks.new
20
- rescue LoadError
21
- puts "Jeweler not available. Install it with: gem install jeweler"
22
- end
23
28
 
24
- Spec::Rake::SpecTask.new do |t|
25
- t.spec_opts = ['--options', "\"#{File.dirname(__FILE__)}/spec/spec.opts\""]
26
- t.libs << 'lib'
27
- t.libs << 'spec'
29
+ task :spec => :check_dependencies
30
+
31
+ namespace :version do
32
+ task :verify do
33
+ $LOAD_PATH.unshift "lib"
34
+ require "rack/test"
35
+
36
+ jeweler_version = Gem::Version.new(File.read("VERSION").strip)
37
+ lib_version = Gem::Version.new(Rack::Test::VERSION)
38
+
39
+ if jeweler_version != lib_version
40
+ raise <<-EOS
41
+
42
+ Error: Version number mismatch!
43
+
44
+ VERSION: #{jeweler_version}
45
+ Rack::Test::VERSION: #{lib_version}
46
+
47
+ EOS
48
+ end
49
+ end
50
+ end
51
+
52
+ task :gemspec => "version:verify"
28
53
  end
29
54
 
30
- desc "Run all specs in spec directory with RCov"
31
- Spec::Rake::SpecTask.new(:rcov) do |t|
32
- t.spec_opts = ['--options', "\"#{File.dirname(__FILE__)}/spec/spec.opts\""]
33
- t.rcov = true
34
- t.rcov_opts = lambda do
35
- IO.readlines(File.dirname(__FILE__) + "/spec/rcov.opts").map {|l| l.chomp.split " "}.flatten
55
+ begin
56
+ require "spec/rake/spectask"
57
+ rescue LoadError
58
+ desc "Run specs"
59
+ task(:spec) { $stderr.puts '`gem install rspec` to run specs' }
60
+ else
61
+ Spec::Rake::SpecTask.new do |t|
62
+ t.spec_opts = ['--options', "\"#{File.dirname(__FILE__)}/spec/spec.opts\""]
63
+ t.libs << 'lib'
64
+ t.libs << 'spec'
65
+ t.warning = true
66
+ end
67
+
68
+ task :default => :spec
69
+
70
+ desc "Run all specs in spec directory with RCov"
71
+ Spec::Rake::SpecTask.new(:rcov) do |t|
72
+ t.spec_opts = ['--options', "\"#{File.dirname(__FILE__)}/spec/spec.opts\""]
73
+ t.libs << 'lib'
74
+ t.libs << 'spec'
75
+ t.warning = true
76
+ t.rcov = true
77
+ t.rcov_opts = ['-x spec']
36
78
  end
37
79
  end
38
80
 
39
81
  desc "Generate RDoc"
40
82
  task :docs do
41
83
  FileUtils.rm_rf("doc")
84
+ require "rack/test"
42
85
  system "hanna --title 'Rack::Test #{Rack::Test::VERSION} API Documentation'"
43
86
  end
44
87
 
@@ -47,7 +90,3 @@ task :whitespace do
47
90
  sh %{find . -name '*.rb' -exec sed -i '' 's/ *$//g' {} \\;}
48
91
  end
49
92
 
50
- task :spec => :check_dependencies if defined?(Jeweler)
51
-
52
- desc "Run the specs"
53
- task :default => :spec
@@ -1,14 +1,15 @@
1
1
  module Rack
2
2
 
3
- class MockSession
3
+ class MockSession # :nodoc:
4
4
  attr_writer :cookie_jar
5
- attr_reader :last_response
6
5
  attr_reader :default_host
7
6
 
8
7
  def initialize(app, default_host = Rack::Test::DEFAULT_HOST)
9
8
  @app = app
10
9
  @after_request = []
11
10
  @default_host = default_host
11
+ @last_request = nil
12
+ @last_response = nil
12
13
  end
13
14
 
14
15
  def after_request(&block)
@@ -9,7 +9,7 @@ require "rack/test/uploaded_file"
9
9
 
10
10
  module Rack
11
11
  module Test
12
- VERSION = "0.4.2"
12
+ VERSION = "0.5.0"
13
13
 
14
14
  DEFAULT_HOST = "example.org"
15
15
  MULTIPART_BOUNDARY = "----------XnJLe9ZIbbGUYtzPQJ16u1"
@@ -17,13 +17,22 @@ module Rack
17
17
  # The common base class for exceptions raised by Rack::Test
18
18
  class Error < StandardError; end
19
19
 
20
+ # This class represents a series of requests issued to a Rack app, sharing
21
+ # a single cookie jar
22
+ #
23
+ # Rack::Test::Session's methods are most often called through Rack::Test::Methods,
24
+ # which will automatically build a session when it's first used.
20
25
  class Session
21
26
  extend Forwardable
22
27
  include Rack::Test::Utils
23
28
 
24
29
  def_delegators :@rack_mock_session, :clear_cookies, :set_cookie, :last_response, :last_request
25
30
 
26
- # Initialize a new session for the given Rack app
31
+ # Creates a Rack::Test::Session for a given Rack app or Rack::MockSession.
32
+ #
33
+ # Note: Generally, you won't need to initialize a Rack::Test::Session directly.
34
+ # Instead, you should include Rack::Test::Methods into your testing context.
35
+ # (See README.rdoc for an example)
27
36
  def initialize(mock_session)
28
37
  @headers = {}
29
38
 
@@ -99,6 +108,9 @@ module Rack
99
108
  # Set a header to be included on all subsequent requests through the
100
109
  # session. Use a value of nil to remove a previously configured header.
101
110
  #
111
+ # In accordance with the Rack spec, headers will be included in the Rack
112
+ # environment hash in HTTP_USER_AGENT form.
113
+ #
102
114
  # Example:
103
115
  # header "User-Agent", "Firefox"
104
116
  def header(name, value)
@@ -116,11 +128,16 @@ module Rack
116
128
  # basic_authorize "bryan", "secret"
117
129
  def basic_authorize(username, password)
118
130
  encoded_login = ["#{username}:#{password}"].pack("m*")
119
- header('HTTP_AUTHORIZATION', "Basic #{encoded_login}")
131
+ header('Authorization', "Basic #{encoded_login}")
120
132
  end
121
133
 
122
134
  alias_method :authorize, :basic_authorize
123
135
 
136
+ # Set the username and password for HTTP Digest authorization, to be
137
+ # included in subsequent requests in the HTTP_AUTHORIZATION header.
138
+ #
139
+ # Example:
140
+ # digest_authorize "bryan", "secret"
124
141
  def digest_authorize(username, password)
125
142
  @digest_username = username
126
143
  @digest_password = password
@@ -146,8 +163,8 @@ module Rack
146
163
 
147
164
  env = default_env.merge(env)
148
165
 
149
- env.update("HTTPS" => "on") if URI::HTTPS === uri
150
- env["X-Requested-With"] = "XMLHttpRequest" if env[:xhr]
166
+ env.update("HTTPS" => "on") if URI::HTTPS === uri
167
+ env["HTTP_X_REQUESTED_WITH"] = "XMLHttpRequest" if env[:xhr]
151
168
 
152
169
  # TODO: Remove this after Rack 1.1 has been released.
153
170
  # Stringifying and upcasing methods has be commit upstream
@@ -231,7 +248,18 @@ module Rack
231
248
  end
232
249
 
233
250
  def default_env
234
- { "rack.test" => true, "REMOTE_ADDR" => "127.0.0.1" }.merge(@headers)
251
+ { "rack.test" => true, "REMOTE_ADDR" => "127.0.0.1" }.merge(headers_for_env)
252
+ end
253
+
254
+ def headers_for_env
255
+ converted_headers = {}
256
+
257
+ @headers.each do |name, value|
258
+ env_key = "HTTP_" + name.upcase.gsub("-", "_")
259
+ converted_headers[env_key] = value
260
+ end
261
+
262
+ converted_headers
235
263
  end
236
264
 
237
265
  def params_to_string(params)
@@ -1,8 +1,9 @@
1
1
  require "uri"
2
+
2
3
  module Rack
3
4
  module Test
4
5
 
5
- class Cookie
6
+ class Cookie # :nodoc:
6
7
  include Rack::Utils
7
8
 
8
9
  # :api: private
@@ -93,7 +94,7 @@ module Rack
93
94
 
94
95
  end
95
96
 
96
- class CookieJar
97
+ class CookieJar # :nodoc:
97
98
 
98
99
  # :api: private
99
100
  def initialize(cookies = [], default_host = DEFAULT_HOST)
@@ -2,67 +2,74 @@ require "forwardable"
2
2
 
3
3
  module Rack
4
4
  module Test
5
+
6
+ # This module serves as the primary integration point for using Rack::Test
7
+ # in a testing environment. It depends on an app method being defined in the
8
+ # same context, and provides the Rack::Test API methods (see Rack::Test::Session
9
+ # for their documentation).
10
+ #
11
+ # Example:
12
+ #
13
+ # class HomepageTest < Test::Unit::TestCase
14
+ # include Rack::Test::Methods
15
+ #
16
+ # def app
17
+ # MyApp.new
18
+ # end
19
+ # end
5
20
  module Methods
6
21
  extend Forwardable
7
22
 
8
- def rack_mock_session(name = :default)
23
+ def rack_mock_session(name = :default) # :nodoc:
9
24
  return build_rack_mock_session unless name
10
25
 
11
26
  @_rack_mock_sessions ||= {}
12
27
  @_rack_mock_sessions[name] ||= build_rack_mock_session
13
28
  end
14
29
 
15
- def build_rack_mock_session
30
+ def build_rack_mock_session # :nodoc:
16
31
  Rack::MockSession.new(app)
17
32
  end
18
33
 
19
- def rack_test_session(name = :default)
34
+ def rack_test_session(name = :default) # :nodoc:
20
35
  return build_rack_test_session(name) unless name
21
36
 
22
37
  @_rack_test_sessions ||= {}
23
38
  @_rack_test_sessions[name] ||= build_rack_test_session(name)
24
39
  end
25
40
 
26
- def build_rack_test_session(name)
41
+ def build_rack_test_session(name) # :nodoc:
27
42
  Rack::Test::Session.new(rack_mock_session(name))
28
43
  end
29
44
 
30
- def current_session
45
+ def current_session # :nodoc:
31
46
  rack_test_session(_current_session_names.last)
32
47
  end
33
48
 
34
- def with_session(name)
49
+ def with_session(name) # :nodoc:
35
50
  _current_session_names.push(name)
36
51
  yield rack_test_session(name)
37
52
  _current_session_names.pop
38
53
  end
39
54
 
40
- def _current_session_names
55
+ def _current_session_names # :nodoc:
41
56
  @_current_session_names ||= [:default]
42
57
  end
43
58
 
44
59
  METHODS = [
45
60
  :request,
46
-
47
- # HTTP verbs
48
61
  :get,
49
62
  :post,
50
63
  :put,
51
64
  :delete,
52
65
  :head,
53
-
54
- # Redirects
55
66
  :follow_redirect!,
56
-
57
- # Header-related features
58
67
  :header,
59
68
  :set_cookie,
60
69
  :clear_cookies,
61
70
  :authorize,
62
71
  :basic_authorize,
63
72
  :digest_authorize,
64
-
65
- # Expose the last request and response
66
73
  :last_response,
67
74
  :last_request
68
75
  ]
@@ -1,7 +1,8 @@
1
1
  module Rack
2
2
  module Test
3
3
 
4
- class MockDigestRequest
4
+ class MockDigestRequest # :nodoc:
5
+
5
6
  def initialize(params)
6
7
  @params = params
7
8
  end
@@ -21,6 +22,7 @@ module Rack
21
22
  def response(password)
22
23
  Rack::Auth::Digest::MD5.new(nil).send :digest, self, password
23
24
  end
25
+
24
26
  end
25
27
 
26
28
  end
@@ -3,7 +3,13 @@ require "tempfile"
3
3
  module Rack
4
4
  module Test
5
5
 
6
+ # Wraps a Tempfile with a content type. Including one or more UploadedFile's
7
+ # in the params causes Rack::Test to build and issue a multipart request.
8
+ #
9
+ # Example:
10
+ # post "/photos", "file" => Rack::Test::UploadedFile.new("me.jpg", "image/jpeg")
6
11
  class UploadedFile
12
+
7
13
  # The filename, *not* including the path, of the "uploaded" file
8
14
  attr_reader :original_filename
9
15
 
@@ -12,11 +18,14 @@ module Rack
12
18
 
13
19
  def initialize(path, content_type = "text/plain", binary = false)
14
20
  raise "#{path} file does not exist" unless ::File.exist?(path)
21
+
15
22
  @content_type = content_type
16
23
  @original_filename = ::File.basename(path)
24
+
17
25
  @tempfile = Tempfile.new(@original_filename)
18
26
  @tempfile.set_encoding(Encoding::BINARY) if @tempfile.respond_to?(:set_encoding)
19
27
  @tempfile.binmode if binary
28
+
20
29
  FileUtils.copy_file(path, @tempfile.path)
21
30
  end
22
31
 
@@ -1,7 +1,7 @@
1
1
  module Rack
2
2
  module Test
3
3
 
4
- module Utils
4
+ module Utils # :nodoc:
5
5
  include Rack::Utils
6
6
 
7
7
  def build_nested_query(value, prefix = nil)
@@ -5,11 +5,15 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rack-test}
8
- s.version = "0.4.2"
8
+ s.version = "0.5.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Bryan Helmkamp"]
12
- s.date = %q{2009-09-01}
12
+ s.date = %q{2009-09-19}
13
+ s.description = %q{Rack::Test is a small, simple testing API for Rack apps. It can be used on its
14
+ own or as a reusable starting point for Web frameworks and testing libraries
15
+ to build on. Most of its initial functionality is an extraction of Merb 1.0's
16
+ request helpers feature.}
13
17
  s.email = %q{bryan@brynary.com}
14
18
  s.extra_rdoc_files = [
15
19
  "MIT-LICENSE.txt",
@@ -38,7 +42,6 @@ Gem::Specification.new do |s|
38
42
  "spec/rack/test/multipart_spec.rb",
39
43
  "spec/rack/test/utils_spec.rb",
40
44
  "spec/rack/test_spec.rb",
41
- "spec/rcov.opts",
42
45
  "spec/spec.opts",
43
46
  "spec/spec_helper.rb"
44
47
  ]
@@ -10,7 +10,7 @@ describe Rack::Test::Session do
10
10
  context "cookies" do
11
11
  it "keeps a cookie jar" do
12
12
  get "/cookies/show"
13
- last_request.cookies.should == {}
13
+ check last_request.cookies.should == {}
14
14
 
15
15
  get "/cookies/set", "value" => "1"
16
16
  get "/cookies/show"
@@ -51,11 +51,13 @@ describe Rack::Test::Session do
51
51
  last_request.cookies.should == { }
52
52
  end
53
53
 
54
- xit "respects cookie domains when no domain is explicitly set" do
55
- request("http://example.org/cookies/count").should have_body("1")
56
- request("http://www.example.org/cookies/count").should have_body("1")
57
- request("http://example.org/cookies/count").should have_body("2")
58
- request("http://www.example.org/cookies/count").should have_body("2")
54
+ it "respects cookie domains when no domain is explicitly set" do
55
+ pending "FIXME: www.example.org should not get the first cookie" do
56
+ request("http://example.org/cookies/count").should have_body("1")
57
+ request("http://www.example.org/cookies/count").should have_body("1")
58
+ request("http://example.org/cookies/count").should have_body("2")
59
+ request("http://www.example.org/cookies/count").should have_body("2")
60
+ end
59
61
  end
60
62
 
61
63
  it "treats domains case insensitively" do
@@ -75,7 +77,7 @@ describe Rack::Test::Session do
75
77
  get "http://sub.example.com/cookies/set", "value" => "sub"
76
78
 
77
79
  get "http://sub.example.com/cookies/show"
78
- last_request.cookies.should == { "value" => "sub" }
80
+ check last_request.cookies.should == { "value" => "sub" }
79
81
 
80
82
  get "http://example.com/cookies/show"
81
83
  last_request.cookies.should == { "value" => "domain" }
@@ -91,7 +93,7 @@ describe Rack::Test::Session do
91
93
  it "defaults the domain to the request domain" do
92
94
  get "http://example.com/cookies/set-simple", "value" => "cookie"
93
95
  get "http://example.com/cookies/show"
94
- last_request.cookies.should == { "simple" => "cookie" }
96
+ check last_request.cookies.should == { "simple" => "cookie" }
95
97
 
96
98
  get "http://other.example/cookies/show"
97
99
  last_request.cookies.should == {}
@@ -106,7 +108,7 @@ describe Rack::Test::Session do
106
108
  it "supports secure cookies" do
107
109
  get "https://example.com/cookies/set-secure", "value" => "set"
108
110
  get "http://example.com/cookies/show"
109
- last_request.cookies.should == {}
111
+ check last_request.cookies.should == {}
110
112
 
111
113
  get "https://example.com/cookies/show"
112
114
  last_request.cookies.should == { "secure-cookie" => "set" }
@@ -115,11 +117,11 @@ describe Rack::Test::Session do
115
117
  it "keeps separate cookie jars for different domains" do
116
118
  get "http://example.com/cookies/set", "value" => "example"
117
119
  get "http://example.com/cookies/show"
118
- last_request.cookies.should == { "value" => "example" }
120
+ check last_request.cookies.should == { "value" => "example" }
119
121
 
120
122
  get "http://other.example/cookies/set", "value" => "other"
121
123
  get "http://other.example/cookies/show"
122
- last_request.cookies.should == { "value" => "other" }
124
+ check last_request.cookies.should == { "value" => "other" }
123
125
 
124
126
  get "http://example.com/cookies/show"
125
127
  last_request.cookies.should == { "value" => "example" }
@@ -166,7 +168,7 @@ describe Rack::Test::Session do
166
168
  it "uses :default as the default session name" do
167
169
  get "/cookies/set", "value" => "1"
168
170
  get "/cookies/show"
169
- last_request.cookies.should == { "value" => "1" }
171
+ check last_request.cookies.should == { "value" => "1" }
170
172
 
171
173
  with_session(:default) do
172
174
  get "/cookies/show"
@@ -31,9 +31,11 @@ describe Rack::Test::Session do
31
31
  last_request.POST["foo"]["bar"]["baz"].should == "bop"
32
32
  end
33
33
 
34
- xit "sends params with arrays" do
35
- post "/", "photo" => uploaded_file, "foo" => ["1", "2"]
36
- last_request.POST["foo[]"].should == ["1", "2"]
34
+ it "sends params with arrays" do
35
+ pending "FIXME: should work the same with and without multipart" do
36
+ post "/", "photo" => uploaded_file, "foo" => ["1", "2"]
37
+ last_request.POST["foo"].should == ["1", "2"]
38
+ end
37
39
  end
38
40
 
39
41
  it "sends params with encoding sensitive values" do
@@ -58,8 +58,8 @@ describe Rack::Test::Utils do
58
58
  }
59
59
  env = Rack::MockRequest.env_for("/", options)
60
60
  params = Rack::Utils::Multipart.parse_multipart(env)
61
- params["submit-name"].should == "Larry"
62
- params["files"][:filename].should == "foo.txt"
61
+ check params["submit-name"].should == "Larry"
62
+ check params["files"][:filename].should == "foo.txt"
63
63
  params["files"][:tempfile].read.should == "bar\n"
64
64
  end
65
65
 
@@ -74,8 +74,8 @@ describe Rack::Test::Utils do
74
74
  }
75
75
  env = Rack::MockRequest.env_for("/", options)
76
76
  params = Rack::Utils::Multipart.parse_multipart(env)
77
- params["people"][0]["submit-name"].should == "Larry"
78
- params["people"][0]["files"][:filename].should == "foo.txt"
77
+ check params["people"][0]["submit-name"].should == "Larry"
78
+ check params["people"][0]["files"][:filename].should == "foo.txt"
79
79
  params["people"][0]["files"][:tempfile].read.should == "bar\n"
80
80
  end
81
81
 
@@ -88,19 +88,19 @@ describe Rack::Test::Session do
88
88
 
89
89
  it "accepts params and builds query strings for GET requests" do
90
90
  request "/foo?baz=2", :params => {:foo => {:bar => "1"}}
91
- last_request.env["QUERY_STRING"].should == "baz=2&foo[bar]=1"
91
+ last_request.GET.should == { "baz" => "2", "foo" => { "bar" => "1" }}
92
92
  end
93
93
 
94
94
  it "accepts raw input in params for GET requests" do
95
95
  request "/foo?baz=2", :params => "foo[bar]=1"
96
- last_request.env["QUERY_STRING"].should == "baz=2&foo[bar]=1"
96
+ last_request.GET.should == { "baz" => "2", "foo" => { "bar" => "1" }}
97
97
  end
98
98
 
99
99
  it "accepts params and builds url encoded params for POST requests" do
100
100
  request "/foo", :method => :post, :params => {:foo => {:bar => "1"}}
101
101
  last_request.env["rack.input"].read.should == "foo[bar]=1"
102
102
  end
103
-
103
+
104
104
  it "accepts raw input in params for POST requests" do
105
105
  request "/foo", :method => :post, :params => "foo[bar]=1"
106
106
  last_request.env["rack.input"].read.should == "foo[bar]=1"
@@ -159,7 +159,8 @@ describe Rack::Test::Session do
159
159
  context "for a XHR" do
160
160
  it "sends XMLHttpRequest for the X-Requested-With header" do
161
161
  request "/", :xhr => true
162
- last_request.env["X-Requested-With"].should == "XMLHttpRequest"
162
+ last_request.env["HTTP_X_REQUESTED_WITH"].should == "XMLHttpRequest"
163
+ last_request.should be_xhr
163
164
  end
164
165
  end
165
166
  end
@@ -169,7 +170,7 @@ describe Rack::Test::Session do
169
170
  header "User-Agent", "Firefox"
170
171
  request "/"
171
172
 
172
- last_request.env["User-Agent"].should == "Firefox"
173
+ last_request.env["HTTP_USER_AGENT"].should == "Firefox"
173
174
  end
174
175
 
175
176
  it "persists across multiple requests" do
@@ -177,7 +178,7 @@ describe Rack::Test::Session do
177
178
  request "/"
178
179
  request "/"
179
180
 
180
- last_request.env["User-Agent"].should == "Firefox"
181
+ last_request.env["HTTP_USER_AGENT"].should == "Firefox"
181
182
  end
182
183
 
183
184
  it "overwrites previously set headers" do
@@ -185,7 +186,7 @@ describe Rack::Test::Session do
185
186
  header "User-Agent", "Safari"
186
187
  request "/"
187
188
 
188
- last_request.env["User-Agent"].should == "Safari"
189
+ last_request.env["HTTP_USER_AGENT"].should == "Safari"
189
190
  end
190
191
 
191
192
  it "can be used to clear a header" do
@@ -193,14 +194,14 @@ describe Rack::Test::Session do
193
194
  header "User-Agent", nil
194
195
  request "/"
195
196
 
196
- last_request.env.should_not have_key("User-Agent")
197
+ last_request.env.should_not have_key("HTTP_USER_AGENT")
197
198
  end
198
199
 
199
200
  it "is overridden by headers sent during the request" do
200
201
  header "User-Agent", "Firefox"
201
- request "/", "User-Agent" => "Safari"
202
+ request "/", "HTTP_USER_AGENT" => "Safari"
202
203
 
203
- last_request.env["User-Agent"].should == "Safari"
204
+ last_request.env["HTTP_USER_AGENT"].should == "Safari"
204
205
  end
205
206
  end
206
207
 
@@ -1 +1,2 @@
1
1
  --color
2
+ -fs
@@ -13,19 +13,22 @@ Spec::Runner.configure do |config|
13
13
  Rack::Lint.new(Rack::Test::FakeApp.new)
14
14
  end
15
15
 
16
+ def check(*args)
17
+ end
18
+
16
19
  end
17
20
 
18
21
  describe "any #verb methods", :shared => true do
19
22
  it "requests the URL using VERB" do
20
23
  send(verb, "/")
21
24
 
22
- last_request.env["REQUEST_METHOD"].should == verb.upcase
25
+ check last_request.env["REQUEST_METHOD"].should == verb.upcase
23
26
  last_response.should be_ok
24
27
  end
25
28
 
26
29
  it "uses the provided env" do
27
- send(verb, "/", {}, { "User-Agent" => "Rack::Test" })
28
- last_request.env["User-Agent"].should == "Rack::Test"
30
+ send(verb, "/", {}, { "HTTP_USER_AGENT" => "Rack::Test" })
31
+ last_request.env["HTTP_USER_AGENT"].should == "Rack::Test"
29
32
  end
30
33
 
31
34
  it "yields the response to a given block" do
@@ -42,7 +45,8 @@ describe "any #verb methods", :shared => true do
42
45
  context "for a XHR" do
43
46
  it "sends XMLHttpRequest for the X-Requested-With header" do
44
47
  send(verb, "/", {}, { :xhr => true })
45
- last_request.env["X-Requested-With"].should == "XMLHttpRequest"
48
+ last_request.env["HTTP_X_REQUESTED_WITH"].should == "XMLHttpRequest"
49
+ last_request.should be_xhr
46
50
  end
47
51
  end
48
52
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-test
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Helmkamp
@@ -9,11 +9,15 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-01 00:00:00 -04:00
12
+ date: 2009-09-19 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
16
- description:
16
+ description: |-
17
+ Rack::Test is a small, simple testing API for Rack apps. It can be used on its
18
+ own or as a reusable starting point for Web frameworks and testing libraries
19
+ to build on. Most of its initial functionality is an extraction of Merb 1.0's
20
+ request helpers feature.
17
21
  email: bryan@brynary.com
18
22
  executables: []
19
23
 
@@ -45,7 +49,6 @@ files:
45
49
  - spec/rack/test/multipart_spec.rb
46
50
  - spec/rack/test/utils_spec.rb
47
51
  - spec/rack/test_spec.rb
48
- - spec/rcov.opts
49
52
  - spec/spec.opts
50
53
  - spec/spec_helper.rb
51
54
  has_rdoc: true
@@ -1 +0,0 @@
1
- -x gems,spec