jodosha-rack-test 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/Rakefile +24 -0
- data/lib/rack/test.rb +1 -0
- data/lib/rack/unit/test_case.rb +75 -0
- data/rack-test.gemspec +13 -0
- metadata +58 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Luca Guidi
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
$:.unshift 'lib'
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/testtask'
|
4
|
+
require 'rake/rdoctask'
|
5
|
+
|
6
|
+
RACK_TEST_VERSION = "0.0.1"
|
7
|
+
|
8
|
+
desc 'Default: run unit tests.'
|
9
|
+
task :default => :test
|
10
|
+
|
11
|
+
desc 'Build and install the gem (useful for development purposes).'
|
12
|
+
task :install do
|
13
|
+
require 'rack/test'
|
14
|
+
system "gem build rack-test.gemspec"
|
15
|
+
system "sudo gem uninstall rack-test"
|
16
|
+
system "sudo gem install --local --no-rdoc --no-ri rack-test-#{RACK_TEST_VERSION}.gem"
|
17
|
+
system "rm rack-test-*.gem"
|
18
|
+
end
|
19
|
+
|
20
|
+
desc 'Show the file list for the gemspec file'
|
21
|
+
task :files do
|
22
|
+
puts "Files:\n #{Dir['**/*'].reject {|f| File.directory?(f)}.sort.inspect}"
|
23
|
+
puts "Test files:\n #{Dir['test/**/*_test.rb'].reject {|f| File.directory?(f)}.sort.inspect}"
|
24
|
+
end
|
data/lib/rack/test.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "rack/unit/test_case"
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
|
3
|
+
module Rack
|
4
|
+
module Unit
|
5
|
+
class TestCase < ::Test::Unit::TestCase
|
6
|
+
attr_reader :app, :response
|
7
|
+
attr_accessor :request
|
8
|
+
|
9
|
+
def env #:nodoc:
|
10
|
+
@env ||= {}
|
11
|
+
end
|
12
|
+
|
13
|
+
# Performs a GET request with the given path and headers.
|
14
|
+
def get(path, headers = {})
|
15
|
+
process :get, path, headers
|
16
|
+
end
|
17
|
+
|
18
|
+
def response=(response) #:nodoc:
|
19
|
+
@response = Rack::Response.new(response[2], response[0], response[1])
|
20
|
+
end
|
21
|
+
|
22
|
+
# Assert the status of the current response
|
23
|
+
#
|
24
|
+
# Example:
|
25
|
+
# assert_response 200
|
26
|
+
# assert_response 301..302
|
27
|
+
# assert_response :success
|
28
|
+
# assert_response :redirect
|
29
|
+
# assert_response :client_error
|
30
|
+
# assert_response :not_found
|
31
|
+
# assert_response :unprocessable_entity
|
32
|
+
# assert_response :server_error
|
33
|
+
def assert_response(status, message = nil)
|
34
|
+
case status
|
35
|
+
when Fixnum
|
36
|
+
assert_equal response.status, status, message
|
37
|
+
when Range
|
38
|
+
assert status.to_a.include?(response.status), message
|
39
|
+
when :success
|
40
|
+
assert_response 200, message
|
41
|
+
when :redirect
|
42
|
+
assert_response 301..302, message
|
43
|
+
when :client_error
|
44
|
+
assert_response 400, message
|
45
|
+
when :not_found
|
46
|
+
assert_response 404, message
|
47
|
+
when :unprocessable_entity
|
48
|
+
assert_response 412, message
|
49
|
+
when :server_error
|
50
|
+
assert_response 500, message
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# Assert to be redirected to the given path
|
55
|
+
#
|
56
|
+
# Example:
|
57
|
+
# assert_redirected_to "/projects/sashimi"
|
58
|
+
def assert_redirected_to(path, message = nil)
|
59
|
+
assert_response :redirect, message
|
60
|
+
assert_equal response.header["Location"], path, message
|
61
|
+
end
|
62
|
+
|
63
|
+
def default_test #:nodoc:
|
64
|
+
end
|
65
|
+
|
66
|
+
protected
|
67
|
+
def process(method, path, headers = {}) #:nodoc:
|
68
|
+
env["REQUEST_METHOD"] = method.to_s.upcase
|
69
|
+
env["PATH_INFO"] = path
|
70
|
+
self.request = Rack::Request.new(env)
|
71
|
+
self.response = app.call(env)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
data/rack-test.gemspec
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "rack-test"
|
3
|
+
s.version = "0.0.1"
|
4
|
+
s.date = "2009-03-26"
|
5
|
+
s.summary = "Test for Rack"
|
6
|
+
s.author = "Luca Guidi"
|
7
|
+
s.email = "guidi.luca@gmail.com"
|
8
|
+
s.homepage = "http://lucaguidi.com"
|
9
|
+
s.description = "Test for Rack"
|
10
|
+
s.has_rdoc = true
|
11
|
+
s.files = ["MIT-LICENSE", "README.rdoc", "Rakefile", "lib/rack/test.rb", "lib/rack/unit/test_case.rb", "rack-test.gemspec"]
|
12
|
+
s.extra_rdoc_files = ['README.rdoc']
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jodosha-rack-test
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Luca Guidi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-03-26 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Test for Rack
|
17
|
+
email: guidi.luca@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.rdoc
|
24
|
+
files:
|
25
|
+
- MIT-LICENSE
|
26
|
+
- README.rdoc
|
27
|
+
- Rakefile
|
28
|
+
- lib/rack/test.rb
|
29
|
+
- lib/rack/unit/test_case.rb
|
30
|
+
- rack-test.gemspec
|
31
|
+
has_rdoc: true
|
32
|
+
homepage: http://lucaguidi.com
|
33
|
+
post_install_message:
|
34
|
+
rdoc_options: []
|
35
|
+
|
36
|
+
require_paths:
|
37
|
+
- lib
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: "0"
|
43
|
+
version:
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: "0"
|
49
|
+
version:
|
50
|
+
requirements: []
|
51
|
+
|
52
|
+
rubyforge_project:
|
53
|
+
rubygems_version: 1.2.0
|
54
|
+
signing_key:
|
55
|
+
specification_version: 2
|
56
|
+
summary: Test for Rack
|
57
|
+
test_files: []
|
58
|
+
|