rspec-api-matchers 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +30 -0
- data/lib/rspec-api-matchers.rb +1 -0
- data/lib/rspec-api/matchers.rb +3 -0
- data/lib/rspec-api/matchers/match_status.rb +60 -0
- data/lib/rspec-api/matchers/matchers.rb +26 -0
- data/lib/rspec-api/matchers/version.rb +5 -0
- metadata +122 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 79c751c1af951762a1fe11184842ac7959b4e43a
|
4
|
+
data.tar.gz: c7b91641ccb763315b14cc0e2eadf2e4651a5fe8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ce34b69d0059e0a5af071de68fe64340066b726c984c71f86213edb1ca6995d7250a97b28b3c081572325fd91af6e1dbb4418db310362bb87b7dbcb05a19d731
|
7
|
+
data.tar.gz: 23abd33b373b5bbd6676a5a9ae10d6a1ae7c97b228ec182c250c81cae0c14d8bc8f173e4909c663883536fb4809baf257c9cb1661b6d8f0dbc971d7f141c9012
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2013 claudiob
|
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.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
RSpec API Matchers
|
2
|
+
==================
|
3
|
+
|
4
|
+
RSpecApi::Matchers lets you express outcomes on the response of web APIs.
|
5
|
+
|
6
|
+
expect(404).to match_status(:not_found)
|
7
|
+
|
8
|
+
More documentation and examples about RSpec Api are available at [http://rspec-api.github.io](http://rspec-api.github.io)
|
9
|
+
|
10
|
+
[![Build Status](https://travis-ci.org/rspec-api/rspec-api-matchers.png)](https://travis-ci.org/rspec-api/rspec-api-matchers)
|
11
|
+
[![Code Climate](https://codeclimate.com/github/rspec-api/rspec-api-matchers.png)](https://codeclimate.com/github/rspec-api/rspec-api-matchers)
|
12
|
+
[![Coverage Status](https://coveralls.io/repos/rspec-api/rspec-api-matchers/badge.png)](https://coveralls.io/r/rspec-api/rspec-api-matchers)
|
13
|
+
[![Dependency Status](https://gemnasium.com/rspec-api/rspec-api-matchers.png)](https://gemnasium.com/rspec-api/rspec-api-matchers)
|
14
|
+
|
15
|
+
Install
|
16
|
+
-------
|
17
|
+
|
18
|
+
Add `gem 'rspec-api-matchers'` to your `Gemfile` and run `bundle`.
|
19
|
+
Or install yourself by running `gem install rspec-api-matchers`.
|
20
|
+
|
21
|
+
Available matchers
|
22
|
+
------------------
|
23
|
+
|
24
|
+
expect(http_status_code).to match_status(http_status)
|
25
|
+
|
26
|
+
How to contribute
|
27
|
+
=================
|
28
|
+
|
29
|
+
Don’t hesitate to send me code comments, issues or pull requests through GitHub!
|
30
|
+
All feedback is appreciated. Thanks :)
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'rspec-api/matchers'
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'rack/utils'
|
2
|
+
|
3
|
+
module RSpecApi
|
4
|
+
module Matchers
|
5
|
+
class MatchStatus
|
6
|
+
def initialize(expected_status)
|
7
|
+
@expected_status = expected_status
|
8
|
+
end
|
9
|
+
|
10
|
+
def matches?(actual_code)
|
11
|
+
@actual_code = actual_code
|
12
|
+
actual_code == expected_code
|
13
|
+
end
|
14
|
+
alias == matches?
|
15
|
+
|
16
|
+
def failure_message_for_should
|
17
|
+
"expected #{@actual_code} to #{description}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def failure_message_for_should_not
|
21
|
+
"expected #{@actual_code} not to #{description}"
|
22
|
+
end
|
23
|
+
|
24
|
+
def description
|
25
|
+
"be #{@expected_status}"
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def expected_code
|
31
|
+
status_to_numeric_code @expected_status
|
32
|
+
end
|
33
|
+
|
34
|
+
# Translates an HTTP status symbol or code into the corresponding code
|
35
|
+
#
|
36
|
+
# @example
|
37
|
+
# status_to_code(:ok) # => 200
|
38
|
+
# status_to_code(200) # => 200
|
39
|
+
# status_to_code(987) # => raise
|
40
|
+
def status_to_numeric_code(status)
|
41
|
+
code = status.is_a?(Symbol) ? Rack::Utils.status_code(status) : status
|
42
|
+
validate_status_code! code
|
43
|
+
code
|
44
|
+
end
|
45
|
+
|
46
|
+
# Raises an exception if +numeric_code+ is not a valid HTTP status code
|
47
|
+
#
|
48
|
+
# @example
|
49
|
+
# validate_status_code!(200) # => (no error)
|
50
|
+
# validate_status_code!(999) # => raise
|
51
|
+
def validate_status_code!(code)
|
52
|
+
valid_codes = Rack::Utils::SYMBOL_TO_STATUS_CODE.values
|
53
|
+
message = "#{code} must be a valid HTTP status code: #{valid_codes}"
|
54
|
+
unless valid_codes.include? code
|
55
|
+
raise ArgumentError, message
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rspec/matchers'
|
2
|
+
|
3
|
+
module RSpecApi
|
4
|
+
module Matchers
|
5
|
+
# Passes if receiver is the same HTTP status code as the argument.
|
6
|
+
# The receiver can either be in a symbolic or numeric form.
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
#
|
10
|
+
# # Passes if 200 corresponds to 200
|
11
|
+
# expect(200).to match_status(200)
|
12
|
+
#
|
13
|
+
# # Passes if :ok corresponds to :ok
|
14
|
+
# expect(:ok).to match_status(200)
|
15
|
+
def match_status(expected_status)
|
16
|
+
RSpecApi::Matchers::MatchStatus.new(expected_status)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
module RSpec
|
22
|
+
module Matchers
|
23
|
+
# Make RSpecApi::Matchers available inside RSpec
|
24
|
+
include ::RSpecApi::Matchers
|
25
|
+
end
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspec-api-matchers
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- claudiob
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-10-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rack
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: coveralls
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: RSpec matchers useful to test web APIs.
|
84
|
+
email:
|
85
|
+
- claudiob@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- lib/rspec-api/matchers/match_status.rb
|
91
|
+
- lib/rspec-api/matchers/matchers.rb
|
92
|
+
- lib/rspec-api/matchers/version.rb
|
93
|
+
- lib/rspec-api/matchers.rb
|
94
|
+
- lib/rspec-api-matchers.rb
|
95
|
+
- MIT-LICENSE
|
96
|
+
- README.md
|
97
|
+
homepage: https://github.com/rspec-api/rspec-api-matchers
|
98
|
+
licenses:
|
99
|
+
- MIT
|
100
|
+
metadata: {}
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options: []
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 1.9.3
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - '>='
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: 1.3.6
|
115
|
+
requirements: []
|
116
|
+
rubyforge_project:
|
117
|
+
rubygems_version: 2.1.10
|
118
|
+
signing_key:
|
119
|
+
specification_version: 4
|
120
|
+
summary: Methods extracted from rspec-api to chech validity of the response of pragmatic
|
121
|
+
RESTful web APIs.
|
122
|
+
test_files: []
|