restful-matchers 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
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=
data/.gitignore ADDED
File without changes
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ branches: master
3
+ rvm:
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem "rake", "~> 10.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,27 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ restful-matchers (0.1)
5
+ rspec (~> 2.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.2.4)
11
+ rake (10.1.0)
12
+ rspec (2.14.1)
13
+ rspec-core (~> 2.14.0)
14
+ rspec-expectations (~> 2.14.0)
15
+ rspec-mocks (~> 2.14.0)
16
+ rspec-core (2.14.5)
17
+ rspec-expectations (2.14.2)
18
+ diff-lcs (>= 1.1.3, < 2.0)
19
+ rspec-mocks (2.14.3)
20
+
21
+ PLATFORMS
22
+ ruby
23
+
24
+ DEPENDENCIES
25
+ bundler (~> 1.0)
26
+ rake (~> 10.0)
27
+ restful-matchers!
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright © 2013 Marcos Hack
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
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)
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:
4
+
5
+ ```json
6
+ {
7
+ "attribute1": "value1",
8
+ "attribute2": "value2",
9
+ "links": [
10
+ { "rel": "self", "href": "http://example.com" }
11
+ ]
12
+ }
13
+ ```
14
+
15
+ Example:
16
+
17
+ ```ruby
18
+ describe MyRestfulController do
19
+ render_views
20
+
21
+ it "should have entry-point links" do
22
+ 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")
26
+ end
27
+ end
28
+ ```
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require 'bundler/setup'
2
+ require 'bundler/gem_tasks'
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new do |t|
6
+ t.pattern = "spec/**/*_spec.rb"
7
+ t.rspec_opts = '--color --format progress'
8
+ t.verbose = false
9
+ end
10
+
11
+ task :test => [:spec]
12
+ task :default => :test
@@ -0,0 +1 @@
1
+ require 'restful/matchers'
@@ -0,0 +1,5 @@
1
+ require "restful/matchers/have_restful_json_link"
2
+
3
+ if defined?(RSpec)
4
+ require 'restful/matchers/integrations/rspec'
5
+ end
@@ -0,0 +1,56 @@
1
+ require 'json'
2
+
3
+ module RESTful
4
+ module Matchers
5
+ # Ensures that JSON response body has the given link.
6
+ #
7
+ # Example:
8
+ # response.body.should have_json_link("self", "http://example.com")
9
+ #
10
+ def have_restful_json_link(rel, href)
11
+ HaveRestfulJsonLink.new(rel, href)
12
+ end
13
+
14
+ class HaveRestfulJsonLink
15
+ def initialize(rel, href)
16
+ @rel = rel
17
+ @href = href
18
+ end
19
+
20
+ def matches?(json_string)
21
+ if links = parse_links(json_string)
22
+ return links[@rel] == @href
23
+ else
24
+ raise StandardError.new("JSON has no RESTful links")
25
+ end
26
+ end
27
+
28
+ def failure_message_for_should
29
+ "Expected RESTful link: #{link_representation}"
30
+ end
31
+
32
+ def failure_message_for_should_not
33
+ "Expected no RESTful link: #{link_representation}"
34
+ end
35
+
36
+ def description
37
+ "have RESTful link: #{link_representation}"
38
+ end
39
+
40
+ private
41
+ def link_representation
42
+ "{ rel: #{@rel}, href: #{@href} }"
43
+ end
44
+
45
+ def parse_links(json_string)
46
+ json = JSON.parse(json_string)
47
+ links = nil
48
+ if json["links"]
49
+ links = {}
50
+ json["links"].each { |link| links[link["rel"]] = link["href"] }
51
+ end
52
+ return links
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,6 @@
1
+ require 'rspec/core'
2
+ require 'restful/matchers'
3
+
4
+ RSpec.configure do |config|
5
+ config.include RESTful::Matchers
6
+ end
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.name = "restful-matchers"
5
+ gem.version = "0.1"
6
+
7
+ gem.authors = [ "Marcos Hack" ]
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"
12
+ gem.license = "MIT"
13
+
14
+ gem.add_dependency "rspec", "~> 2.0"
15
+
16
+ gem.add_development_dependency "bundler", "~> 1.0"
17
+
18
+ gem.files = `git ls-files`.split($\)
19
+ gem.test_files = gem.files.grep(/^(test)/)
20
+ gem.require_paths = ["lib"]
21
+ end
@@ -0,0 +1,7 @@
1
+ {
2
+ "attr1": "value1",
3
+ "attr2": "value2",
4
+ "links": [
5
+ { "rel": "self", "href": "http://example.com" }
6
+ ]
7
+ }
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe RESTful::Matchers::HaveRestfulJsonLink do
4
+ before :each do
5
+ @json_response = open("spec/fixtures/json/resource.json").read
6
+ end
7
+
8
+ it "should find a json link" do
9
+ @json_response.should have_restful_json_link("self", "http://example.com")
10
+ end
11
+
12
+ it "should not find an unexistant link" do
13
+ @json_response.should_not have_restful_json_link("foo", "http://bar.com")
14
+ end
15
+ end
@@ -0,0 +1,6 @@
1
+ require 'restful/matchers'
2
+
3
+ PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..')).freeze
4
+ $LOAD_PATH << File.join(PROJECT_ROOT, 'lib')
5
+
6
+ Dir[File.join(PROJECT_ROOT, 'spec', 'support', '**', '*.rb')].each { |file| require(file) }
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: restful-matchers
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Marcos Hack
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ description: RSpec matchers for testing RESTful resource link representations
42
+ email:
43
+ - marcoshack@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - .travis.yml
50
+ - Gemfile
51
+ - Gemfile.lock
52
+ - LICENSE
53
+ - README.md
54
+ - Rakefile
55
+ - lib/restful-matchers.rb
56
+ - lib/restful/matchers.rb
57
+ - lib/restful/matchers/have_restful_json_link.rb
58
+ - lib/restful/matchers/integrations/rspec.rb
59
+ - restful-matchers.gemspec
60
+ - spec/fixtures/json/resource.json
61
+ - spec/restful/matchers/have_restful_json_link_spec.rb
62
+ - spec/spec_helper.rb
63
+ homepage: https://github.com/marcoshack/rspec-restful-matchers
64
+ licenses:
65
+ - MIT
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 2.0.5
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: Easily handle RESTful resources in your tests
87
+ test_files: []