restful-matchers 0.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MGJiYzQwMGZhNTEyNDIxYjFhZGYxMmVhNzg0ZjNhY2NkMzVlNTVlMg==
5
- data.tar.gz: !binary |-
6
- YWI1MmMwYWJhMGFmY2FjMTU5MjllMDM5OTRjMjIwZDkyNGVlZTc2OA==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- OWQ2MjdlMDBiMzk4N2JlNjk0OTZhNzk3NzA0M2E0YjE3MmNhODc2YWYzMmFh
10
- M2M1NjNlYzRlOTJkYzMwYTkyMmQ3OTBkZjAyNDU0M2MwMzA3OTIxZjA2ODQy
11
- OTI0ZmNmMjE4ZmUwZDZjZGVlMjc3MjYwYmQxMDY1NzJiMDM2Nzk=
12
- data.tar.gz: !binary |-
13
- Y2MzMTFhNDg1NGM2N2FkMmUyYjcwNjE3NzMwZmU3ODBkOTRlZTNmOWNkY2Yw
14
- YzRlNWJhNmE4NjU4N2Q0ZTRlMDVkNjExZDQ4M2RkYmZjYjVjMjBiMmYyNmY3
15
- MjZhMTQzMTRjNmYzNmJjNWNjOWYxNmUzNGVlZjhmYTMzNWYzM2M=
2
+ SHA1:
3
+ metadata.gz: 17bb149bb591339ab94a2184962ecec34c73c868
4
+ data.tar.gz: 793b990cfa27d182b7a29b6c2817aaa147f77f86
5
+ SHA512:
6
+ metadata.gz: d8b21187bf478846242ac79c81989131a577d987d13a49b2b451e44fc8cbdc01b08ea3e41b4639e0691c07a1e91f994f9351d537fd8df6bbc56c054addac0661
7
+ data.tar.gz: 98a7a1c319fb2e10561d74c1e82b85d5f8e8d24c44e3aea8581f8ccdb5d5b49873c97766429405a82089505424f7ce2311749ee4ae20cb2a186f73e3d5c842f3
data/.gitignore CHANGED
@@ -0,0 +1 @@
1
+ restful-matchers-*.gem
data/Gemfile CHANGED
@@ -3,3 +3,5 @@ source "https://rubygems.org"
3
3
  gemspec
4
4
 
5
5
  gem "rake", "~> 10.0"
6
+ gem "pry", "~> 0.9"
7
+ gem "pry-nav", "~> 0.2"
data/Gemfile.lock CHANGED
@@ -7,7 +7,15 @@ PATH
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
+ coderay (1.0.9)
10
11
  diff-lcs (1.2.4)
12
+ method_source (0.8.1)
13
+ pry (0.9.12.2)
14
+ coderay (~> 1.0.5)
15
+ method_source (~> 0.8)
16
+ slop (~> 3.4)
17
+ pry-nav (0.2.3)
18
+ pry (~> 0.9.10)
11
19
  rake (10.1.0)
12
20
  rspec (2.14.1)
13
21
  rspec-core (~> 2.14.0)
@@ -17,11 +25,14 @@ GEM
17
25
  rspec-expectations (2.14.2)
18
26
  diff-lcs (>= 1.1.3, < 2.0)
19
27
  rspec-mocks (2.14.3)
28
+ slop (3.4.5)
20
29
 
21
30
  PLATFORMS
22
31
  ruby
23
32
 
24
33
  DEPENDENCIES
25
34
  bundler (~> 1.0)
35
+ pry (~> 0.9)
36
+ pry-nav (~> 0.2)
26
37
  rake (~> 10.0)
27
38
  restful-matchers!
data/README.md CHANGED
@@ -1,6 +1,6 @@
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)
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 resource links. Currently it supports only JSON representations with an array of link objects with `rel` and `href` attributes, like this:
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, like this:
4
4
 
5
5
  ```json
6
6
  {
@@ -26,3 +26,13 @@ describe MyRestfulController do
26
26
  end
27
27
  end
28
28
  ```
29
+
30
+ ## Installation
31
+
32
+ Add it to the `test` group in your Gemfile and be happy!
33
+
34
+ ```ruby
35
+ group :test do
36
+ gem 'restful-matchers'
37
+ end
38
+ ```
@@ -7,19 +7,20 @@ module RESTful
7
7
  # Example:
8
8
  # response.body.should have_json_link("self", "http://example.com")
9
9
  #
10
- def have_restful_json_link(rel, href)
10
+ def have_restful_json_link(rel, href = nil)
11
11
  HaveRestfulJsonLink.new(rel, href)
12
12
  end
13
+ alias_method :have_link, :have_restful_json_link
13
14
 
14
15
  class HaveRestfulJsonLink
15
- def initialize(rel, href)
16
+ def initialize(rel, href = nil)
16
17
  @rel = rel
17
18
  @href = href
18
19
  end
19
20
 
20
- def matches?(json_string)
21
- if links = parse_links(json_string)
22
- return links[@rel] == @href
21
+ def matches?(content)
22
+ if links = parse_links_from(content)
23
+ return @href ? links[@rel] == @href : links.has_key?(@rel)
23
24
  else
24
25
  raise StandardError.new("JSON has no RESTful links")
25
26
  end
@@ -42,8 +43,8 @@ module RESTful
42
43
  "{ rel: #{@rel}, href: #{@href} }"
43
44
  end
44
45
 
45
- def parse_links(json_string)
46
- json = JSON.parse(json_string)
46
+ def parse_links_from(content)
47
+ json = content.is_a?(Hash) ? content : JSON.parse(content)
47
48
  links = nil
48
49
  if json["links"]
49
50
  links = {}
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = "restful-matchers"
5
- gem.version = "0.1"
5
+ gem.version = "0.2.0"
6
6
 
7
7
  gem.authors = [ "Marcos Hack" ]
8
8
  gem.email = [ "marcoshack@gmail.com" ]
@@ -14,6 +14,8 @@ Gem::Specification.new do |gem|
14
14
  gem.add_dependency "rspec", "~> 2.0"
15
15
 
16
16
  gem.add_development_dependency "bundler", "~> 1.0"
17
+ gem.add_development_dependency "pry"
18
+ gem.add_development_dependency "pry-nav"
17
19
 
18
20
  gem.files = `git ls-files`.split($\)
19
21
  gem.test_files = gem.files.grep(/^(test)/)
@@ -1,15 +1,30 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe RESTful::Matchers::HaveRestfulJsonLink do
4
- before :each do
5
- @json_response = open("spec/fixtures/json/resource.json").read
4
+
5
+ shared_examples_for "RESTful Matcher" do
6
+ it "should find a json link" do
7
+ @content.should have_restful_json_link("self", "http://example.com")
8
+ @content.should have_link("self", "http://example.com")
9
+ end
10
+
11
+ it "should not find an unexistant link" do
12
+ @content.should_not have_restful_json_link("foo", "http://bar.com")
13
+ @content.should_not have_link("foo", "http://bar.com")
14
+ end
15
+
16
+ it "should find a link matching only the rel attribute" do
17
+ @content.should have_link("self")
18
+ end
6
19
  end
7
20
 
8
- it "should find a json link" do
9
- @json_response.should have_restful_json_link("self", "http://example.com")
21
+ context "when processing a JSON content" do
22
+ before(:each) { @content = open("spec/fixtures/json/resource.json").read }
23
+ it_behaves_like "RESTful Matcher"
10
24
  end
11
25
 
12
- it "should not find an unexistant link" do
13
- @json_response.should_not have_restful_json_link("foo", "http://bar.com")
26
+ context "when processing a parsed JSON" do
27
+ before(:each) { @content = JSON.parse(open("spec/fixtures/json/resource.json").read) }
28
+ it_behaves_like "RESTful Matcher"
14
29
  end
15
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restful-matchers
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcos Hack
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-16 00:00:00.000000000 Z
11
+ date: 2013-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -38,6 +38,34 @@ dependencies:
38
38
  - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
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'
41
69
  description: RSpec matchers for testing RESTful resource link representations
42
70
  email:
43
71
  - marcoshack@gmail.com
@@ -70,17 +98,17 @@ require_paths:
70
98
  - lib
71
99
  required_ruby_version: !ruby/object:Gem::Requirement
72
100
  requirements:
73
- - - ! '>='
101
+ - - '>='
74
102
  - !ruby/object:Gem::Version
75
103
  version: '0'
76
104
  required_rubygems_version: !ruby/object:Gem::Requirement
77
105
  requirements:
78
- - - ! '>='
106
+ - - '>='
79
107
  - !ruby/object:Gem::Version
80
108
  version: '0'
81
109
  requirements: []
82
110
  rubyforge_project:
83
- rubygems_version: 2.0.5
111
+ rubygems_version: 2.0.4
84
112
  signing_key:
85
113
  specification_version: 4
86
114
  summary: Easily handle RESTful resources in your tests