hiroeorz-rspec-response-code-matchers 0.9.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.
- data/LICENSE +20 -0
- data/README.rdoc +41 -0
- data/Rakefile +48 -0
- data/VERSION.yml +4 -0
- data/lib/rspec_response_code_matchers.rb +197 -0
- data/spec/rspec_response_code_matchers_spec.rb +82 -0
- data/spec/spec_helper.rb +9 -0
- metadata +61 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 hiroeorz
|
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/README.rdoc
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
= rspec-response-code-matcher
|
2
|
+
|
3
|
+
* http://github.com/hiroeorz/rspec-response-code-matchers/tree/master
|
4
|
+
* mailto:hiroeorz@gmail.com
|
5
|
+
|
6
|
+
== DESCRIPTION:
|
7
|
+
|
8
|
+
RSpecResponseCodeMatchers is rspec's custom spec matcher, that checking http response code.
|
9
|
+
|
10
|
+
|
11
|
+
== SYNOPSIS:
|
12
|
+
|
13
|
+
target is Integer or Object, that defined "status" method.
|
14
|
+
|
15
|
+
require "rspec_response_code_matchers"
|
16
|
+
|
17
|
+
500.should be_internal_server_error
|
18
|
+
404.should be_not_found
|
19
|
+
|
20
|
+
===If you use merb rspec:
|
21
|
+
|
22
|
+
in spec/spec_helper.rb:
|
23
|
+
require "rspec_response_code_matchers"
|
24
|
+
|
25
|
+
in spec/requests/sample_helper.rb:
|
26
|
+
|
27
|
+
describe "/sample/show" do
|
28
|
+
before(:each) do
|
29
|
+
@response = request("/sample/show")
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should response code 301(redirect)" do
|
33
|
+
@response.should be_redirect # match 3xx
|
34
|
+
@response.should be_moved_permanently # match 301
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
== Copyright
|
40
|
+
|
41
|
+
Copyright (c) 2009 hiroeorz. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "rspec-response-code-matchers"
|
8
|
+
gem.summary = %Q{TODO}
|
9
|
+
gem.email = "hiroe.orz@gmail.com"
|
10
|
+
gem.homepage = "http://github.com/hiroeorz/rspec-response-code-matchers"
|
11
|
+
gem.authors = ["hiroeorz"]
|
12
|
+
|
13
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
14
|
+
end
|
15
|
+
rescue LoadError
|
16
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'spec/rake/spectask'
|
20
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
21
|
+
spec.libs << 'lib' << 'spec'
|
22
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
23
|
+
end
|
24
|
+
|
25
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
26
|
+
spec.libs << 'lib' << 'spec'
|
27
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
28
|
+
spec.rcov = true
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
task :default => :spec
|
33
|
+
|
34
|
+
require 'rake/rdoctask'
|
35
|
+
Rake::RDocTask.new do |rdoc|
|
36
|
+
if File.exist?('VERSION.yml')
|
37
|
+
config = YAML.load(File.read('VERSION.yml'))
|
38
|
+
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
39
|
+
else
|
40
|
+
version = ""
|
41
|
+
end
|
42
|
+
|
43
|
+
rdoc.rdoc_dir = 'rdoc'
|
44
|
+
rdoc.title = "rspec-response-code-matchers #{version}"
|
45
|
+
rdoc.rdoc_files.include('README*')
|
46
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
47
|
+
end
|
48
|
+
|
data/VERSION.yml
ADDED
@@ -0,0 +1,197 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
class BeStatus
|
4
|
+
def initialize(status)
|
5
|
+
@status = status
|
6
|
+
end
|
7
|
+
|
8
|
+
def matches?(target)
|
9
|
+
if defined?(target.status)
|
10
|
+
@target = target.status
|
11
|
+
else
|
12
|
+
@target = target
|
13
|
+
end
|
14
|
+
|
15
|
+
if @status.is_a?(Range)
|
16
|
+
return @status.include?(@target)
|
17
|
+
else
|
18
|
+
return @target == @status
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def failure_message_for_should
|
23
|
+
"expected #{@target} to be Status #{@status}"
|
24
|
+
end
|
25
|
+
|
26
|
+
def failure_message_for_should_not
|
27
|
+
"expected #{@target} not to be in Status #{@status}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def be_information
|
32
|
+
BeStatus.new(100..101)
|
33
|
+
end
|
34
|
+
|
35
|
+
def be_continue
|
36
|
+
BeStatus.new(100)
|
37
|
+
end
|
38
|
+
|
39
|
+
def be_switching_protocols
|
40
|
+
BeStatus.new(101)
|
41
|
+
end
|
42
|
+
|
43
|
+
# def be_successful
|
44
|
+
# BeStatus.new(200..206)
|
45
|
+
# end
|
46
|
+
|
47
|
+
def be_request_ok
|
48
|
+
BeStatus.new(200)
|
49
|
+
end
|
50
|
+
|
51
|
+
def be_resource_created
|
52
|
+
BeStatus.new(201)
|
53
|
+
end
|
54
|
+
|
55
|
+
def be_request_accepted
|
56
|
+
BeStatus.new(202)
|
57
|
+
end
|
58
|
+
|
59
|
+
def be_non_authoritative_information
|
60
|
+
BeStatus.new(203)
|
61
|
+
end
|
62
|
+
|
63
|
+
def be_no_content
|
64
|
+
BeStatus.new(204)
|
65
|
+
end
|
66
|
+
|
67
|
+
def be_reset_content
|
68
|
+
BeStatus.new(205)
|
69
|
+
end
|
70
|
+
|
71
|
+
def be_partial_content
|
72
|
+
BeStatus.new(206)
|
73
|
+
end
|
74
|
+
|
75
|
+
def be_redirect
|
76
|
+
BeStatus.new(300..305)
|
77
|
+
end
|
78
|
+
|
79
|
+
def be_multiple_choices
|
80
|
+
BeStatus.new(300)
|
81
|
+
end
|
82
|
+
|
83
|
+
def be_moved_permanently
|
84
|
+
BeStatus.new(301)
|
85
|
+
end
|
86
|
+
|
87
|
+
def be_moved_temporarily
|
88
|
+
BeStatus.new(302)
|
89
|
+
end
|
90
|
+
|
91
|
+
def be_see_other
|
92
|
+
BeStatus.new(303)
|
93
|
+
end
|
94
|
+
|
95
|
+
def be_not_modified
|
96
|
+
BeStatus.new(304)
|
97
|
+
end
|
98
|
+
|
99
|
+
def be_use_proxy
|
100
|
+
BeStatus.new(305)
|
101
|
+
end
|
102
|
+
|
103
|
+
def be_client_error
|
104
|
+
BeStatus.new(400..415)
|
105
|
+
end
|
106
|
+
|
107
|
+
def be_bad_request
|
108
|
+
BeStatus.new(400)
|
109
|
+
end
|
110
|
+
|
111
|
+
def be_unauthorized
|
112
|
+
BeStatus.new(401)
|
113
|
+
end
|
114
|
+
|
115
|
+
def be_payment_required
|
116
|
+
BeStatus.new(402)
|
117
|
+
end
|
118
|
+
|
119
|
+
def be_forbidden
|
120
|
+
BeStatus.new(403)
|
121
|
+
end
|
122
|
+
|
123
|
+
def be_not_found
|
124
|
+
BeStatus.new(404)
|
125
|
+
end
|
126
|
+
|
127
|
+
def be_method_not_allowed
|
128
|
+
BeStatus.new(405)
|
129
|
+
end
|
130
|
+
|
131
|
+
def be_not_acceptable
|
132
|
+
BeStatus.new(406)
|
133
|
+
end
|
134
|
+
|
135
|
+
def be_proxy_authentication_required
|
136
|
+
BeStatus.new(407)
|
137
|
+
end
|
138
|
+
|
139
|
+
def be_request_timeout
|
140
|
+
BeStatus.new(408)
|
141
|
+
end
|
142
|
+
|
143
|
+
def be_request_conflict
|
144
|
+
BeStatus.new(409)
|
145
|
+
end
|
146
|
+
|
147
|
+
def be_resource_is_gone
|
148
|
+
BeStatus.new(410)
|
149
|
+
end
|
150
|
+
|
151
|
+
def be_length_required
|
152
|
+
BeStatus.new(411)
|
153
|
+
end
|
154
|
+
|
155
|
+
def be_precondition_failed
|
156
|
+
BeStatus.new(412)
|
157
|
+
end
|
158
|
+
|
159
|
+
def be_request_entity_too_large
|
160
|
+
BeStatus.new(413)
|
161
|
+
end
|
162
|
+
|
163
|
+
def be_request_uri_too_large
|
164
|
+
BeStatus.new(414)
|
165
|
+
end
|
166
|
+
|
167
|
+
def be_unsupported_media_type
|
168
|
+
BeStatus.new(415)
|
169
|
+
end
|
170
|
+
|
171
|
+
def be_server_error
|
172
|
+
BeStatus.new(500..505)
|
173
|
+
end
|
174
|
+
|
175
|
+
def be_internal_server_error
|
176
|
+
BeStatus.new(500)
|
177
|
+
end
|
178
|
+
|
179
|
+
def be_not_implemented
|
180
|
+
BeStatus.new(501)
|
181
|
+
end
|
182
|
+
|
183
|
+
def be_bad_gateway
|
184
|
+
BeStatus.new(502)
|
185
|
+
end
|
186
|
+
|
187
|
+
def be_service_unavailable
|
188
|
+
BeStatus.new(503)
|
189
|
+
end
|
190
|
+
|
191
|
+
def be_gateway_timeout
|
192
|
+
BeStatus.new(504)
|
193
|
+
end
|
194
|
+
|
195
|
+
def be_http_version_not_supported
|
196
|
+
BeStatus.new(505)
|
197
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
describe "RspecResponseCodeMatchers" do
|
4
|
+
it "should information response" do
|
5
|
+
100.should be_information
|
6
|
+
200.should_not be_information
|
7
|
+
|
8
|
+
100.should be_continue
|
9
|
+
101.should be_switching_protocols
|
10
|
+
|
11
|
+
303.should_not be_continue
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should success response" do
|
15
|
+
200.should be_request_ok
|
16
|
+
201.should be_resource_created
|
17
|
+
202.should be_request_accepted
|
18
|
+
203.should be_non_authoritative_information
|
19
|
+
204.should be_no_content
|
20
|
+
205.should be_reset_content
|
21
|
+
206.should be_partial_content
|
22
|
+
|
23
|
+
506.should_not be_partial_content
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should redirect response" do
|
27
|
+
302.should be_redirect
|
28
|
+
404.should_not be_redirect
|
29
|
+
|
30
|
+
300.should be_multiple_choices
|
31
|
+
301.should be_moved_permanently
|
32
|
+
302.should be_moved_temporarily
|
33
|
+
|
34
|
+
502.should_not be_moved_temporarily
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should client error response" do
|
38
|
+
MockResponse.new(404).should be_client_error
|
39
|
+
MockResponse.new(504).should_not be_client_error
|
40
|
+
|
41
|
+
MockResponse.new(400).should be_bad_request
|
42
|
+
MockResponse.new(401).should be_unauthorized
|
43
|
+
MockResponse.new(402).should be_payment_required
|
44
|
+
MockResponse.new(403).should be_forbidden
|
45
|
+
MockResponse.new(404).should be_not_found
|
46
|
+
MockResponse.new(405).should be_method_not_allowed
|
47
|
+
MockResponse.new(406).should be_not_acceptable
|
48
|
+
MockResponse.new(407).should be_proxy_authentication_required
|
49
|
+
MockResponse.new(408).should be_request_timeout
|
50
|
+
MockResponse.new(409).should be_request_conflict
|
51
|
+
MockResponse.new(410).should be_resource_is_gone
|
52
|
+
MockResponse.new(411).should be_length_required
|
53
|
+
MockResponse.new(412).should be_precondition_failed
|
54
|
+
MockResponse.new(413).should be_request_entity_too_large
|
55
|
+
MockResponse.new(414).should be_request_uri_too_large
|
56
|
+
MockResponse.new(415).should be_unsupported_media_type
|
57
|
+
|
58
|
+
MockResponse.new(515).should_not be_unsupported_media_type
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should server error response" do
|
62
|
+
MockResponse.new(504).should be_server_error
|
63
|
+
MockResponse.new(404).should_not be_server_error
|
64
|
+
|
65
|
+
MockResponse.new(500).should be_internal_server_error
|
66
|
+
MockResponse.new(501).should be_not_implemented
|
67
|
+
MockResponse.new(502).should be_bad_gateway
|
68
|
+
MockResponse.new(503).should be_service_unavailable
|
69
|
+
MockResponse.new(504).should be_gateway_timeout
|
70
|
+
MockResponse.new(505).should be_http_version_not_supported
|
71
|
+
|
72
|
+
MockResponse.new(405).should_not be_http_version_not_supported
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
class MockResponse
|
77
|
+
attr_accessor :status
|
78
|
+
|
79
|
+
def initialize(status)
|
80
|
+
@status = status
|
81
|
+
end
|
82
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hiroeorz-rspec-response-code-matchers
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- hiroeorz
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-05-15 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: hiroe.orz@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- LICENSE
|
24
|
+
- README.rdoc
|
25
|
+
files:
|
26
|
+
- LICENSE
|
27
|
+
- README.rdoc
|
28
|
+
- Rakefile
|
29
|
+
- VERSION.yml
|
30
|
+
- lib/rspec_response_code_matchers.rb
|
31
|
+
- spec/rspec_response_code_matchers_spec.rb
|
32
|
+
- spec/spec_helper.rb
|
33
|
+
has_rdoc: true
|
34
|
+
homepage: http://github.com/hiroeorz/rspec-response-code-matchers
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options:
|
37
|
+
- --charset=UTF-8
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: "0"
|
45
|
+
version:
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: "0"
|
51
|
+
version:
|
52
|
+
requirements: []
|
53
|
+
|
54
|
+
rubyforge_project:
|
55
|
+
rubygems_version: 1.2.0
|
56
|
+
signing_key:
|
57
|
+
specification_version: 2
|
58
|
+
summary: TODO
|
59
|
+
test_files:
|
60
|
+
- spec/spec_helper.rb
|
61
|
+
- spec/rspec_response_code_matchers_spec.rb
|