rack-test 0.6.3 → 0.8.0
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.
- checksums.yaml +7 -0
- data/{History.txt → History.md} +87 -58
- data/README.md +139 -0
- data/lib/rack/mock_session.rb +6 -9
- data/lib/rack/test/cookie_jar.rb +38 -28
- data/lib/rack/test/methods.rb +22 -22
- data/lib/rack/test/mock_digest_request.rb +1 -5
- data/lib/rack/test/uploaded_file.rb +41 -19
- data/lib/rack/test/utils.rb +37 -43
- data/lib/rack/test/version.rb +5 -0
- data/lib/rack/test.rb +79 -78
- metadata +139 -60
- data/.document +0 -4
- data/.gitignore +0 -6
- data/Gemfile +0 -8
- data/Gemfile.lock +0 -41
- data/README.rdoc +0 -85
- data/Rakefile +0 -33
- data/Thorfile +0 -114
- data/rack-test.gemspec +0 -77
- data/spec/fixtures/bar.txt +0 -1
- data/spec/fixtures/config.ru +0 -3
- data/spec/fixtures/fake_app.rb +0 -143
- data/spec/fixtures/foo.txt +0 -1
- data/spec/rack/test/cookie_spec.rb +0 -219
- data/spec/rack/test/digest_auth_spec.rb +0 -46
- data/spec/rack/test/multipart_spec.rb +0 -145
- data/spec/rack/test/uploaded_file_spec.rb +0 -24
- data/spec/rack/test/utils_spec.rb +0 -193
- data/spec/rack/test_spec.rb +0 -550
- data/spec/spec_helper.rb +0 -69
- data/spec/support/matchers/body.rb +0 -9
- data/spec/support/matchers/challenge.rb +0 -11
data/.document
DELETED
data/.gitignore
DELETED
data/Gemfile
DELETED
data/Gemfile.lock
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
GEM
|
2
|
-
remote: https://rubygems.org/
|
3
|
-
specs:
|
4
|
-
codeclimate-test-reporter (0.3.0)
|
5
|
-
simplecov (>= 0.7.1, < 1.0.0)
|
6
|
-
diff-lcs (1.2.3)
|
7
|
-
docile (1.1.3)
|
8
|
-
multi_json (1.9.0)
|
9
|
-
rack (1.5.2)
|
10
|
-
rack-protection (1.5.0)
|
11
|
-
rack
|
12
|
-
rake (10.0.4)
|
13
|
-
rspec (2.13.0)
|
14
|
-
rspec-core (~> 2.13.0)
|
15
|
-
rspec-expectations (~> 2.13.0)
|
16
|
-
rspec-mocks (~> 2.13.0)
|
17
|
-
rspec-core (2.13.1)
|
18
|
-
rspec-expectations (2.13.0)
|
19
|
-
diff-lcs (>= 1.1.3, < 2.0)
|
20
|
-
rspec-mocks (2.13.1)
|
21
|
-
simplecov (0.8.2)
|
22
|
-
docile (~> 1.1.0)
|
23
|
-
multi_json
|
24
|
-
simplecov-html (~> 0.8.0)
|
25
|
-
simplecov-html (0.8.0)
|
26
|
-
sinatra (1.4.2)
|
27
|
-
rack (~> 1.5, >= 1.5.2)
|
28
|
-
rack-protection (~> 1.4)
|
29
|
-
tilt (~> 1.3, >= 1.3.4)
|
30
|
-
tilt (1.3.7)
|
31
|
-
|
32
|
-
PLATFORMS
|
33
|
-
java
|
34
|
-
ruby
|
35
|
-
|
36
|
-
DEPENDENCIES
|
37
|
-
codeclimate-test-reporter
|
38
|
-
rack
|
39
|
-
rake
|
40
|
-
rspec
|
41
|
-
sinatra
|
data/README.rdoc
DELETED
@@ -1,85 +0,0 @@
|
|
1
|
-
= Rack::Test {<img src="https://codeclimate.com/github/brynary/rack-test.png" />}[https://codeclimate.com/github/brynary/rack-test] {<img src="https://codeclimate.com/github/brynary/rack-test/coverage.png" />}[https://codeclimate.com/github/brynary/rack-test]
|
2
|
-
|
3
|
-
- Code: http://github.com/brynary/rack-test
|
4
|
-
|
5
|
-
== Description
|
6
|
-
|
7
|
-
Rack::Test is a small, simple testing API for Rack apps. It can be used on its
|
8
|
-
own or as a reusable starting point for Web frameworks and testing libraries
|
9
|
-
to build on. Most of its initial functionality is an extraction of Merb 1.0's
|
10
|
-
request helpers feature.
|
11
|
-
|
12
|
-
== Features
|
13
|
-
|
14
|
-
* Maintains a cookie jar across requests
|
15
|
-
* Easily follow redirects when desired
|
16
|
-
* Set request headers to be used by all subsequent requests
|
17
|
-
* Small footprint. Approximately 200 LOC
|
18
|
-
|
19
|
-
== Examples
|
20
|
-
|
21
|
-
require "rack/test"
|
22
|
-
|
23
|
-
class HomepageTest < Test::Unit::TestCase
|
24
|
-
include Rack::Test::Methods
|
25
|
-
|
26
|
-
def app
|
27
|
-
MyApp.new
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_redirect_logged_in_users_to_dashboard
|
31
|
-
authorize "bryan", "secret"
|
32
|
-
get "/"
|
33
|
-
follow_redirect!
|
34
|
-
|
35
|
-
assert_equal "http://example.org/redirected", last_request.url
|
36
|
-
assert last_response.ok?
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
|
42
|
-
If you want to test one app in isolation, you just return that app as shown above. But if you want to test the entire app stack, including middlewares, cascades etc. you need to parse the app defined in config.ru.
|
43
|
-
|
44
|
-
OUTER_APP = Rack::Builder.parse_file('config.ru').first
|
45
|
-
|
46
|
-
class TestApp < Test::Unit::TestCase
|
47
|
-
include Rack::Test::Methods
|
48
|
-
|
49
|
-
def app
|
50
|
-
OUTER_APP
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_root
|
54
|
-
get '/'
|
55
|
-
assert last_response.ok?
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
|
60
|
-
== Install
|
61
|
-
|
62
|
-
To install the latest release as a gem:
|
63
|
-
|
64
|
-
sudo gem install rack-test
|
65
|
-
|
66
|
-
Or via Bundler:
|
67
|
-
|
68
|
-
gem "rack-test", require: "rack/test"
|
69
|
-
|
70
|
-
== Authors
|
71
|
-
|
72
|
-
- Maintained by {Bryan Helmkamp}[mailto:bryan@brynary.com]
|
73
|
-
- Contributions from Simon Rozet, Pat Nakajima and others
|
74
|
-
- Much of the original code was extracted from Merb 1.0's request helper
|
75
|
-
|
76
|
-
== License
|
77
|
-
|
78
|
-
Copyright (c) 2008-2009 Bryan Helmkamp, Engine Yard Inc.
|
79
|
-
See MIT-LICENSE.txt in this directory.
|
80
|
-
|
81
|
-
== Releasing
|
82
|
-
|
83
|
-
* Ensure History.txt is up-to-date
|
84
|
-
* Bump VERSION in lib/rack/test.rb
|
85
|
-
* thor :release
|
data/Rakefile
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
require "rubygems"
|
2
|
-
|
3
|
-
|
4
|
-
require 'rspec/core'
|
5
|
-
require "rspec/core/rake_task"
|
6
|
-
|
7
|
-
RSpec::Core::RakeTask.new do |t|
|
8
|
-
t.pattern = "./**/*_spec.rb"
|
9
|
-
t.ruby_opts = "-w"
|
10
|
-
end
|
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
|
-
|
23
|
-
desc "Generate RDoc"
|
24
|
-
task :docs do
|
25
|
-
FileUtils.rm_rf("doc")
|
26
|
-
require "rack/test"
|
27
|
-
system "hanna --title 'Rack::Test #{Rack::Test::VERSION} API Documentation'"
|
28
|
-
end
|
29
|
-
|
30
|
-
desc 'Removes trailing whitespace'
|
31
|
-
task :whitespace do
|
32
|
-
sh %{find . -name '*.rb' -exec sed -i '' 's/ *$//g' {} \\;}
|
33
|
-
end
|
data/Thorfile
DELETED
@@ -1,114 +0,0 @@
|
|
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
|
data/rack-test.gemspec
DELETED
@@ -1,77 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
Gem::Specification.new do |s|
|
4
|
-
s.name = "rack-test"
|
5
|
-
s.version = "0.6.3"
|
6
|
-
|
7
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
-
s.authors = ["Bryan Helmkamp"]
|
9
|
-
s.date = "2015-01-09"
|
10
|
-
s.description = "Rack::Test is a small, simple testing API for Rack apps. It can be used on its\nown or as a reusable starting point for Web frameworks and testing libraries\nto build on. Most of its initial functionality is an extraction of Merb 1.0's\nrequest helpers feature."
|
11
|
-
s.email = "bryan@brynary.com"
|
12
|
-
s.extra_rdoc_files = [
|
13
|
-
"README.rdoc",
|
14
|
-
"MIT-LICENSE.txt"
|
15
|
-
]
|
16
|
-
s.files = [
|
17
|
-
".document",
|
18
|
-
".gitignore",
|
19
|
-
"Gemfile",
|
20
|
-
"Gemfile.lock",
|
21
|
-
"History.txt",
|
22
|
-
"MIT-LICENSE.txt",
|
23
|
-
"README.rdoc",
|
24
|
-
"Rakefile",
|
25
|
-
"Thorfile",
|
26
|
-
"lib/rack/mock_session.rb",
|
27
|
-
"lib/rack/test.rb",
|
28
|
-
"lib/rack/test/cookie_jar.rb",
|
29
|
-
"lib/rack/test/methods.rb",
|
30
|
-
"lib/rack/test/mock_digest_request.rb",
|
31
|
-
"lib/rack/test/uploaded_file.rb",
|
32
|
-
"lib/rack/test/utils.rb",
|
33
|
-
"rack-test.gemspec",
|
34
|
-
"spec/fixtures/bar.txt",
|
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/uploaded_file_spec.rb",
|
42
|
-
"spec/rack/test/utils_spec.rb",
|
43
|
-
"spec/rack/test_spec.rb",
|
44
|
-
"spec/spec_helper.rb",
|
45
|
-
"spec/support/matchers/body.rb",
|
46
|
-
"spec/support/matchers/challenge.rb"
|
47
|
-
]
|
48
|
-
s.homepage = "http://github.com/brynary/rack-test"
|
49
|
-
s.require_paths = ["lib"]
|
50
|
-
s.rubyforge_project = "rack-test"
|
51
|
-
s.rubygems_version = "1.8.23"
|
52
|
-
s.summary = "Simple testing API built on Rack"
|
53
|
-
s.test_files = [
|
54
|
-
"spec/fixtures/fake_app.rb",
|
55
|
-
"spec/rack/test/cookie_spec.rb",
|
56
|
-
"spec/rack/test/digest_auth_spec.rb",
|
57
|
-
"spec/rack/test/multipart_spec.rb",
|
58
|
-
"spec/rack/test/uploaded_file_spec.rb",
|
59
|
-
"spec/rack/test/utils_spec.rb",
|
60
|
-
"spec/rack/test_spec.rb",
|
61
|
-
"spec/spec_helper.rb",
|
62
|
-
"spec/support/matchers/body.rb",
|
63
|
-
"spec/support/matchers/challenge.rb"
|
64
|
-
]
|
65
|
-
|
66
|
-
if s.respond_to? :specification_version then
|
67
|
-
s.specification_version = 3
|
68
|
-
|
69
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
70
|
-
s.add_runtime_dependency(%q<rack>, [">= 1.0"])
|
71
|
-
else
|
72
|
-
s.add_dependency(%q<rack>, [">= 1.0"])
|
73
|
-
end
|
74
|
-
else
|
75
|
-
s.add_dependency(%q<rack>, [">= 1.0"])
|
76
|
-
end
|
77
|
-
end
|
data/spec/fixtures/bar.txt
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
baz
|
data/spec/fixtures/config.ru
DELETED
data/spec/fixtures/fake_app.rb
DELETED
@@ -1,143 +0,0 @@
|
|
1
|
-
require "rubygems"
|
2
|
-
require "sinatra/base"
|
3
|
-
|
4
|
-
module Rack
|
5
|
-
module Test
|
6
|
-
|
7
|
-
class FakeApp < Sinatra::Base
|
8
|
-
head "/" do
|
9
|
-
"meh"
|
10
|
-
end
|
11
|
-
|
12
|
-
options "/" do
|
13
|
-
[200, {}, ""]
|
14
|
-
end
|
15
|
-
|
16
|
-
get "/" do
|
17
|
-
"Hello, GET: #{params.inspect}"
|
18
|
-
end
|
19
|
-
|
20
|
-
get "/redirect" do
|
21
|
-
redirect "/redirected"
|
22
|
-
end
|
23
|
-
|
24
|
-
get "/redirected" do
|
25
|
-
"You've been redirected"
|
26
|
-
end
|
27
|
-
|
28
|
-
get "/void" do
|
29
|
-
[200, {}, ""]
|
30
|
-
end
|
31
|
-
|
32
|
-
get "/cookies/show" do
|
33
|
-
request.cookies.inspect
|
34
|
-
end
|
35
|
-
|
36
|
-
get "/COOKIES/show" do
|
37
|
-
request.cookies.inspect
|
38
|
-
end
|
39
|
-
|
40
|
-
get "/not-cookies/show" do
|
41
|
-
request.cookies.inspect
|
42
|
-
end
|
43
|
-
|
44
|
-
get "/cookies/set-secure" do
|
45
|
-
raise if params["value"].nil?
|
46
|
-
|
47
|
-
response.set_cookie("secure-cookie", :value => params["value"], :secure => true)
|
48
|
-
"Set"
|
49
|
-
end
|
50
|
-
|
51
|
-
get "/cookies/set-simple" do
|
52
|
-
raise if params["value"].nil?
|
53
|
-
|
54
|
-
response.set_cookie "simple", params["value"]
|
55
|
-
"Set"
|
56
|
-
end
|
57
|
-
|
58
|
-
post "/cookies/default-path" do
|
59
|
-
raise if params["value"].nil?
|
60
|
-
|
61
|
-
response.set_cookie "simple", params["value"]
|
62
|
-
"Set"
|
63
|
-
end
|
64
|
-
|
65
|
-
get "/cookies/default-path" do
|
66
|
-
response.cookies.inspect
|
67
|
-
end
|
68
|
-
|
69
|
-
get "/cookies/delete" do
|
70
|
-
response.delete_cookie "value"
|
71
|
-
end
|
72
|
-
|
73
|
-
get "/cookies/count" do
|
74
|
-
old_value = request.cookies["count"].to_i || 0
|
75
|
-
new_value = (old_value + 1).to_s
|
76
|
-
|
77
|
-
response.set_cookie("count", :value => new_value)
|
78
|
-
new_value
|
79
|
-
end
|
80
|
-
|
81
|
-
get "/cookies/set" do
|
82
|
-
raise if params["value"].nil?
|
83
|
-
|
84
|
-
response.set_cookie("value", {
|
85
|
-
:value => params["value"],
|
86
|
-
:path => "/cookies",
|
87
|
-
:expires => Time.now + 10
|
88
|
-
})
|
89
|
-
"Set"
|
90
|
-
end
|
91
|
-
|
92
|
-
get "/cookies/domain" do
|
93
|
-
old_value = request.cookies["count"].to_i || 0
|
94
|
-
new_value = (old_value + 1).to_s
|
95
|
-
|
96
|
-
response.set_cookie("count", :value => new_value, :domain => "localhost.com")
|
97
|
-
new_value
|
98
|
-
end
|
99
|
-
|
100
|
-
get "/cookies/subdomain" do
|
101
|
-
old_value = request.cookies["count"].to_i || 0
|
102
|
-
new_value = (old_value + 1).to_s
|
103
|
-
|
104
|
-
response.set_cookie("count", :value => new_value, :domain => ".example.org")
|
105
|
-
new_value
|
106
|
-
end
|
107
|
-
|
108
|
-
get "/cookies/set-uppercase" do
|
109
|
-
raise if params["value"].nil?
|
110
|
-
|
111
|
-
response.set_cookie("VALUE", {
|
112
|
-
:value => params["value"],
|
113
|
-
:path => "/cookies",
|
114
|
-
:expires => Time.now + 10
|
115
|
-
})
|
116
|
-
"Set"
|
117
|
-
end
|
118
|
-
|
119
|
-
get "/cookies/set-multiple" do
|
120
|
-
response.set_cookie("key1", :value => "value1")
|
121
|
-
response.set_cookie("key2", :value => "value2")
|
122
|
-
"Set"
|
123
|
-
end
|
124
|
-
|
125
|
-
post "/" do
|
126
|
-
"Hello, POST: #{params.inspect}"
|
127
|
-
end
|
128
|
-
|
129
|
-
put "/" do
|
130
|
-
"Hello, PUT: #{params.inspect}"
|
131
|
-
end
|
132
|
-
|
133
|
-
patch "/" do
|
134
|
-
"Hello, PUT: #{params.inspect}"
|
135
|
-
end
|
136
|
-
|
137
|
-
delete "/" do
|
138
|
-
"Hello, DELETE: #{params.inspect}"
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
end
|
143
|
-
end
|