rack-test 0.5.0 → 0.5.1

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.
@@ -1,3 +1,10 @@
1
+ == 0.5.1 / 2009-10-27
2
+
3
+ * Bug fixes
4
+
5
+ * Escape cookie values (John Pignata)
6
+ * Close the response body after each request, as per the Rack spec (Elomar França)
7
+
1
8
  == 0.5.0 / 2009-09-19
2
9
 
3
10
  * Bug fixes
data/Rakefile CHANGED
@@ -1,57 +1,5 @@
1
1
  require "rubygems"
2
2
 
3
- begin
4
- require "jeweler"
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
11
- Jeweler::Tasks.new do |s|
12
- s.name = "rack-test"
13
- s.author = "Bryan Helmkamp"
14
- s.email = "bryan" + "@" + "brynary.com"
15
- s.homepage = "http://github.com/brynary/rack-test"
16
- s.summary = "Simple testing API built on Rack"
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
23
- s.rubyforge_project = "rack-test"
24
- s.extra_rdoc_files = %w[README.rdoc MIT-LICENSE.txt]
25
- end
26
-
27
- Jeweler::RubyforgeTasks.new
28
-
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"
53
- end
54
-
55
3
  begin
56
4
  require "spec/rake/spectask"
57
5
  rescue LoadError
@@ -89,4 +37,3 @@ desc 'Removes trailing whitespace'
89
37
  task :whitespace do
90
38
  sh %{find . -name '*.rb' -exec sed -i '' 's/ *$//g' {} \\;}
91
39
  end
92
-
@@ -0,0 +1,114 @@
1
+ module GemHelpers
2
+
3
+ def generate_gemspec
4
+ $LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), "lib")))
5
+ require "rack/test"
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "rack-test"
9
+ s.version = Rack::Test::VERSION
10
+ s.author = "Bryan Helmkamp"
11
+ s.email = "bryan@brynary.com"
12
+ s.homepage = "http://github.com/brynary/rack-test"
13
+ s.summary = "Simple testing API built on Rack"
14
+ s.description = <<-EOS.strip
15
+ Rack::Test is a small, simple testing API for Rack apps. It can be used on its
16
+ own or as a reusable starting point for Web frameworks and testing libraries
17
+ to build on. Most of its initial functionality is an extraction of Merb 1.0's
18
+ request helpers feature.
19
+ EOS
20
+ s.rubyforge_project = "rack-test"
21
+
22
+ require "git"
23
+ repo = Git.open(".")
24
+
25
+ s.files = normalize_files(repo.ls_files.keys - repo.lib.ignored_files)
26
+ s.test_files = normalize_files(Dir['spec/**/*.rb'] - repo.lib.ignored_files)
27
+
28
+ s.has_rdoc = true
29
+ s.extra_rdoc_files = %w[README.rdoc MIT-LICENSE.txt]
30
+
31
+ s.add_dependency "rack", ">= 1.0"
32
+ end
33
+ end
34
+
35
+ def normalize_files(array)
36
+ # only keep files, no directories, and sort
37
+ array.select do |path|
38
+ File.file?(path)
39
+ end.sort
40
+ end
41
+
42
+ # Adds extra space when outputting an array. This helps create better version
43
+ # control diffs, because otherwise it is all on the same line.
44
+ def prettyify_array(gemspec_ruby, array_name)
45
+ gemspec_ruby.gsub(/s\.#{array_name.to_s} = \[.+?\]/) do |match|
46
+ leadin, files = match[0..-2].split("[")
47
+ leadin + "[\n #{files.split(",").join(",\n ")}\n ]"
48
+ end
49
+ end
50
+
51
+ def read_gemspec
52
+ @read_gemspec ||= eval(File.read("rack-test.gemspec"))
53
+ end
54
+
55
+ def sh(command)
56
+ puts command
57
+ system command
58
+ end
59
+ end
60
+
61
+ class Default < Thor
62
+ include GemHelpers
63
+
64
+ desc "gemspec", "Regenerate rack-test.gemspec"
65
+ def gemspec
66
+ File.open("rack-test.gemspec", "w") do |file|
67
+ gemspec_ruby = generate_gemspec.to_ruby
68
+ gemspec_ruby = prettyify_array(gemspec_ruby, :files)
69
+ gemspec_ruby = prettyify_array(gemspec_ruby, :test_files)
70
+ gemspec_ruby = prettyify_array(gemspec_ruby, :extra_rdoc_files)
71
+
72
+ file.write gemspec_ruby
73
+ end
74
+
75
+ puts "Wrote gemspec to rack-test.gemspec"
76
+ read_gemspec.validate
77
+ end
78
+
79
+ desc "build", "Build a rack-test gem"
80
+ def build
81
+ sh "gem build rack-test.gemspec"
82
+ FileUtils.mkdir_p "pkg"
83
+ FileUtils.mv read_gemspec.file_name, "pkg"
84
+ end
85
+
86
+ desc "install", "Install the latest built gem"
87
+ def install
88
+ sh "gem install --local pkg/#{read_gemspec.file_name}"
89
+ end
90
+
91
+ desc "release", "Release the current branch to GitHub and Gemcutter"
92
+ def release
93
+ gemspec
94
+ build
95
+ Release.new.tag
96
+ Release.new.gem
97
+ end
98
+ end
99
+
100
+ class Release < Thor
101
+ include GemHelpers
102
+
103
+ desc "tag", "Tag the gem on the origin server"
104
+ def tag
105
+ release_tag = "v#{read_gemspec.version}"
106
+ sh "git tag -a #{release_tag} -m 'Tagging #{release_tag}'"
107
+ sh "git push origin #{release_tag}"
108
+ end
109
+
110
+ desc "gem", "Push the gem to Gemcutter"
111
+ def gem
112
+ sh "gem push pkg/#{read_gemspec.file_name}"
113
+ end
114
+ end
@@ -28,6 +28,8 @@ module Rack
28
28
  env["HTTP_COOKIE"] ||= cookie_jar.for(uri)
29
29
  @last_request = Rack::Request.new(env)
30
30
  status, headers, body = @app.call(@last_request.env)
31
+ body.close if body.respond_to?(:close)
32
+
31
33
  @last_response = MockResponse.new(status, headers, body, env["rack.errors"].flush)
32
34
  cookie_jar.merge(last_response.headers["Set-Cookie"], uri)
33
35
 
@@ -9,7 +9,7 @@ require "rack/test/uploaded_file"
9
9
 
10
10
  module Rack
11
11
  module Test
12
- VERSION = "0.5.0"
12
+ VERSION = "0.5.1"
13
13
 
14
14
  DEFAULT_HOST = "example.org"
15
15
  MULTIPART_BOUNDARY = "----------XnJLe9ZIbbGUYtzPQJ16u1"
@@ -110,8 +110,7 @@ module Rack
110
110
  end
111
111
 
112
112
  def []=(name, value)
113
- # TODO: needs proper escaping
114
- merge("#{name}=#{value}")
113
+ merge("#{name}=#{Rack::Utils.escape(value)}")
115
114
  end
116
115
 
117
116
  def merge(raw_cookies, uri = nil)
@@ -1,4 +1,5 @@
1
1
  require "tempfile"
2
+ require "fileutils"
2
3
 
3
4
  module Rack
4
5
  module Test
@@ -1,64 +1,61 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
1
  # -*- encoding: utf-8 -*-
5
2
 
6
3
  Gem::Specification.new do |s|
7
4
  s.name = %q{rack-test}
8
- s.version = "0.5.0"
5
+ s.version = "0.5.1"
9
6
 
10
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
8
  s.authors = ["Bryan Helmkamp"]
12
- s.date = %q{2009-09-19}
9
+ s.date = %q{2009-10-27}
13
10
  s.description = %q{Rack::Test is a small, simple testing API for Rack apps. It can be used on its
14
11
  own or as a reusable starting point for Web frameworks and testing libraries
15
12
  to build on. Most of its initial functionality is an extraction of Merb 1.0's
16
13
  request helpers feature.}
17
14
  s.email = %q{bryan@brynary.com}
18
15
  s.extra_rdoc_files = [
19
- "MIT-LICENSE.txt",
20
- "README.rdoc"
16
+ "README.rdoc",
17
+ "MIT-LICENSE.txt"
21
18
  ]
22
19
  s.files = [
23
20
  ".document",
24
- ".gitignore",
25
- "History.txt",
26
- "MIT-LICENSE.txt",
27
- "README.rdoc",
28
- "Rakefile",
29
- "lib/rack/mock_session.rb",
30
- "lib/rack/test.rb",
31
- "lib/rack/test/cookie_jar.rb",
32
- "lib/rack/test/methods.rb",
33
- "lib/rack/test/mock_digest_request.rb",
34
- "lib/rack/test/uploaded_file.rb",
35
- "lib/rack/test/utils.rb",
36
- "rack-test.gemspec",
37
- "spec/fixtures/config.ru",
38
- "spec/fixtures/fake_app.rb",
39
- "spec/fixtures/foo.txt",
40
- "spec/rack/test/cookie_spec.rb",
41
- "spec/rack/test/digest_auth_spec.rb",
42
- "spec/rack/test/multipart_spec.rb",
43
- "spec/rack/test/utils_spec.rb",
44
- "spec/rack/test_spec.rb",
45
- "spec/spec.opts",
46
- "spec/spec_helper.rb"
21
+ ".gitignore",
22
+ "History.txt",
23
+ "MIT-LICENSE.txt",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "Thorfile",
27
+ "lib/rack/mock_session.rb",
28
+ "lib/rack/test.rb",
29
+ "lib/rack/test/cookie_jar.rb",
30
+ "lib/rack/test/methods.rb",
31
+ "lib/rack/test/mock_digest_request.rb",
32
+ "lib/rack/test/uploaded_file.rb",
33
+ "lib/rack/test/utils.rb",
34
+ "rack-test.gemspec",
35
+ "spec/fixtures/config.ru",
36
+ "spec/fixtures/fake_app.rb",
37
+ "spec/fixtures/foo.txt",
38
+ "spec/rack/test/cookie_spec.rb",
39
+ "spec/rack/test/digest_auth_spec.rb",
40
+ "spec/rack/test/multipart_spec.rb",
41
+ "spec/rack/test/utils_spec.rb",
42
+ "spec/rack/test_spec.rb",
43
+ "spec/spec.opts",
44
+ "spec/spec_helper.rb"
47
45
  ]
48
46
  s.homepage = %q{http://github.com/brynary/rack-test}
49
- s.rdoc_options = ["--charset=UTF-8"]
50
47
  s.require_paths = ["lib"]
51
48
  s.rubyforge_project = %q{rack-test}
52
49
  s.rubygems_version = %q{1.3.5}
53
50
  s.summary = %q{Simple testing API built on Rack}
54
51
  s.test_files = [
55
52
  "spec/fixtures/fake_app.rb",
56
- "spec/rack/test/cookie_spec.rb",
57
- "spec/rack/test/digest_auth_spec.rb",
58
- "spec/rack/test/multipart_spec.rb",
59
- "spec/rack/test/utils_spec.rb",
60
- "spec/rack/test_spec.rb",
61
- "spec/spec_helper.rb"
53
+ "spec/rack/test/cookie_spec.rb",
54
+ "spec/rack/test/digest_auth_spec.rb",
55
+ "spec/rack/test/multipart_spec.rb",
56
+ "spec/rack/test/utils_spec.rb",
57
+ "spec/rack/test_spec.rb",
58
+ "spec/spec_helper.rb"
62
59
  ]
63
60
 
64
61
  if s.respond_to? :specification_version then
@@ -66,8 +63,11 @@ request helpers feature.}
66
63
  s.specification_version = 3
67
64
 
68
65
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
66
+ s.add_runtime_dependency(%q<rack>, [">= 1.0"])
69
67
  else
68
+ s.add_dependency(%q<rack>, [">= 1.0"])
70
69
  end
71
70
  else
71
+ s.add_dependency(%q<rack>, [">= 1.0"])
72
72
  end
73
73
  end
@@ -25,6 +25,12 @@ describe Rack::Test::Session do
25
25
  last_request.cookies.should == {}
26
26
  end
27
27
 
28
+ it "escapes cookie values" do
29
+ jar = Rack::Test::CookieJar.new
30
+ jar["value"] = "foo;abc"
31
+ jar["value"].should == "foo;abc"
32
+ end
33
+
28
34
  it "doesn't send cookies with the wrong domain" do
29
35
  get "http://www.example.com/cookies/set", "value" => "1"
30
36
  get "http://www.other.example/cookies/show"
@@ -106,6 +106,15 @@ describe Rack::Test::Session do
106
106
  last_request.env["rack.input"].read.should == "foo[bar]=1"
107
107
  end
108
108
 
109
+ it "closes response's body" do
110
+ body = "Hello, World!"
111
+ body.should_receive(:close)
112
+ app = lambda {|env|
113
+ [200, {"Content-Type" => "text/html", "Content-Length" => "13"}, body]
114
+ }
115
+ Rack::Test::Session.new(Rack::MockSession.new(app)).request("/")
116
+ end
117
+
109
118
  context "when input is given" do
110
119
  it "should send the input" do
111
120
  request "/", :method => "POST", :input => "foo"
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.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Helmkamp
@@ -9,10 +9,19 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-19 00:00:00 -04:00
12
+ date: 2009-10-27 00:00:00 -04:00
13
13
  default_executable:
14
- dependencies: []
15
-
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rack
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "1.0"
24
+ version:
16
25
  description: |-
17
26
  Rack::Test is a small, simple testing API for Rack apps. It can be used on its
18
27
  own or as a reusable starting point for Web frameworks and testing libraries
@@ -24,8 +33,8 @@ executables: []
24
33
  extensions: []
25
34
 
26
35
  extra_rdoc_files:
27
- - MIT-LICENSE.txt
28
36
  - README.rdoc
37
+ - MIT-LICENSE.txt
29
38
  files:
30
39
  - .document
31
40
  - .gitignore
@@ -33,6 +42,7 @@ files:
33
42
  - MIT-LICENSE.txt
34
43
  - README.rdoc
35
44
  - Rakefile
45
+ - Thorfile
36
46
  - lib/rack/mock_session.rb
37
47
  - lib/rack/test.rb
38
48
  - lib/rack/test/cookie_jar.rb
@@ -56,8 +66,8 @@ homepage: http://github.com/brynary/rack-test
56
66
  licenses: []
57
67
 
58
68
  post_install_message:
59
- rdoc_options:
60
- - --charset=UTF-8
69
+ rdoc_options: []
70
+
61
71
  require_paths:
62
72
  - lib
63
73
  required_ruby_version: !ruby/object:Gem::Requirement