httpspec_simple 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -0
- data/lib/httpspec_simple/custom_matchers.rb +18 -0
- data/lib/httpspec_simple/request.rb +4 -1
- data/lib/httpspec_simple/version.rb +1 -1
- data/spec/httpspec_simple/custom_matcher_spec.rb +25 -0
- metadata +13 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c7a4a13d7119d5d2f05affddfb927380d85f57c4
|
4
|
+
data.tar.gz: 3f71018eafd3e423a945b962d07edc8a54163ce9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70c10461277c63e4203225f5c902a6280bc85433bee02092e60b6db0c88a1ad975e023ea3087dc7903d5c6c55579aa66a219cc7d928cb15a9a716061ecb2bcd4
|
7
|
+
data.tar.gz: af985c27b460a7a61b8127f29065cd1c509220fe27492f9772453c0c6aaa405e7b13212f949bdb604d4e3a706121efe8a38ebfafde11660c6b3123e4395a2524
|
data/README.md
CHANGED
@@ -42,6 +42,18 @@ http://kozy4324.github.io/blog/archives/
|
|
42
42
|
|
43
43
|
Example passes if response is 200 ok
|
44
44
|
|
45
|
+
### be_http_redirect
|
46
|
+
|
47
|
+
Example passes if response is 301 or 302
|
48
|
+
|
49
|
+
### be_http_redirect_301_to(url)
|
50
|
+
|
51
|
+
Example passes if response is 301 and `Location` response header has a value which equals expected url
|
52
|
+
|
53
|
+
### be_http_redirect_302_to(url)
|
54
|
+
|
55
|
+
Example passes if response is 302 and `Location` response header has a value which equals expected url
|
56
|
+
|
45
57
|
### resond_within(n).seconds
|
46
58
|
|
47
59
|
Example passes if response time is less than n seconds
|
@@ -27,6 +27,24 @@ module HttpspecSimple
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
+
%w|301 302|.each do |code|
|
31
|
+
RSpec::Matchers.define "be_http_redirect_#{code}_to".to_sym do |expected|
|
32
|
+
match do |actual|
|
33
|
+
location_header = (actual.headers['location'] || []).first
|
34
|
+
actual.status == code && location_header == expected
|
35
|
+
end
|
36
|
+
|
37
|
+
failure_message_for_should do |actual|
|
38
|
+
if actual.status == '301' || actual.status == '302'
|
39
|
+
location_header = (actual.headers['location'] || []).first
|
40
|
+
"expected: #{code}, #{expected}\n got: #{actual.status}, #{location_header}"
|
41
|
+
else
|
42
|
+
"expected: #{code}, #{expected}\n got: #{actual.status}"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
30
48
|
RSpec::Matchers.define :respond_within do |expected|
|
31
49
|
match do |actual|
|
32
50
|
(@response_time = actual.response_time) < expected
|
@@ -3,7 +3,7 @@ require 'uri'
|
|
3
3
|
|
4
4
|
module HttpspecSimple
|
5
5
|
class Request
|
6
|
-
attr_reader :response_time, :status, :body
|
6
|
+
attr_reader :response_time, :status, :body, :headers
|
7
7
|
|
8
8
|
def initialize(url, opt = {})
|
9
9
|
@url = URI.parse(url)
|
@@ -30,6 +30,7 @@ module HttpspecSimple
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
@status = res ? res.code : 'timeout'
|
33
|
+
@headers = res ? res.to_hash : {}
|
33
34
|
unless res.nil?
|
34
35
|
@body = res.body
|
35
36
|
charset = (res['content-type'] || '').split(';').select{|i| i.start_with?('charset=')}.map{|i| i.sub('charset=', '')}[0]
|
@@ -78,6 +79,7 @@ module HttpspecSimple
|
|
78
79
|
def response_time; self.class.response_time; end
|
79
80
|
def status; self.class.status; end
|
80
81
|
def body; self.class.body; end
|
82
|
+
def headers; self.class.headers; end
|
81
83
|
end
|
82
84
|
class << sub
|
83
85
|
def url=(_url); @url = _url; end
|
@@ -87,6 +89,7 @@ module HttpspecSimple
|
|
87
89
|
def response_time; request.response_time; end
|
88
90
|
def status; request.status; end
|
89
91
|
def body; request.body; end
|
92
|
+
def headers; request.headers; end
|
90
93
|
end
|
91
94
|
sub.url = url
|
92
95
|
sub.opt = opt
|
@@ -34,6 +34,31 @@ describe 'custom matchers' do
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
+
describe '#be_http_redirect_30(1|2)_to' do
|
38
|
+
it "should check status code 301 with Location header" do
|
39
|
+
_, response = server_start('/' => Proc.new {|req, res|
|
40
|
+
res.status = '301'
|
41
|
+
res['Location'] = 'http://example.com/hoge'
|
42
|
+
}) do
|
43
|
+
response = request('/', :immediately => true)
|
44
|
+
end
|
45
|
+
expect {
|
46
|
+
response.should be_http_redirect_301_to 'http://example.com/hoge'
|
47
|
+
}.not_to raise_error
|
48
|
+
end
|
49
|
+
it "should check status code 302 with Location header" do
|
50
|
+
_, response = server_start('/' => Proc.new {|req, res|
|
51
|
+
res.status = '302'
|
52
|
+
res['Location'] = 'http://example.com/foo'
|
53
|
+
}) do
|
54
|
+
response = request('/', :immediately => true)
|
55
|
+
end
|
56
|
+
expect {
|
57
|
+
response.should be_http_redirect_302_to 'http://example.com/foo'
|
58
|
+
}.not_to raise_error
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
37
62
|
describe '#respond_within(num).seconds' do
|
38
63
|
it "should check response time" do
|
39
64
|
requests, response = server_start('/' => Proc.new {|req, res| sleep 2 }) do
|
metadata
CHANGED
@@ -1,55 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: httpspec_simple
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Koji NAKAMURA
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 2.14.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 2.14.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '1.3'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.3'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
description: RSpec extension for HTTP request
|
@@ -59,8 +59,8 @@ executables: []
|
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
-
- .gitignore
|
63
|
-
- .rspec
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
64
|
- Gemfile
|
65
65
|
- LICENSE.txt
|
66
66
|
- README.md
|
@@ -84,17 +84,17 @@ require_paths:
|
|
84
84
|
- lib
|
85
85
|
required_ruby_version: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
91
|
requirements:
|
92
|
-
- -
|
92
|
+
- - ">="
|
93
93
|
- !ruby/object:Gem::Version
|
94
94
|
version: '0'
|
95
95
|
requirements: []
|
96
96
|
rubyforge_project:
|
97
|
-
rubygems_version: 2.0
|
97
|
+
rubygems_version: 2.2.0
|
98
98
|
signing_key:
|
99
99
|
specification_version: 4
|
100
100
|
summary: RSpec extension for HTTP request
|