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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 17bb149bb591339ab94a2184962ecec34c73c868
4
- data.tar.gz: 793b990cfa27d182b7a29b6c2817aaa147f77f86
3
+ metadata.gz: fa23bf113f67c1d2ebcec7749f06a5297fe44ad0
4
+ data.tar.gz: 2ef8175345a2c7abc59b4f3cc2a0f00b3bcb9bdd
5
5
  SHA512:
6
- metadata.gz: d8b21187bf478846242ac79c81989131a577d987d13a49b2b451e44fc8cbdc01b08ea3e41b4639e0691c07a1e91f994f9351d537fd8df6bbc56c054addac0661
7
- data.tar.gz: 98a7a1c319fb2e10561d74c1e82b85d5f8e8d24c44e3aea8581f8ccdb5d5b49873c97766429405a82089505424f7ce2311749ee4ae20cb2a186f73e3d5c842f3
6
+ metadata.gz: e694f1dfa908ccdb0292d6f8ffb0c04ce130ee345072c7640ebed3cf2afed1993e2637bd93fb2965c8b93cfd38e76cfd7680684d3ec79c8a6f970db5efb54f4f
7
+ data.tar.gz: 23bac76446ef247fdcf053e98d65032bca1245b1d6f21b53b0d2eaaf1742bee9fe41730a4cb3a1c419c752336515642e4f673b33652164eed052d2aac92da999
data/.gitignore CHANGED
@@ -1 +1,3 @@
1
- restful-matchers-*.gem
1
+ restful-matchers-*.gem
2
+ .bundle
3
+ vendor
data/Gemfile CHANGED
@@ -2,6 +2,6 @@ source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
- gem "rake", "~> 10.0"
5
+ gem "rake", "~> 10.1"
6
6
  gem "pry", "~> 0.9"
7
- gem "pry-nav", "~> 0.2"
7
+ gem "pry-nav", "~> 0.2"
@@ -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.1)
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.5)
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.0)
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, 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.
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
- Example:
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 entry-point links" do
26
+ it "should have links" do
22
27
  get :index
23
- response.body.should have_restful_json_link("self", "http://example.com")
24
- response.body.should have_restful_json_link("resource1", "http://example.com/resource1")
25
- response.body.should have_restful_json_link("resource2", "http://example.com/resource2")
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 do
36
- gem 'restful-matchers'
37
- end
43
+ gem 'restful-matchers', '~> 0.2', :group => :test
38
44
  ```
@@ -1,4 +1,4 @@
1
- require "restful/matchers/have_restful_json_link"
1
+ require "restful/matchers/have_link"
2
2
 
3
3
  if defined?(RSpec)
4
4
  require 'restful/matchers/integrations/rspec'
@@ -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 have_restful_json_link(rel, href = nil)
11
- HaveRestfulJsonLink.new(rel, href)
10
+ def have_link(rel, href = nil)
11
+ HaveLink.new(rel, href)
12
12
  end
13
- alias_method :have_link, :have_restful_json_link
13
+ alias_method :have_restful_json_link, :have_link
14
14
 
15
- class HaveRestfulJsonLink
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
- raise StandardError.new("JSON has no RESTful links")
26
+ return false
26
27
  end
27
28
  end
28
29
 
29
30
  def failure_message_for_should
30
- "Expected RESTful link: #{link_representation}"
31
+ error_message "Expected RESTful link"
31
32
  end
32
33
 
33
34
  def failure_message_for_should_not
34
- "Expected no RESTful link: #{link_representation}"
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 link_representation
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)
@@ -2,20 +2,17 @@
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = "restful-matchers"
5
- gem.version = "0.2.0"
5
+ gem.version = "0.2.1"
6
6
 
7
7
  gem.authors = [ "Marcos Hack" ]
8
8
  gem.email = [ "marcoshack@gmail.com" ]
9
- gem.summary = "Easily handle RESTful resources in your tests"
10
- gem.description = "RSpec matchers for testing RESTful resource link representations"
11
- gem.homepage = "https://github.com/marcoshack/rspec-restful-matchers"
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::HaveRestfulJsonLink do
3
+ describe RESTful::Matchers::HaveLink do
4
4
 
5
- shared_examples_for "RESTful Matcher" do
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 "RESTful Matcher"
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 "RESTful Matcher"
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
+
@@ -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.0
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
- - !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'
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/have_restful_json_link.rb
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/have_restful_json_link_spec.rb
63
+ - spec/restful/matchers/have_link_spec.rb
90
64
  - spec/spec_helper.rb
91
- homepage: https://github.com/marcoshack/rspec-restful-matchers
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: Easily handle RESTful resources in your tests
88
+ summary: RSpec matchers to test RESTful HATEOAS-compliant resource links.
115
89
  test_files: []