restful-matchers 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -1
- data/Gemfile +2 -2
- data/Gemfile.lock +8 -4
- data/README.md +15 -9
- data/lib/restful/matchers.rb +1 -1
- data/lib/restful/matchers/{have_restful_json_link.rb → have_link.rb} +10 -13
- data/restful-matchers.gemspec +4 -7
- data/spec/restful/matchers/{have_restful_json_link_spec.rb → have_link_spec.rb} +10 -4
- data/spec/spec_helper.rb +6 -2
- metadata +8 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa23bf113f67c1d2ebcec7749f06a5297fe44ad0
|
4
|
+
data.tar.gz: 2ef8175345a2c7abc59b4f3cc2a0f00b3bcb9bdd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e694f1dfa908ccdb0292d6f8ffb0c04ce130ee345072c7640ebed3cf2afed1993e2637bd93fb2965c8b93cfd38e76cfd7680684d3ec79c8a6f970db5efb54f4f
|
7
|
+
data.tar.gz: 23bac76446ef247fdcf053e98d65032bca1245b1d6f21b53b0d2eaaf1742bee9fe41730a4cb3a1c419c752336515642e4f673b33652164eed052d2aac92da999
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
restful-matchers (0.1)
|
4
|
+
restful-matchers (0.2.1)
|
5
5
|
rspec (~> 2.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -9,7 +9,7 @@ GEM
|
|
9
9
|
specs:
|
10
10
|
coderay (1.0.9)
|
11
11
|
diff-lcs (1.2.4)
|
12
|
-
method_source (0.8.
|
12
|
+
method_source (0.8.2)
|
13
13
|
pry (0.9.12.2)
|
14
14
|
coderay (~> 1.0.5)
|
15
15
|
method_source (~> 0.8)
|
@@ -25,7 +25,10 @@ GEM
|
|
25
25
|
rspec-expectations (2.14.2)
|
26
26
|
diff-lcs (>= 1.1.3, < 2.0)
|
27
27
|
rspec-mocks (2.14.3)
|
28
|
-
slop (3.4.
|
28
|
+
slop (3.4.6)
|
29
|
+
step-up (0.9.1)
|
30
|
+
thor (>= 0.14.6)
|
31
|
+
thor (0.18.1)
|
29
32
|
|
30
33
|
PLATFORMS
|
31
34
|
ruby
|
@@ -34,5 +37,6 @@ DEPENDENCIES
|
|
34
37
|
bundler (~> 1.0)
|
35
38
|
pry (~> 0.9)
|
36
39
|
pry-nav (~> 0.2)
|
37
|
-
rake (~> 10.
|
40
|
+
rake (~> 10.1)
|
38
41
|
restful-matchers!
|
42
|
+
step-up (~> 0.9)
|
data/README.md
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
# restful-matchers [![Build Status](https://travis-ci.org/marcoshack/restful-matchers.png?branch=master)](https://travis-ci.org/marcoshack/restful-matchers) [![Code Climate](https://codeclimate.com/github/marcoshack/restful-matchers.png)](https://codeclimate.com/github/marcoshack/restful-matchers) [![Gem Version](https://badge.fury.io/rb/restful-matchers.png)](http://badge.fury.io/rb/restful-matchers)
|
2
2
|
|
3
|
-
RSpec matchers to test RESTful HATEOAS-compliant resource links. Currently it supports only JSON representations as an array of link objects with `rel` and `href` attributes
|
3
|
+
RSpec matchers to test RESTful HATEOAS-compliant resource links. Currently it supports only JSON representations as an array of link objects with `rel` and `href` attributes.
|
4
|
+
|
5
|
+
|
6
|
+
## Usage
|
7
|
+
|
8
|
+
Given the following JSON response:
|
4
9
|
|
5
10
|
```json
|
6
11
|
{
|
@@ -12,17 +17,20 @@ RSpec matchers to test RESTful HATEOAS-compliant resource links. Currently it su
|
|
12
17
|
}
|
13
18
|
```
|
14
19
|
|
15
|
-
|
20
|
+
You can match links represented as an array of `{rel: ... , href: ...}` objects named as `links`:
|
16
21
|
|
17
22
|
```ruby
|
18
23
|
describe MyRestfulController do
|
19
24
|
render_views
|
20
25
|
|
21
|
-
it "should have
|
26
|
+
it "should have links" do
|
22
27
|
get :index
|
23
|
-
|
24
|
-
response.body.should
|
25
|
-
response.body.should
|
28
|
+
|
29
|
+
response.body.should have_link "resource1", "http://example.com/resource1"
|
30
|
+
response.body.should have_link "resource2", "http://example.com/resource1"
|
31
|
+
|
32
|
+
parsed_json = JSON.parse(response.body) # you can match both raw or parsed (hash) JSON
|
33
|
+
parsed_json.should have_link "self" # href attribute is optional
|
26
34
|
end
|
27
35
|
end
|
28
36
|
```
|
@@ -32,7 +40,5 @@ end
|
|
32
40
|
Add it to the `test` group in your Gemfile and be happy!
|
33
41
|
|
34
42
|
```ruby
|
35
|
-
group :test
|
36
|
-
gem 'restful-matchers'
|
37
|
-
end
|
43
|
+
gem 'restful-matchers', '~> 0.2', :group => :test
|
38
44
|
```
|
data/lib/restful/matchers.rb
CHANGED
@@ -7,40 +7,37 @@ module RESTful
|
|
7
7
|
# Example:
|
8
8
|
# response.body.should have_json_link("self", "http://example.com")
|
9
9
|
#
|
10
|
-
def
|
11
|
-
|
10
|
+
def have_link(rel, href = nil)
|
11
|
+
HaveLink.new(rel, href)
|
12
12
|
end
|
13
|
-
alias_method :
|
13
|
+
alias_method :have_restful_json_link, :have_link
|
14
14
|
|
15
|
-
class
|
15
|
+
class HaveLink
|
16
16
|
def initialize(rel, href = nil)
|
17
17
|
@rel = rel
|
18
18
|
@href = href
|
19
19
|
end
|
20
20
|
|
21
21
|
def matches?(content)
|
22
|
+
@content = content
|
22
23
|
if links = parse_links_from(content)
|
23
24
|
return @href ? links[@rel] == @href : links.has_key?(@rel)
|
24
25
|
else
|
25
|
-
|
26
|
+
return false
|
26
27
|
end
|
27
28
|
end
|
28
29
|
|
29
30
|
def failure_message_for_should
|
30
|
-
"Expected RESTful link
|
31
|
+
error_message "Expected RESTful link"
|
31
32
|
end
|
32
33
|
|
33
34
|
def failure_message_for_should_not
|
34
|
-
"Expected no RESTful link
|
35
|
-
end
|
36
|
-
|
37
|
-
def description
|
38
|
-
"have RESTful link: #{link_representation}"
|
35
|
+
error_message "Expected no RESTful link"
|
39
36
|
end
|
40
37
|
|
41
38
|
private
|
42
|
-
def
|
43
|
-
"{ rel: #{@rel}, href: #{@href} }"
|
39
|
+
def error_message(message)
|
40
|
+
"#{message} '{\"rel\": \"#{@rel}\", \"href\": \"#{@href || "<any>" }\"}' in '#{@content}'"
|
44
41
|
end
|
45
42
|
|
46
43
|
def parse_links_from(content)
|
data/restful-matchers.gemspec
CHANGED
@@ -2,20 +2,17 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |gem|
|
4
4
|
gem.name = "restful-matchers"
|
5
|
-
gem.version = "0.2.
|
5
|
+
gem.version = "0.2.1"
|
6
6
|
|
7
7
|
gem.authors = [ "Marcos Hack" ]
|
8
8
|
gem.email = [ "marcoshack@gmail.com" ]
|
9
|
-
gem.summary = "
|
10
|
-
gem.description = "RSpec matchers
|
11
|
-
gem.homepage = "https://github.com/marcoshack/
|
9
|
+
gem.summary = "RSpec matchers to test RESTful HATEOAS-compliant resource links."
|
10
|
+
gem.description = "RSpec matchers to test RESTful HATEOAS-compliant resource links. Currently it supports only JSON representations as an array of link objects with rel and href attributes."
|
11
|
+
gem.homepage = "https://github.com/marcoshack/restful-matchers"
|
12
12
|
gem.license = "MIT"
|
13
13
|
|
14
14
|
gem.add_dependency "rspec", "~> 2.0"
|
15
|
-
|
16
15
|
gem.add_development_dependency "bundler", "~> 1.0"
|
17
|
-
gem.add_development_dependency "pry"
|
18
|
-
gem.add_development_dependency "pry-nav"
|
19
16
|
|
20
17
|
gem.files = `git ls-files`.split($\)
|
21
18
|
gem.test_files = gem.files.grep(/^(test)/)
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe RESTful::Matchers::
|
3
|
+
describe RESTful::Matchers::HaveLink do
|
4
4
|
|
5
|
-
shared_examples_for "
|
5
|
+
shared_examples_for "Matcher" do
|
6
6
|
it "should find a json link" do
|
7
7
|
@content.should have_restful_json_link("self", "http://example.com")
|
8
8
|
@content.should have_link("self", "http://example.com")
|
@@ -20,11 +20,17 @@ describe RESTful::Matchers::HaveRestfulJsonLink do
|
|
20
20
|
|
21
21
|
context "when processing a JSON content" do
|
22
22
|
before(:each) { @content = open("spec/fixtures/json/resource.json").read }
|
23
|
-
it_behaves_like "
|
23
|
+
it_behaves_like "Matcher"
|
24
24
|
end
|
25
25
|
|
26
26
|
context "when processing a parsed JSON" do
|
27
27
|
before(:each) { @content = JSON.parse(open("spec/fixtures/json/resource.json").read) }
|
28
|
-
it_behaves_like "
|
28
|
+
it_behaves_like "Matcher"
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should show matched content on fail" do
|
32
|
+
content = '{"foo": "bar", "baz": "qux"}'
|
33
|
+
expect { content.should have_link "self" }.to raise_error(RSpec::Expectations::ExpectationNotMetError, /.*in '#{content}'.*/)
|
29
34
|
end
|
30
35
|
end
|
36
|
+
|
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
|
-
require 'restful/matchers'
|
2
|
-
|
3
1
|
PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..')).freeze
|
4
2
|
$LOAD_PATH << File.join(PROJECT_ROOT, 'lib')
|
5
3
|
|
6
4
|
Dir[File.join(PROJECT_ROOT, 'spec', 'support', '**', '*.rb')].each { |file| require(file) }
|
5
|
+
|
6
|
+
require 'rubygems'
|
7
|
+
require 'bundler/setup'
|
8
|
+
Bundler.require(:default, :test)
|
9
|
+
|
10
|
+
require 'restful/matchers'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: restful-matchers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcos Hack
|
@@ -38,35 +38,9 @@ dependencies:
|
|
38
38
|
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.0'
|
41
|
-
-
|
42
|
-
|
43
|
-
|
44
|
-
requirements:
|
45
|
-
- - '>='
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - '>='
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: pry-nav
|
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
|
-
description: RSpec matchers for testing RESTful resource link representations
|
41
|
+
description: RSpec matchers to test RESTful HATEOAS-compliant resource links. Currently
|
42
|
+
it supports only JSON representations as an array of link objects with rel and href
|
43
|
+
attributes.
|
70
44
|
email:
|
71
45
|
- marcoshack@gmail.com
|
72
46
|
executables: []
|
@@ -82,13 +56,13 @@ files:
|
|
82
56
|
- Rakefile
|
83
57
|
- lib/restful-matchers.rb
|
84
58
|
- lib/restful/matchers.rb
|
85
|
-
- lib/restful/matchers/
|
59
|
+
- lib/restful/matchers/have_link.rb
|
86
60
|
- lib/restful/matchers/integrations/rspec.rb
|
87
61
|
- restful-matchers.gemspec
|
88
62
|
- spec/fixtures/json/resource.json
|
89
|
-
- spec/restful/matchers/
|
63
|
+
- spec/restful/matchers/have_link_spec.rb
|
90
64
|
- spec/spec_helper.rb
|
91
|
-
homepage: https://github.com/marcoshack/
|
65
|
+
homepage: https://github.com/marcoshack/restful-matchers
|
92
66
|
licenses:
|
93
67
|
- MIT
|
94
68
|
metadata: {}
|
@@ -111,5 +85,5 @@ rubyforge_project:
|
|
111
85
|
rubygems_version: 2.0.4
|
112
86
|
signing_key:
|
113
87
|
specification_version: 4
|
114
|
-
summary:
|
88
|
+
summary: RSpec matchers to test RESTful HATEOAS-compliant resource links.
|
115
89
|
test_files: []
|