response_code_matchers 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +116 -0
- data/Rakefile +1 -0
- data/lib/response_code_matchers/version.rb +3 -0
- data/lib/response_code_matchers.rb +35 -0
- data/response_code_matchers.gemspec +22 -0
- data/spec/response_code_matchers_spec.rb +68 -0
- data/spec/spec_helper.rb +9 -0
- metadata +103 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Ryo NAKAMURA
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
# ResponseCodeMatchers
|
2
|
+
|
3
|
+
Provide rspec matchers to match http response code.
|
4
|
+
The receiver of this matcher should have `#code` method which returns http status code.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
```
|
8
|
+
$ gem install response_code_matchers
|
9
|
+
```
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
In Rails example:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
# spec/spec_helper.rb
|
16
|
+
require "response_code_matchers"
|
17
|
+
|
18
|
+
RSpec.configure do |config|
|
19
|
+
config.include ResponseCodeMatchers
|
20
|
+
end
|
21
|
+
```
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
# spec/controllers/blogs_controller.rb
|
25
|
+
describe BlogsController do
|
26
|
+
describe "#create" do
|
27
|
+
subject do
|
28
|
+
post :create, params
|
29
|
+
end
|
30
|
+
|
31
|
+
let(:params) do
|
32
|
+
{ :title => "title", :body => "body", :token => "token", :user_id => 1 }
|
33
|
+
end
|
34
|
+
|
35
|
+
# 201
|
36
|
+
context "with valid token" do
|
37
|
+
it { should be_created }
|
38
|
+
end
|
39
|
+
|
40
|
+
# 400
|
41
|
+
context "without user_id" do
|
42
|
+
before do
|
43
|
+
params.delete(:user_id)
|
44
|
+
end
|
45
|
+
|
46
|
+
it { should be_bad_request }
|
47
|
+
end
|
48
|
+
|
49
|
+
# 401
|
50
|
+
context "with invalid token" do
|
51
|
+
before do
|
52
|
+
params[:token] = "invalid"
|
53
|
+
end
|
54
|
+
|
55
|
+
it { should be_unauthorized }
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
```
|
60
|
+
|
61
|
+
|
62
|
+
## Matchers
|
63
|
+
```ruby
|
64
|
+
100: response.should be_continue
|
65
|
+
101: response.should be_switching_protocols
|
66
|
+
102: response.should be_processing
|
67
|
+
200: response.should be_ok
|
68
|
+
201: response.should be_created
|
69
|
+
202: response.should be_accepted
|
70
|
+
203: response.should be_non_authoritative_information
|
71
|
+
204: response.should be_no_content
|
72
|
+
205: response.should be_reset_content
|
73
|
+
206: response.should be_partial_content
|
74
|
+
207: response.should be_multi_status
|
75
|
+
226: response.should be_im_used
|
76
|
+
300: response.should be_multiple_choices
|
77
|
+
301: response.should be_moved_permanently
|
78
|
+
302: response.should be_found
|
79
|
+
303: response.should be_see_other
|
80
|
+
304: response.should be_not_modified
|
81
|
+
305: response.should be_use_proxy
|
82
|
+
306: response.should be_reserved
|
83
|
+
307: response.should be_temporary_redirect
|
84
|
+
400: response.should be_bad_request
|
85
|
+
401: response.should be_unauthorized
|
86
|
+
402: response.should be_payment_required
|
87
|
+
403: response.should be_forbidden
|
88
|
+
404: response.should be_not_found
|
89
|
+
405: response.should be_method_not_allowed
|
90
|
+
406: response.should be_not_acceptable
|
91
|
+
407: response.should be_proxy_authentication_required
|
92
|
+
408: response.should be_request_timeout
|
93
|
+
409: response.should be_conflict
|
94
|
+
410: response.should be_gone
|
95
|
+
411: response.should be_length_required
|
96
|
+
412: response.should be_precondition_failed
|
97
|
+
413: response.should be_request_entity_too_large
|
98
|
+
414: response.should be_request_uri_too_long
|
99
|
+
415: response.should be_unsupported_media_type
|
100
|
+
416: response.should be_requested_range_not_satisfiable
|
101
|
+
417: response.should be_expectation_failed
|
102
|
+
418: response.should be_im_a_teapot
|
103
|
+
422: response.should be_unprocessable_entity
|
104
|
+
423: response.should be_locked
|
105
|
+
424: response.should be_failed_dependency
|
106
|
+
426: response.should be_upgrade_required
|
107
|
+
500: response.should be_internal_server_error
|
108
|
+
501: response.should be_not_implemented
|
109
|
+
502: response.should be_bad_gateway
|
110
|
+
503: response.should be_service_unavailable
|
111
|
+
504: response.should be_gateway_timeout
|
112
|
+
505: response.should be_http_version_not_supported
|
113
|
+
506: response.should be_variant_also_negotiates
|
114
|
+
507: response.should be_insufficient_storage
|
115
|
+
510: response.should be_not_extended
|
116
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require "response_code_matchers/version"
|
2
|
+
require "rack"
|
3
|
+
|
4
|
+
module ResponseCodeMatchers
|
5
|
+
Rack::Utils::SYMBOL_TO_STATUS_CODE.each do |name, code|
|
6
|
+
name = name.to_s.gsub("'", "")
|
7
|
+
define_method("be_#{name}") do
|
8
|
+
ResponseCodeMatcher.new(code.to_s, name)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class ResponseCodeMatcher
|
13
|
+
def initialize(expected, name)
|
14
|
+
@expected = expected
|
15
|
+
@description = name.to_s.gsub("_", " ")
|
16
|
+
end
|
17
|
+
|
18
|
+
def matches?(response)
|
19
|
+
@actual = response.code
|
20
|
+
@actual == @expected
|
21
|
+
end
|
22
|
+
|
23
|
+
def description
|
24
|
+
"be #@description"
|
25
|
+
end
|
26
|
+
|
27
|
+
def failure_message
|
28
|
+
"expected response code to be #@expected, but #@actual"
|
29
|
+
end
|
30
|
+
|
31
|
+
def negative_failure_message
|
32
|
+
"expected response code not to be #@expected, but #@actual"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'response_code_matchers/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "response_code_matchers"
|
8
|
+
gem.version = ResponseCodeMatchers::VERSION
|
9
|
+
gem.authors = ["Ryo NAKAMURA"]
|
10
|
+
gem.email = ["r7kamura@gmail.com"]
|
11
|
+
gem.description = "Provide rspec matchers to match http response code"
|
12
|
+
gem.summary = "RSpec utility matchers for http response code"
|
13
|
+
gem.homepage = "https://github.com/r7kamura/response_code_matchers"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_dependency "rack"
|
21
|
+
gem.add_development_dependency "rspec"
|
22
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe ResponseCodeMatchers do
|
4
|
+
%w[
|
5
|
+
100 be_continue
|
6
|
+
101 be_switching_protocols
|
7
|
+
102 be_processing
|
8
|
+
200 be_ok
|
9
|
+
201 be_created
|
10
|
+
202 be_accepted
|
11
|
+
203 be_non_authoritative_information
|
12
|
+
204 be_no_content
|
13
|
+
205 be_reset_content
|
14
|
+
206 be_partial_content
|
15
|
+
207 be_multi_status
|
16
|
+
226 be_im_used
|
17
|
+
300 be_multiple_choices
|
18
|
+
301 be_moved_permanently
|
19
|
+
302 be_found
|
20
|
+
303 be_see_other
|
21
|
+
304 be_not_modified
|
22
|
+
305 be_use_proxy
|
23
|
+
306 be_reserved
|
24
|
+
307 be_temporary_redirect
|
25
|
+
400 be_bad_request
|
26
|
+
401 be_unauthorized
|
27
|
+
402 be_payment_required
|
28
|
+
403 be_forbidden
|
29
|
+
404 be_not_found
|
30
|
+
405 be_method_not_allowed
|
31
|
+
406 be_not_acceptable
|
32
|
+
407 be_proxy_authentication_required
|
33
|
+
408 be_request_timeout
|
34
|
+
409 be_conflict
|
35
|
+
410 be_gone
|
36
|
+
411 be_length_required
|
37
|
+
412 be_precondition_failed
|
38
|
+
413 be_request_entity_too_large
|
39
|
+
414 be_request_uri_too_long
|
40
|
+
415 be_unsupported_media_type
|
41
|
+
416 be_requested_range_not_satisfiable
|
42
|
+
417 be_expectation_failed
|
43
|
+
418 be_im_a_teapot
|
44
|
+
422 be_unprocessable_entity
|
45
|
+
423 be_locked
|
46
|
+
424 be_failed_dependency
|
47
|
+
426 be_upgrade_required
|
48
|
+
500 be_internal_server_error
|
49
|
+
501 be_not_implemented
|
50
|
+
502 be_bad_gateway
|
51
|
+
503 be_service_unavailable
|
52
|
+
504 be_gateway_timeout
|
53
|
+
505 be_http_version_not_supported
|
54
|
+
506 be_variant_also_negotiates
|
55
|
+
507 be_insufficient_storage
|
56
|
+
510 be_not_extended
|
57
|
+
].each_slice(2) do |code, matcher|
|
58
|
+
describe "##{matcher}" do
|
59
|
+
let(:response) do
|
60
|
+
mock(:code => code)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "matches http response code #{code}" do
|
64
|
+
response.should send(matcher)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: response_code_matchers
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Ryo NAKAMURA
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-11-28 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rack
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: rspec
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
hash: 3
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
version: "0"
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id002
|
48
|
+
description: Provide rspec matchers to match http response code
|
49
|
+
email:
|
50
|
+
- r7kamura@gmail.com
|
51
|
+
executables: []
|
52
|
+
|
53
|
+
extensions: []
|
54
|
+
|
55
|
+
extra_rdoc_files: []
|
56
|
+
|
57
|
+
files:
|
58
|
+
- .gitignore
|
59
|
+
- Gemfile
|
60
|
+
- LICENSE.txt
|
61
|
+
- README.md
|
62
|
+
- Rakefile
|
63
|
+
- lib/response_code_matchers.rb
|
64
|
+
- lib/response_code_matchers/version.rb
|
65
|
+
- response_code_matchers.gemspec
|
66
|
+
- spec/response_code_matchers_spec.rb
|
67
|
+
- spec/spec_helper.rb
|
68
|
+
homepage: https://github.com/r7kamura/response_code_matchers
|
69
|
+
licenses: []
|
70
|
+
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options: []
|
73
|
+
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
hash: 3
|
82
|
+
segments:
|
83
|
+
- 0
|
84
|
+
version: "0"
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
hash: 3
|
91
|
+
segments:
|
92
|
+
- 0
|
93
|
+
version: "0"
|
94
|
+
requirements: []
|
95
|
+
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 1.8.24
|
98
|
+
signing_key:
|
99
|
+
specification_version: 3
|
100
|
+
summary: RSpec utility matchers for http response code
|
101
|
+
test_files:
|
102
|
+
- spec/response_code_matchers_spec.rb
|
103
|
+
- spec/spec_helper.rb
|