hal_spec 0.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.
- data/..gemspec +17 -0
- data/.gitignore +18 -0
- data/.rvmrc +38 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +119 -0
- data/Rakefile +16 -0
- data/features/equivalence.feature +11 -0
- data/features/step_definitions/steps.rb +17 -0
- data/features/support/env.rb +1 -0
- data/hal_spec.gemspec +27 -0
- data/lib/hal_spec.rb +8 -0
- data/lib/hal_spec/cucumber.rb +11 -0
- data/lib/hal_spec/matchers.rb +26 -0
- data/lib/hal_spec/matchers/be_valid_hal.rb +11 -0
- data/lib/hal_spec/matchers/have_a_valid_hal_content_type.rb +14 -0
- data/lib/hal_spec/version.rb +3 -0
- data/spec/hal_spec/matchers/be_valid_hal_spec.rb +127 -0
- data/spec/hal_spec/matchers/have_a_valid_hal_content_type_spec.rb +26 -0
- data/spec/hal_spec/matchers_spec.rb +19 -0
- data/spec/spec_helper.rb +1 -0
- metadata +138 -0
data/..gemspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/./version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Luis Borjas"]
|
6
|
+
gem.email = ["luisfborjas@gmail.com"]
|
7
|
+
gem.description = %q{TODO: Write a gem description}
|
8
|
+
gem.summary = %q{TODO: Write a gem summary}
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "."
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = .::VERSION
|
17
|
+
end
|
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
4
|
+
# development environment upon cd'ing into the directory
|
5
|
+
|
6
|
+
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
|
7
|
+
# Only full ruby name is supported here, for short names use:
|
8
|
+
# echo "rvm use 1.9.3" > .rvmrc
|
9
|
+
environment_id="ruby-1.9.3-p125@hal_spec"
|
10
|
+
|
11
|
+
# Uncomment the following lines if you want to verify rvm version per project
|
12
|
+
# rvmrc_rvm_version="1.16.20 (stable)" # 1.10.1 seams as a safe start
|
13
|
+
# eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
|
14
|
+
# echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
|
15
|
+
# return 1
|
16
|
+
# }
|
17
|
+
|
18
|
+
# First we attempt to load the desired environment directly from the environment
|
19
|
+
# file. This is very fast and efficient compared to running through the entire
|
20
|
+
# CLI and selector. If you want feedback on which environment was used then
|
21
|
+
# insert the word 'use' after --create as this triggers verbose mode.
|
22
|
+
if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
|
23
|
+
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
|
24
|
+
then
|
25
|
+
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
26
|
+
[[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
|
27
|
+
\. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
|
28
|
+
if [[ $- == *i* ]] # check for interactive shells
|
29
|
+
then echo "Using: $(tput setaf 2)$GEM_HOME$(tput sgr0)" # show the user the ruby and gemset they are using in green
|
30
|
+
else echo "Using: $GEM_HOME" # don't use colors in non-interactive shells
|
31
|
+
fi
|
32
|
+
else
|
33
|
+
# If the environment file has not yet been created, use the RVM CLI to select.
|
34
|
+
rvm --create use "$environment_id" || {
|
35
|
+
echo "Failed to create RVM environment '${environment_id}'."
|
36
|
+
return 1
|
37
|
+
}
|
38
|
+
fi
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Luis Borjas
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
# HalSpec
|
2
|
+
|
3
|
+
Adds custom matchers for RSpec and step definitions
|
4
|
+
for cucumber to validate and inspect [Hypertext Application
|
5
|
+
Language](http://stateless.co/hal_specification.html)
|
6
|
+
(the json version) responses (i.e. __no xml support is included__). Builds atop
|
7
|
+
[json_spec](https://github.com/collectiveidea/json_spec)
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
gem 'hal_spec'
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install hal_spec
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
|
26
|
+
### Rspec
|
27
|
+
|
28
|
+
This gem exposes all the matchers and helpers provided by
|
29
|
+
`json_spec` (cf. [their
|
30
|
+
README](https://github.com/collectiveidea/json_spec)) plus some
|
31
|
+
HAL-specific matchers:
|
32
|
+
|
33
|
+
* `be_valid_hal`
|
34
|
+
|
35
|
+
(the below example assumes use of the
|
36
|
+
[Roar](https://github.com/apotonick/roar) gem for the `MovieRepresenter` class just for illustration purposes, it's not necessary at all)
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
describe Movie
|
40
|
+
let(:movie){ Movie.create!(title: "2001", cast: [Character.create(name: "HAL"), Character.create(name: "Dave")]) }
|
41
|
+
|
42
|
+
context "#to_json" do
|
43
|
+
it "includes the associations" do
|
44
|
+
Movie.extend(MovieRepresenter)
|
45
|
+
movie.to_json should be_valid_hal
|
46
|
+
movie.to_json should have_json_path("_embedded/cast")
|
47
|
+
movie.to_json should have_json_size(2).at_path("_embedded/cast")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
```
|
52
|
+
|
53
|
+
### Cucumber
|
54
|
+
|
55
|
+
In your `env.rb`, add
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
require "hal_spec/cucumber"
|
59
|
+
```
|
60
|
+
|
61
|
+
(the `json_spec` gem requires that you define a `last_json` method in
|
62
|
+
your support files, but this
|
63
|
+
one doesn't, since it also validates headers from the response)
|
64
|
+
|
65
|
+
And use the steps in your responses.
|
66
|
+
|
67
|
+
(the example below had the
|
68
|
+
[cucumber-api-steps](https://github.com/jayzes/cucumber-api-steps) gem in mind but,
|
69
|
+
again, not necessary)
|
70
|
+
|
71
|
+
```cucumber
|
72
|
+
Feature: Movie API
|
73
|
+
Background:
|
74
|
+
Given the following movies exist:
|
75
|
+
| id | title |
|
76
|
+
| 1 | 2001: a space odyssey |
|
77
|
+
| 2 | 2010: odyssey two |
|
78
|
+
And the following characters exist:
|
79
|
+
| id | name |
|
80
|
+
| 1 | Dave |
|
81
|
+
And character "Dave" appears in "2001: a space odyssey"
|
82
|
+
And character "Dave" appears in "2010: odyssey two"
|
83
|
+
|
84
|
+
Scenario: Show character endpoint
|
85
|
+
When I send a GET request to "/characters/1"
|
86
|
+
Then the HAL response should be:
|
87
|
+
"""
|
88
|
+
{
|
89
|
+
"_links": {
|
90
|
+
"self": {"href": "/characters/1"}
|
91
|
+
}
|
92
|
+
,"id": 1
|
93
|
+
,"name": "Dave"
|
94
|
+
,"_embedded": {
|
95
|
+
"movies": [
|
96
|
+
{
|
97
|
+
"_links": {"self": {"href": "/movies/1"}}
|
98
|
+
,"id": 1
|
99
|
+
,"name": "2001: a space odyssey"
|
100
|
+
}
|
101
|
+
,{
|
102
|
+
"_links": {"self": {"href": "/movies/2"}}
|
103
|
+
,"id": 2
|
104
|
+
,"name": "2010: odyssey two"
|
105
|
+
}
|
106
|
+
]
|
107
|
+
}
|
108
|
+
}
|
109
|
+
"""
|
110
|
+
```
|
111
|
+
|
112
|
+
|
113
|
+
## Contributing
|
114
|
+
|
115
|
+
1. Fork it
|
116
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
117
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
118
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
119
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
|
6
|
+
RSpec::Core::RakeTask.new('spec')
|
7
|
+
|
8
|
+
|
9
|
+
require 'cucumber'
|
10
|
+
require 'cucumber/rake/task'
|
11
|
+
|
12
|
+
Cucumber::Rake::Task.new(:features) do |t|
|
13
|
+
t.cucumber_opts = "features --format pretty"
|
14
|
+
end
|
15
|
+
|
16
|
+
task :default => [:spec, :features]
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rack/test'
|
2
|
+
|
3
|
+
World(Rack::Test::Methods)
|
4
|
+
|
5
|
+
def app
|
6
|
+
->(env) do
|
7
|
+
[200, {"Content-Type" => "application/vnd.hal+json", "Content-Length" => @hal.length}, [@hal] || []]
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
Given "the HAL is:" do |provided_hal|
|
12
|
+
@hal = provided_hal
|
13
|
+
end
|
14
|
+
|
15
|
+
When "I get the HAL" do
|
16
|
+
get '/'
|
17
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'hal_spec/cucumber'
|
data/hal_spec.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/hal_spec/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Luis Borjas"]
|
6
|
+
gem.email = ["luisfborjas@gmail.com"]
|
7
|
+
gem.description = %q{RSpec and Cucumber helpers for HAL}
|
8
|
+
gem.summary = %q{
|
9
|
+
Adds custom matchers for RSpec and step definitions
|
10
|
+
for cucumber to validate and inspect Hypertext Application Language
|
11
|
+
(+json) responses
|
12
|
+
}
|
13
|
+
gem.homepage = "https://github.com/lfborjas/hal_spec"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($\)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.name = "hal_spec"
|
19
|
+
gem.require_paths = ["lib"]
|
20
|
+
gem.version = HalSpec::VERSION
|
21
|
+
|
22
|
+
gem.add_dependency "halidator", "~> 0.5"
|
23
|
+
|
24
|
+
gem.add_development_dependency "rspec", "~> 2.0"
|
25
|
+
gem.add_development_dependency "cucumber"
|
26
|
+
gem.add_development_dependency "rack-test"
|
27
|
+
end
|
data/lib/hal_spec.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.expand_path("../../hal_spec", __FILE__)
|
2
|
+
World(HalSpec::Matchers)
|
3
|
+
|
4
|
+
Then /the HAL response should be:/ do |whole_or_partial_hal|
|
5
|
+
|
6
|
+
json_body = JSON.parse(last_response.body)
|
7
|
+
json_body.should_not be_nil
|
8
|
+
json_body.should == (JSON.parse(whole_or_partial_hal))
|
9
|
+
last_response.should have_a_valid_hal_content_type
|
10
|
+
last_response.should be_valid_hal
|
11
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'hal_spec/matchers/have_a_valid_hal_content_type'
|
2
|
+
require 'hal_spec/matchers/be_valid_hal'
|
3
|
+
|
4
|
+
module HalSpec
|
5
|
+
module Matchers
|
6
|
+
extend RSpec::Matchers::DSL
|
7
|
+
include HalSpec::Matchers::HaveAValidHalContentType
|
8
|
+
include HalSpec::Matchers::BeValidHal
|
9
|
+
|
10
|
+
matcher :have_a_valid_hal_content_type do
|
11
|
+
match do |response|
|
12
|
+
has_valid_content_type?(response)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
matcher :be_valid_hal do
|
17
|
+
match do |response|
|
18
|
+
has_valid_body?(response)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
RSpec.configure do |config|
|
25
|
+
config.include HalSpec::Matchers
|
26
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module HalSpec
|
2
|
+
module Matchers
|
3
|
+
module BeValidHal
|
4
|
+
def has_valid_body?(response)
|
5
|
+
return false unless (response.respond_to?(:body) and !response.body.nil?)
|
6
|
+
JSON.parse(response.body) rescue return false
|
7
|
+
return Halidator.new(response.body).valid?
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module HalSpec
|
2
|
+
module Matchers
|
3
|
+
module HaveAValidHalContentType
|
4
|
+
def has_valid_content_type?(response)
|
5
|
+
response.respond_to?(:headers) or return false
|
6
|
+
response.headers.include?("Content-Type") or return false
|
7
|
+
%w(
|
8
|
+
application/vnd.hal+json
|
9
|
+
application/hal+json
|
10
|
+
).include?(response.headers["Content-Type"])
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'ostruct'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
def Hal(body)
|
6
|
+
OpenStruct.new(body: JSON.dump(body))
|
7
|
+
end
|
8
|
+
|
9
|
+
describe HalSpec::Matchers::BeValidHal do
|
10
|
+
let(:minimal_hal){ {_links: {self: {href: "/some/url"}}} }
|
11
|
+
|
12
|
+
context "response prerequisites" do
|
13
|
+
it "should match responses with documented json" do
|
14
|
+
OpenStruct.new(
|
15
|
+
body: '/*this is hal*/{"_links": /*documents are fun!*/{"self": {"href": "/url"}}}'
|
16
|
+
).should be_valid_hal
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should not match responses without bodies" do
|
20
|
+
OpenStruct.new(bodie: "lel").should_not be_valid_hal
|
21
|
+
OpenStruct.new(body: nil).should_not be_valid_hal
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should not match responses without json bodies" do
|
25
|
+
OpenStruct.new(body: "Yo dawg").should_not be_valid_hal
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "link validation" do
|
30
|
+
it "should match a document with only links" do
|
31
|
+
Hal(minimal_hal).should be_valid_hal
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should match a document with valid links other than self" do
|
35
|
+
json = minimal_hal.dup
|
36
|
+
json[:_links].merge!({search: {href: "/search/{q}", templated: true}})
|
37
|
+
Hal(json).should be_valid_hal
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should match a document with valid links in arrays" do
|
41
|
+
json = minimal_hal.dup
|
42
|
+
json[:_links].merge!({users: [{href: "/users/42"}]})
|
43
|
+
Hal(json).should be_valid_hal
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should match a document with templated links in arrays" do
|
47
|
+
json = minimal_hal.dup
|
48
|
+
json[:_links].merge!({sortings: [{href: "/sort/{dir}", templated: true}]})
|
49
|
+
Hal(json).should be_valid_hal
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should not match a document without links" do
|
53
|
+
Hal({no_links: {self: {href: "/nope"}}}).should_not be_valid_hal
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should not match a document without the self link" do
|
57
|
+
Hal({_links: {lel: {href: "/pah"}}}).should_not be_valid_hal
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should not match a document with invalid link values for self" do
|
61
|
+
Hal({_links: {self: {breh: "/brah"}}}).should_not be_valid_hal
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should not match a document with invalid links for other rels" do
|
65
|
+
json = minimal_hal.dup
|
66
|
+
json[:_links].merge!({search: "/search/{q}", templated: true})
|
67
|
+
Hal(json).should_not be_valid_hal
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should not match a document with too many self rels" do
|
71
|
+
json = minimal_hal.dup
|
72
|
+
json[:_links].merge!({users: [{self: {href: "/users/4"}},{self: {href: "/users/2"}}]})
|
73
|
+
Hal(json).should_not be_valid_hal
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should not match a document with no href key in arrays" do
|
77
|
+
json = minimal_hal.dup
|
78
|
+
json[:_links].merge!({users: [{bref: "/lel"}]})
|
79
|
+
Hal(json).should_not be_valid_hal
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should not match a document with invalid templates in arrays" do
|
83
|
+
json = minimal_hal.dup
|
84
|
+
json[:_links].merge!({sortings: [
|
85
|
+
{href: "/name", templated: true},
|
86
|
+
{href: "/age/{sort", templated: true},
|
87
|
+
{href: "/age/sort}", templated: true},
|
88
|
+
]})
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
context "resource validation" do
|
93
|
+
it "should match a document with embedded resources as an object" do
|
94
|
+
Hal({_embedded: {resources: []}}.merge(minimal_hal)).should be_valid_hal
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should match a document with valid embedded resources" do
|
98
|
+
Hal({_embedded: {resources: 2.times.collect{minimal_hal}}}.merge(minimal_hal)).should be_valid_hal
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should match a document with non-array valid embedded resources" do
|
102
|
+
Hal({
|
103
|
+
_embedded: {user: minimal_hal}
|
104
|
+
}.merge(minimal_hal)).should be_valid_hal
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should match a document with deeply nested valid resources" do
|
108
|
+
valid_hal = minimal_hal
|
109
|
+
json = {
|
110
|
+
_embedded: {
|
111
|
+
user: [{_embedded: {stuff: [valid_hal]}}.merge(valid_hal)]
|
112
|
+
}
|
113
|
+
}.merge(minimal_hal)
|
114
|
+
Hal(json).should be_valid_hal
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should not match a document with deeply nested invalid resources" do
|
118
|
+
Hal({
|
119
|
+
_embedded: {
|
120
|
+
user: [{
|
121
|
+
_embedded: {stuff: [{_links: {self: {lel: "/lol"}}}]}
|
122
|
+
}.merge(minimal_hal)]
|
123
|
+
}
|
124
|
+
}.merge(minimal_hal)).should_not be_valid_hal
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
describe HalSpec::Matchers::HaveAValidHalContentType do
|
5
|
+
it "matches standard hal content types" do
|
6
|
+
response = OpenStruct.new(headers: {"Content-Type" => "application/vnd.hal+json"})
|
7
|
+
response.should have_a_valid_hal_content_type
|
8
|
+
|
9
|
+
response = OpenStruct.new(headers: {"Content-Type" => "application/hal+json"})
|
10
|
+
response.should have_a_valid_hal_content_type
|
11
|
+
end
|
12
|
+
|
13
|
+
it "doesn't match invalid hal content types" do
|
14
|
+
response = OpenStruct.new(headers: {"Content-Type" => "application/json"})
|
15
|
+
response.should_not have_a_valid_hal_content_type
|
16
|
+
end
|
17
|
+
|
18
|
+
it "doesn't match responses without content types" do
|
19
|
+
response = OpenStruct.new(headers: {})
|
20
|
+
response.should_not have_a_valid_hal_content_type
|
21
|
+
|
22
|
+
response = OpenStruct.new
|
23
|
+
response.should_not have_a_valid_hal_content_type
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe HalSpec::Matchers do
|
4
|
+
context "have_a_valid_hal_content_type" do
|
5
|
+
it "responds to the matcher" do
|
6
|
+
klass = Class.new
|
7
|
+
klass.send(:include, HalSpec::Matchers)
|
8
|
+
klass.new.should respond_to(:have_a_valid_hal_content_type)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
context "be_valid_hal" do
|
13
|
+
it "responds to the matcher" do
|
14
|
+
klass = Class.new
|
15
|
+
klass.send(:include, HalSpec::Matchers)
|
16
|
+
klass.new.should respond_to(:be_valid_hal)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "hal_spec"
|
metadata
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hal_spec
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Luis Borjas
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-14 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: halidator
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0.5'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.5'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '2.0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '2.0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: cucumber
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rack-test
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: RSpec and Cucumber helpers for HAL
|
79
|
+
email:
|
80
|
+
- luisfborjas@gmail.com
|
81
|
+
executables: []
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files: []
|
84
|
+
files:
|
85
|
+
- ..gemspec
|
86
|
+
- .gitignore
|
87
|
+
- .rvmrc
|
88
|
+
- Gemfile
|
89
|
+
- LICENSE
|
90
|
+
- README.md
|
91
|
+
- Rakefile
|
92
|
+
- features/equivalence.feature
|
93
|
+
- features/step_definitions/steps.rb
|
94
|
+
- features/support/env.rb
|
95
|
+
- hal_spec.gemspec
|
96
|
+
- lib/hal_spec.rb
|
97
|
+
- lib/hal_spec/cucumber.rb
|
98
|
+
- lib/hal_spec/matchers.rb
|
99
|
+
- lib/hal_spec/matchers/be_valid_hal.rb
|
100
|
+
- lib/hal_spec/matchers/have_a_valid_hal_content_type.rb
|
101
|
+
- lib/hal_spec/version.rb
|
102
|
+
- spec/hal_spec/matchers/be_valid_hal_spec.rb
|
103
|
+
- spec/hal_spec/matchers/have_a_valid_hal_content_type_spec.rb
|
104
|
+
- spec/hal_spec/matchers_spec.rb
|
105
|
+
- spec/spec_helper.rb
|
106
|
+
homepage: https://github.com/lfborjas/hal_spec
|
107
|
+
licenses: []
|
108
|
+
post_install_message:
|
109
|
+
rdoc_options: []
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
none: false
|
120
|
+
requirements:
|
121
|
+
- - ! '>='
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
requirements: []
|
125
|
+
rubyforge_project:
|
126
|
+
rubygems_version: 1.8.21
|
127
|
+
signing_key:
|
128
|
+
specification_version: 3
|
129
|
+
summary: Adds custom matchers for RSpec and step definitions for cucumber to validate
|
130
|
+
and inspect Hypertext Application Language (+json) responses
|
131
|
+
test_files:
|
132
|
+
- features/equivalence.feature
|
133
|
+
- features/step_definitions/steps.rb
|
134
|
+
- features/support/env.rb
|
135
|
+
- spec/hal_spec/matchers/be_valid_hal_spec.rb
|
136
|
+
- spec/hal_spec/matchers/have_a_valid_hal_content_type_spec.rb
|
137
|
+
- spec/hal_spec/matchers_spec.rb
|
138
|
+
- spec/spec_helper.rb
|