httpfiesta 0.0.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.
- checksums.yaml +7 -0
- data/.gitignore +24 -0
- data/.rspec +1 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +7 -0
- data/httpfiesta.gemspec +29 -0
- data/lib/httpfiesta/assertion.rb +59 -0
- data/lib/httpfiesta/unacceptable_response_error.rb +14 -0
- data/lib/httpfiesta/version.rb +3 -0
- data/lib/httpfiesta.rb +14 -0
- data/spec/helper.rb +13 -0
- data/spec/lib/assertion_spec.rb +94 -0
- data/spec/lib/monkeypatch_spec.rb +15 -0
- metadata +163 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f81ee99aeb3835583c3ea649a0824cd94ef7f4d1
|
4
|
+
data.tar.gz: 82d91c31530e142731df9c74d8807bfcbe2fb395
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 43565b86656986e8752643d0ed4d8251cff6c0102a7ddd9a3674d0fec2bf3f96f52d7e0a2ae0585f1430e3a7cf698e78a01de93086d4821e7fee31905bb5d33d
|
7
|
+
data.tar.gz: a43e98369e12616dfbb1a7e224b55486bfa332a15b3aee503cc96b83bb2bf17dd0c87bbfba42ba4bd9e65b5a236f3c2ce82c1c3633abf0142ef8b2fb51af9614
|
data/.gitignore
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
23
|
+
|
24
|
+
.idea
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Christopher Thornton
|
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,29 @@
|
|
1
|
+
# Httpfiesta
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'httpfiesta'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install httpfiesta
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( https://github.com/[my-github-username]/httpfiesta/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/httpfiesta.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'httpfiesta/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'httpfiesta'
|
8
|
+
spec.version = HTTPFiesta::VERSION
|
9
|
+
spec.authors = ['Christopher Thornton', 'Ben Radler']
|
10
|
+
spec.email = ['rmdirbin@gmail.com', 'ben@benradler.com']
|
11
|
+
spec.summary = %q{Makes verifying your HTTParty responses easier!}
|
12
|
+
spec.description = %q{Adds some extra utilities to make verifying your HTTParty responses more convienent and fun}
|
13
|
+
spec.homepage = 'https://github.com/cgthornt/httpfiesta'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
23
|
+
spec.add_development_dependency 'rake'
|
24
|
+
spec.add_development_dependency 'rspec', '~> 3.0.0'
|
25
|
+
spec.add_development_dependency 'webmock'
|
26
|
+
spec.add_development_dependency 'pry'
|
27
|
+
spec.add_development_dependency 'json'
|
28
|
+
spec.add_development_dependency 'httparty'
|
29
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'httpfiesta/unacceptable_response_error'
|
2
|
+
|
3
|
+
module HTTPFiesta
|
4
|
+
class Assertion
|
5
|
+
attr_reader :response
|
6
|
+
|
7
|
+
CONTENT_TYPE_MAP = {
|
8
|
+
json: 'application/json',
|
9
|
+
xml: 'text/xml',
|
10
|
+
html: 'text/html'
|
11
|
+
}
|
12
|
+
|
13
|
+
def initialize(response)
|
14
|
+
@response = response
|
15
|
+
end
|
16
|
+
|
17
|
+
def status(*ranges_or_codes)
|
18
|
+
ranges = ranges_or_codes.map do |range_or_code|
|
19
|
+
range = range_or_code.is_a?(Range) ? range_or_code : range_or_code..range_or_code
|
20
|
+
return self if range.include?(response.code.to_i)
|
21
|
+
range
|
22
|
+
end
|
23
|
+
|
24
|
+
# If we're here, then error
|
25
|
+
description = ranges.map(&:to_s).join(', ')
|
26
|
+
error "status code '#{response.code}' not in allowable range: #{description}"
|
27
|
+
end
|
28
|
+
|
29
|
+
alias_method :code, :status
|
30
|
+
|
31
|
+
def content_type(type)
|
32
|
+
raise ArgumentError, 'type cannot be nil' if type.nil?
|
33
|
+
if type.is_a?(Symbol)
|
34
|
+
if CONTENT_TYPE_MAP.key?(type)
|
35
|
+
type = CONTENT_TYPE_MAP[type]
|
36
|
+
else
|
37
|
+
raise ArgumentError, "Unallowed content-type symbol :#{type}, valid symbols: #{CONTENT_TYPE_MAP.keys.join ', '}"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
raise ArgumentError, 'type must be a String or Symbol' unless type.is_a?(String)
|
41
|
+
|
42
|
+
|
43
|
+
mime = response.headers['Content-Type']
|
44
|
+
error 'Content-Type header not present' if mime.nil?
|
45
|
+
if mime.downcase.include?(type.to_s)
|
46
|
+
self
|
47
|
+
else
|
48
|
+
error "response content type '#{mime}' does not match expected type of '#{type}'"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
alias_method :content, :content_type
|
52
|
+
|
53
|
+
protected
|
54
|
+
|
55
|
+
def error(message)
|
56
|
+
raise UnacceptableResponseError.new(message, response)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module HTTPFiesta
|
2
|
+
class UnacceptableResponseError < StandardError
|
3
|
+
attr_reader :response
|
4
|
+
|
5
|
+
def initialize(message, response)
|
6
|
+
super(message)
|
7
|
+
@response = response
|
8
|
+
end
|
9
|
+
|
10
|
+
def message
|
11
|
+
"HTTP #{response.request.method.upcase} #{response.request.path} : #{super}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/httpfiesta.rb
ADDED
data/spec/helper.rb
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe HTTPFiesta::Assertion do
|
4
|
+
let(:status_code) { 200 }
|
5
|
+
let(:content_type) { 'application/json' }
|
6
|
+
let(:return_body) { { 'hello' => 'world'}.to_json }
|
7
|
+
|
8
|
+
let(:response) { HTTParty.get 'http://example.com' }
|
9
|
+
before do
|
10
|
+
stub_request(:any, 'http://example.com').
|
11
|
+
to_return(body: return_body, status: status_code, headers: { content_type: content_type })
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
describe '#status' do
|
16
|
+
context 'with only a single acceptable range' do
|
17
|
+
it 'allows acceptable status code' do
|
18
|
+
expect {
|
19
|
+
response.assert.status(200)
|
20
|
+
}.to_not raise_error
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'allows an acceptable status code within a range' do
|
24
|
+
expect {
|
25
|
+
response.assert.status(150..300)
|
26
|
+
}.to_not raise_error
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'does not permit unacceptable status codes' do
|
30
|
+
expect {
|
31
|
+
response.assert.status(201)
|
32
|
+
}.to raise_error(HTTPFiesta::UnacceptableResponseError)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'does not permit unacceptable status codes that are not within a range' do
|
36
|
+
expect {
|
37
|
+
response.assert.status(300..400)
|
38
|
+
}.to raise_error(HTTPFiesta::UnacceptableResponseError)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'with several acceptable ranges' do
|
43
|
+
it 'allows the response if it is within one of multiple ranges' do
|
44
|
+
expect {
|
45
|
+
response.assert.status(100..110, 190..200, 300..400)
|
46
|
+
}.to_not raise_error
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'denies the response if it is *not* within one of multiple ranges' do
|
50
|
+
expect {
|
51
|
+
response.assert.status(100..110, 190..199, 201..220, 300..400)
|
52
|
+
}.to raise_error(HTTPFiesta::UnacceptableResponseError)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'return object' do
|
57
|
+
it 'always returns itself (if successful)' do
|
58
|
+
assertion = response.assert
|
59
|
+
expect(assertion.status(200)).to eq(assertion)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe '#content_type' do
|
65
|
+
it 'allows valid content types' do
|
66
|
+
expect {
|
67
|
+
response.assert.content_type('application/json')
|
68
|
+
}.to_not raise_error
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'accepts a symbol shortcut' do
|
72
|
+
expect {
|
73
|
+
response.assert.content_type(:json)
|
74
|
+
}.to_not raise_error
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'denies an invalid content type' do
|
78
|
+
expect {
|
79
|
+
response.assert.content_type('text/xml')
|
80
|
+
}.to raise_error(HTTPFiesta::UnacceptableResponseError)
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'always returns itself' do
|
84
|
+
assertion = response.assert
|
85
|
+
expect(assertion.content_type(:json)).to eq(assertion)
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'raises an ArgumentError if it is given garbage input' do
|
89
|
+
expect {
|
90
|
+
response.assert.content_type(:asdf)
|
91
|
+
}.to raise_error(ArgumentError)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe HTTParty::Response do
|
4
|
+
before do
|
5
|
+
stub_request(:any, 'http://example.com').to_return(body: 'hello world')
|
6
|
+
end
|
7
|
+
|
8
|
+
describe '#assert' do
|
9
|
+
it 'should be monkeypatched correctly' do
|
10
|
+
response = HTTParty.get 'http://example.com'
|
11
|
+
expect(response.assert).to be_a(HTTPFiesta::Assertion)
|
12
|
+
expect(response.assert.response).to eq(response)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,163 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: httpfiesta
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Christopher Thornton
|
8
|
+
- Ben Radler
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-06-20 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.6'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.6'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rspec
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 3.0.0
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 3.0.0
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: webmock
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: pry
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: json
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: httparty
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
description: Adds some extra utilities to make verifying your HTTParty responses more
|
113
|
+
convienent and fun
|
114
|
+
email:
|
115
|
+
- rmdirbin@gmail.com
|
116
|
+
- ben@benradler.com
|
117
|
+
executables: []
|
118
|
+
extensions: []
|
119
|
+
extra_rdoc_files: []
|
120
|
+
files:
|
121
|
+
- ".gitignore"
|
122
|
+
- ".rspec"
|
123
|
+
- ".travis.yml"
|
124
|
+
- Gemfile
|
125
|
+
- LICENSE.txt
|
126
|
+
- README.md
|
127
|
+
- Rakefile
|
128
|
+
- httpfiesta.gemspec
|
129
|
+
- lib/httpfiesta.rb
|
130
|
+
- lib/httpfiesta/assertion.rb
|
131
|
+
- lib/httpfiesta/unacceptable_response_error.rb
|
132
|
+
- lib/httpfiesta/version.rb
|
133
|
+
- spec/helper.rb
|
134
|
+
- spec/lib/assertion_spec.rb
|
135
|
+
- spec/lib/monkeypatch_spec.rb
|
136
|
+
homepage: https://github.com/cgthornt/httpfiesta
|
137
|
+
licenses:
|
138
|
+
- MIT
|
139
|
+
metadata: {}
|
140
|
+
post_install_message:
|
141
|
+
rdoc_options: []
|
142
|
+
require_paths:
|
143
|
+
- lib
|
144
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - ">="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - ">="
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
154
|
+
requirements: []
|
155
|
+
rubyforge_project:
|
156
|
+
rubygems_version: 2.2.2
|
157
|
+
signing_key:
|
158
|
+
specification_version: 4
|
159
|
+
summary: Makes verifying your HTTParty responses easier!
|
160
|
+
test_files:
|
161
|
+
- spec/helper.rb
|
162
|
+
- spec/lib/assertion_spec.rb
|
163
|
+
- spec/lib/monkeypatch_spec.rb
|