rspec-http 0.9.0 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +7 -1
- data/Gemfile +2 -1
- data/README.rdoc +2 -2
- data/Rakefile +4 -1
- data/lib/rspec/http/header_matchers.rb +2 -2
- data/lib/rspec/http/response_code_matcher.rb +4 -4
- data/lib/rspec/http/version.rb +1 -1
- data/spec/rspec/http/header_matchers_spec.rb +17 -17
- data/spec/rspec/http/response_code_matchers_spec.rb +11 -17
- metadata +11 -7
data/CHANGELOG
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
== 0.10.0
|
2
|
+
|
3
|
+
* RSpec::Matchers::MatcherError used is removed from RSpec
|
4
|
+
(https://github.com/rspec/rspec-expectations/commit/e031971317884815f2397c70ee9b02e467d0ef3c)
|
5
|
+
* Support for Rake::MockResponse which does not have method code
|
6
|
+
|
1
7
|
== 0.0.1
|
2
8
|
|
3
|
-
* Matchers for HTTP response codes
|
9
|
+
* Matchers for HTTP response codes
|
data/Gemfile
CHANGED
@@ -4,9 +4,10 @@ gem "rack", "~> 1.0"
|
|
4
4
|
gem "ruby-debug", :platforms => [:ruby_18, :jruby]
|
5
5
|
gem "ruby-debug19", :platforms => :ruby_19
|
6
6
|
gem "rcov", :platforms => :ruby_18
|
7
|
+
gem "rake", "~> 0.9.2"
|
7
8
|
|
8
9
|
platforms :jruby do
|
9
10
|
gem "jruby-openssl"
|
10
11
|
end
|
11
12
|
|
12
|
-
gemspec
|
13
|
+
gemspec
|
data/README.rdoc
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
= RSpec HTTP 0.
|
1
|
+
= RSpec HTTP 0.10.0
|
2
2
|
|
3
3
|
(c) Copyright 2010-2011 {C42 Engineering}[http://c42.in]. All Rights Reserved.
|
4
4
|
|
5
|
-
RSpec HTTP is a RSpec extension library that adds support for writing specs that cover HTTP based
|
5
|
+
RSpec HTTP is a RSpec extension library that adds support for writing specs that cover HTTP based APIs (or more popularly, RESTful APIs).
|
6
6
|
|
7
7
|
To use this library, first add the rspec-http gem to your Gemfile like so:
|
8
8
|
gem 'rspec-http', '~> 0.9'
|
data/Rakefile
CHANGED
@@ -1,11 +1,14 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
1
2
|
require "bundler"
|
2
3
|
Bundler.setup
|
3
4
|
|
5
|
+
require 'rake/dsl_definition'
|
4
6
|
require 'rspec/core/rake_task'
|
5
7
|
|
8
|
+
|
6
9
|
desc "Run all examples"
|
7
10
|
RSpec::Core::RakeTask.new(:spec) do |t|
|
8
11
|
t.rspec_opts = %w[--color]
|
9
12
|
end
|
10
13
|
|
11
|
-
task :default => :spec
|
14
|
+
task :default => :spec
|
@@ -14,7 +14,7 @@ module RSpec
|
|
14
14
|
when String then HeaderStringMatcher.new(header, expected_value)
|
15
15
|
when Regexp then HeaderRegexpMatcher.new(header, expected_value)
|
16
16
|
when NO_VALUE then HeaderPresenceMatcher.new(header)
|
17
|
-
else raise
|
17
|
+
else raise SyntaxError.new("The value for a header should be either a String or a Regexp and not of type #{expected_value.class}")
|
18
18
|
end
|
19
19
|
else
|
20
20
|
@matcher = HeaderPresenceMatcher.new(header)
|
@@ -115,4 +115,4 @@ module RSpec
|
|
115
115
|
end
|
116
116
|
end
|
117
117
|
end
|
118
|
-
end
|
118
|
+
end
|
@@ -7,7 +7,7 @@ module RSpec
|
|
7
7
|
|
8
8
|
def matches?(target)
|
9
9
|
@target = target
|
10
|
-
@target.
|
10
|
+
@target.status == @expected_code
|
11
11
|
end
|
12
12
|
|
13
13
|
def description
|
@@ -23,12 +23,12 @@ module RSpec
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def common_message
|
26
|
-
message = "have a response code of #{@expected_code}, but got #{@target.
|
27
|
-
if @target.
|
26
|
+
message = "have a response code of #{@expected_code}, but got #{@target.status}"
|
27
|
+
if @target.status == 302 || @target.status == 201
|
28
28
|
message += " with a location of #{@target['Location'] || @target['location']}"
|
29
29
|
end
|
30
30
|
message
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
34
|
-
end
|
34
|
+
end
|
data/lib/rspec/http/version.rb
CHANGED
@@ -4,16 +4,16 @@ module RSpec::Http
|
|
4
4
|
describe HeaderMatchers do
|
5
5
|
let(:response) { Rack::Response.new }
|
6
6
|
before(:each) { response["Content-Type"] = "text/plain"}
|
7
|
-
|
7
|
+
|
8
8
|
context "checking for the presence of a header" do
|
9
9
|
it "passes if the header is set" do
|
10
10
|
response.should have_header("Content-Type")
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
it "fails if the header is not set" do
|
14
14
|
response.should_not have_header("Foobar")
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
it "returns an appropriate failure message in the positive case" do
|
18
18
|
lambda {
|
19
19
|
response.should have_header("Foobar")
|
@@ -25,7 +25,7 @@ module RSpec::Http
|
|
25
25
|
response.should_not have_header("Content-Type")
|
26
26
|
}.should fail_with("The header 'Content-Type' should not have been found, but it was and it has a value of 'text/plain'")
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
it "should be case insensitive" do
|
30
30
|
response.should have_header("Content-Type")
|
31
31
|
response.should have_header("content-type")
|
@@ -33,17 +33,17 @@ module RSpec::Http
|
|
33
33
|
response.should have_header("CONTENT-TYPE")
|
34
34
|
end
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
context "checking the value of the header" do
|
38
38
|
it "passes if the value is set correctly" do
|
39
39
|
response.should have_header("Content-Type" => "text/plain")
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
context "incorrect value" do
|
43
43
|
it "fails if the value is incorrect" do
|
44
44
|
response.should_not have_header("Content-Type" => "text/csv")
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
it "returns an appropriate failure message in the positive case" do
|
48
48
|
lambda {
|
49
49
|
response.should have_header("Content-Type" => "text/csv")
|
@@ -56,12 +56,12 @@ module RSpec::Http
|
|
56
56
|
}.should fail_with("Expected the response header 'Content-Type' to have a value that is not 'text/plain'")
|
57
57
|
end
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
context "missing header" do
|
61
61
|
it "fails if the header is missing" do
|
62
62
|
response.should_not have_header("Foobar" => "text/csv")
|
63
63
|
end
|
64
|
-
|
64
|
+
|
65
65
|
it "returns an appropriate failure message in the positive case" do
|
66
66
|
lambda {
|
67
67
|
response.should have_header("Foobar" => "text/csv")
|
@@ -69,17 +69,17 @@ module RSpec::Http
|
|
69
69
|
end
|
70
70
|
end
|
71
71
|
end
|
72
|
-
|
72
|
+
|
73
73
|
context "comparing the value to a regex" do
|
74
74
|
it "passes if the value is set correctly" do
|
75
75
|
response.should have_header("Content-Type" => /plain/)
|
76
76
|
end
|
77
|
-
|
77
|
+
|
78
78
|
context "incorrect value" do
|
79
79
|
it "fails if the value is incorrect" do
|
80
80
|
response.should_not have_header("Content-Type" => /csv/)
|
81
81
|
end
|
82
|
-
|
82
|
+
|
83
83
|
it "returns an appropriate failure message in the positive case" do
|
84
84
|
lambda {
|
85
85
|
response.should have_header("Content-Type" => /csv/)
|
@@ -92,24 +92,24 @@ module RSpec::Http
|
|
92
92
|
}.should fail_with("Expected the response header 'Content-Type' to have a value that does not match /plain/ but it was 'text/plain'")
|
93
93
|
end
|
94
94
|
end
|
95
|
-
|
95
|
+
|
96
96
|
context "missing header" do
|
97
97
|
it "fails if the header is missing" do
|
98
98
|
response.should_not have_header("Foobar" => /csv/)
|
99
99
|
end
|
100
|
-
|
100
|
+
|
101
101
|
it "returns an appropriate failure message in the positive case" do
|
102
102
|
lambda {
|
103
103
|
response.should have_header("Foobar" => "text/csv")
|
104
104
|
}.should fail_with("The header 'Foobar' was not found")
|
105
105
|
end
|
106
106
|
end
|
107
|
-
|
107
|
+
|
108
108
|
it "fails if the value is something other than a String or Regexp" do
|
109
109
|
lambda {
|
110
110
|
response.should have_header("Content-Type" => [])
|
111
|
-
}.should raise_error(
|
111
|
+
}.should raise_error(SyntaxError, 'The value for a header should be either a String or a Regexp and not of type Array')
|
112
112
|
end
|
113
113
|
end
|
114
114
|
end
|
115
|
-
end
|
115
|
+
end
|
@@ -4,54 +4,48 @@ module RSpec::Http
|
|
4
4
|
describe ResponseCodeMatchers do
|
5
5
|
include ResponseCodeMatchers
|
6
6
|
|
7
|
-
let(:response) { mock('HTTP Response') }
|
8
|
-
|
9
7
|
context 'status to matcher conversion' do
|
10
8
|
it "replaces spaces with underscores" do
|
11
9
|
StatusCodes.clean_up_status("Method Not Allowed").should eq(:method_not_allowed)
|
12
10
|
end
|
13
|
-
|
11
|
+
|
14
12
|
it "downcases capital letters" do
|
15
13
|
StatusCodes.clean_up_status("IM Used").should eq(:im_used)
|
16
14
|
end
|
17
|
-
|
15
|
+
|
18
16
|
it "removes apostrophes" do
|
19
17
|
StatusCodes.clean_up_status("I'm A Teapot").should eq(:im_a_teapot)
|
20
18
|
end
|
21
|
-
|
19
|
+
|
22
20
|
it "replaces hyphens with underscores" do
|
23
21
|
StatusCodes.clean_up_status("Non-Authoritative Information").should eq(:non_authoritative_information)
|
24
22
|
end
|
25
23
|
end
|
26
|
-
|
24
|
+
|
27
25
|
context "matching codes" do
|
28
26
|
StatusCodes.values.each do |code, status|
|
29
27
|
it "understands if a response is of type #{status}" do
|
30
|
-
response.
|
28
|
+
response = Rack::MockResponse.new(code, {}, "")
|
31
29
|
response.should send("be_http_#{StatusCodes.as_valid_method_name(code)}")
|
32
30
|
end
|
33
|
-
|
31
|
+
|
34
32
|
it "understands if a response is not of type #{status}" do
|
35
|
-
response.
|
33
|
+
response = Rack::MockResponse.new(0, {}, "")
|
36
34
|
response.should_not send("be_http_#{StatusCodes.as_valid_method_name(code)}")
|
37
35
|
end
|
38
36
|
end
|
39
|
-
|
37
|
+
|
40
38
|
context "where the value of the location header field can be important" do
|
41
|
-
before :each do
|
42
|
-
response.stub(:[]).with('Location').and_return('http://test.server')
|
43
|
-
end
|
44
|
-
|
45
39
|
it "response of type created" do
|
46
|
-
response.
|
40
|
+
response = Rack::MockResponse.new(201, {"Location" => "http://test.server"}, "")
|
47
41
|
expect{ response.should be_http_ok }.to raise_error(/with a location of http:\/\/test\.server$/)
|
48
42
|
end
|
49
43
|
|
50
44
|
it "response of type redirect" do
|
51
|
-
response.
|
45
|
+
response = Rack::MockResponse.new(302, {"Location" => "http://test.server"}, "")
|
52
46
|
expect{ response.should be_http_ok }.to raise_error(/with a location of http:\/\/test\.server$/)
|
53
47
|
end
|
54
48
|
end
|
55
49
|
end
|
56
50
|
end
|
57
|
-
end
|
51
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-http
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,12 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
14
|
-
default_executable:
|
13
|
+
date: 2012-05-09 00:00:00.000000000Z
|
15
14
|
dependencies:
|
16
15
|
- !ruby/object:Gem::Dependency
|
17
16
|
name: rspec
|
18
|
-
requirement: &
|
17
|
+
requirement: &70143901345000 !ruby/object:Gem::Requirement
|
19
18
|
none: false
|
20
19
|
requirements:
|
21
20
|
- - ~>
|
@@ -23,7 +22,7 @@ dependencies:
|
|
23
22
|
version: '2.0'
|
24
23
|
type: :runtime
|
25
24
|
prerelease: false
|
26
|
-
version_requirements: *
|
25
|
+
version_requirements: *70143901345000
|
27
26
|
description: RSpec HTTP is an extension library that makes it easier to write specs
|
28
27
|
for HTTP/REST APIs
|
29
28
|
email: ckponnappa@gmail.com
|
@@ -51,7 +50,6 @@ files:
|
|
51
50
|
- spec/rspec/http/response_code_matchers_spec.rb
|
52
51
|
- spec/spec_helper.rb
|
53
52
|
- spec/support/matchers.rb
|
54
|
-
has_rdoc: true
|
55
53
|
homepage: http://c42.in/open_source
|
56
54
|
licenses: []
|
57
55
|
post_install_message:
|
@@ -65,15 +63,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
65
63
|
- - ! '>='
|
66
64
|
- !ruby/object:Gem::Version
|
67
65
|
version: '0'
|
66
|
+
segments:
|
67
|
+
- 0
|
68
|
+
hash: -941351284999052965
|
68
69
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
70
|
none: false
|
70
71
|
requirements:
|
71
72
|
- - ! '>='
|
72
73
|
- !ruby/object:Gem::Version
|
73
74
|
version: '0'
|
75
|
+
segments:
|
76
|
+
- 0
|
77
|
+
hash: -941351284999052965
|
74
78
|
requirements: []
|
75
79
|
rubyforge_project:
|
76
|
-
rubygems_version: 1.
|
80
|
+
rubygems_version: 1.8.10
|
77
81
|
signing_key:
|
78
82
|
specification_version: 3
|
79
83
|
summary: RSpec HTTP is an extension library that makes it easier to write specs for
|