rspec-hal 1.2.4 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -1
- data/README.md +3 -3
- data/gemfiles/rspec3_0.gemfile +1 -1
- data/lib/rspec/hal/matchers/templated_relation_matcher.rb +16 -0
- data/lib/rspec/hal/matchers/uri_template_has_variables_matcher.rb +44 -0
- data/lib/rspec/hal/version.rb +1 -1
- data/rspec-hal.gemspec +2 -1
- data/spec/rspec/hal/matchers/templated_relation_matcher_spec.rb +27 -0
- data/spec/rspec/hal/matchers/uri_template_has_variables_matcher_spec.rb +31 -0
- metadata +27 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4f45bc788fb6dedb83b95f4e3c590675656f00f
|
4
|
+
data.tar.gz: 32d538a5f870c291400fa3bd9a009b6b874d185c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d7d17141a06542082de424a0e5d435137fab68c4bff5a6dcabc568aa1c72aef7d4086a86539bf96a8a953865135c0a529982b4703c60f26780969b9da1e3b9a
|
7
|
+
data.tar.gz: a07578234ce02b41184b1e049a00f7d83307f978d040101bb9eb21b3951288e0668f63b5a19318f8ace245425042d3f602fe9217b1d8a36451d6cb039ada178b
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
[![Build Status](https://travis-ci.org/pezra/hal
|
2
|
-
[![Code Climate](https://codeclimate.com/github/pezra/hal
|
1
|
+
[![Build Status](https://travis-ci.org/pezra/rspec-hal.png?branch=master)](https://travis-ci.org/pezra/rspec-hal)
|
2
|
+
[![Code Climate](https://codeclimate.com/github/pezra/rspec-hal.png)](https://codeclimate.com/github/pezra/rspec-hal)
|
3
3
|
|
4
4
|
# Rspec Hal
|
5
5
|
|
@@ -36,7 +36,7 @@ Once you have the matchers included you can use it like this
|
|
36
36
|
|
37
37
|
expect(a_user_doc).to have_relation('tag')
|
38
38
|
expect(a_user_doc).to have_templated_relation("search")
|
39
|
-
expect(a_user_doc).to have_templated_relation("search"
|
39
|
+
expect(a_user_doc).to have_templated_relation("search").with_variables("q", "limit")
|
40
40
|
```
|
41
41
|
|
42
42
|
## Installation
|
data/gemfiles/rspec3_0.gemfile
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
require 'rspec/expectations'
|
2
|
+
require 'rspec/hal/matchers/uri_template_has_variables_matcher'
|
3
|
+
|
1
4
|
module RSpec
|
2
5
|
module Hal
|
3
6
|
module Matchers
|
@@ -57,6 +60,19 @@ module RSpec
|
|
57
60
|
"have templated #{link_rel} link"
|
58
61
|
end
|
59
62
|
|
63
|
+
def with_variables(*vars)
|
64
|
+
raise "This method is unsupported with RSpec version 2.x" unless
|
65
|
+
defined? RSpec::Matchers::BuiltIn::Compound::And
|
66
|
+
|
67
|
+
RSpec::Matchers::BuiltIn::Compound::And.
|
68
|
+
new(self, UriTemplateHasVariablesMatcher.new(self, vars))
|
69
|
+
end
|
70
|
+
alias_method :with_variable, :with_variables
|
71
|
+
|
72
|
+
def uri_template
|
73
|
+
repr.raw_related_hrefs(link_rel){[]}.first
|
74
|
+
end
|
75
|
+
|
60
76
|
protected
|
61
77
|
|
62
78
|
attr_reader :link_rel, :outcome, :expected
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'set'
|
2
|
+
require 'addressable/template'
|
3
|
+
|
4
|
+
module RSpec
|
5
|
+
module Hal
|
6
|
+
module Matchers
|
7
|
+
class UriTemplateHasVariablesMatcher
|
8
|
+
def initialize(a_tmpl_relation_matcher, vars)
|
9
|
+
@tmpl_matcher = a_tmpl_relation_matcher
|
10
|
+
@expected_vars = Set.new(vars)
|
11
|
+
end
|
12
|
+
|
13
|
+
def matches?(actual)
|
14
|
+
expected_vars.subset? actual_vars
|
15
|
+
end
|
16
|
+
|
17
|
+
def description
|
18
|
+
"have variables #{expected_vars.join(", ")}"
|
19
|
+
end
|
20
|
+
|
21
|
+
def failure_message
|
22
|
+
"Expected #{actual_tmpl.to_s} to have #{expected_vars.join(", ")}"
|
23
|
+
end
|
24
|
+
|
25
|
+
def failure_message_when_negated
|
26
|
+
"Expected #{actual_tmpl.to_s} not to have #{expected_vars.join(", ")}"
|
27
|
+
end
|
28
|
+
|
29
|
+
protected
|
30
|
+
|
31
|
+
attr_reader :tmpl_matcher, :expected_vars
|
32
|
+
|
33
|
+
def actual_tmpl
|
34
|
+
Addressable::Template.new(tmpl_matcher.uri_template)
|
35
|
+
end
|
36
|
+
|
37
|
+
def actual_vars
|
38
|
+
Set.new(actual_tmpl.variables)
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/rspec/hal/version.rb
CHANGED
data/rspec-hal.gemspec
CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.add_development_dependency "bundler", "~> 1.5"
|
21
21
|
spec.add_development_dependency "rake", "~> 10.1"
|
22
22
|
|
23
|
-
spec.add_runtime_dependency "rspec", ">= 2.0", "< 4.0.0.
|
23
|
+
spec.add_runtime_dependency "rspec", ">= 2.0", "< 4.0.0.a"
|
24
|
+
spec.add_runtime_dependency "rspec-expectations", ">= 2.0", "< 4.0.0.a"
|
24
25
|
spec.add_runtime_dependency "hal-client", "> 2.4"
|
25
26
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require_relative "../../../spec_helper"
|
2
|
+
require 'rspec/version'
|
2
3
|
|
3
4
|
describe RSpec::Hal::Matchers::TemplatedRelationMatcher do
|
4
5
|
describe "creation" do
|
@@ -22,6 +23,21 @@ describe RSpec::Hal::Matchers::TemplatedRelationMatcher do
|
|
22
23
|
|
23
24
|
specify { expect(matcher.description).to match "have templated #{a_link_rel} link" }
|
24
25
|
|
26
|
+
context "in RSpec 3.x" do
|
27
|
+
before { skip("unsupported version") if /2\./ === RSpec::Version::STRING }
|
28
|
+
|
29
|
+
specify { expect(matcher.with_variables("since", "before")).to be_a_matcher }
|
30
|
+
specify { expect(matcher.with_variable("since")).to be_a_matcher }
|
31
|
+
end
|
32
|
+
|
33
|
+
context "in RSpec 3.x" do
|
34
|
+
before { skip("unsupported version") unless /2\./ === RSpec::Version::STRING }
|
35
|
+
|
36
|
+
specify { expect { matcher.with_variables("since", "before") }.to raise_exception(/version/) }
|
37
|
+
|
38
|
+
specify { expect { matcher.with_variable("since") }.to raise_exception(/version/) }
|
39
|
+
end
|
40
|
+
|
25
41
|
context "failed due to missing relation matcher" do
|
26
42
|
before do
|
27
43
|
matcher.matches? json_str_wo_link
|
@@ -105,4 +121,15 @@ describe RSpec::Hal::Matchers::TemplatedRelationMatcher do
|
|
105
121
|
let(:any_template_str_matcher) { matching_template_str_matcher }
|
106
122
|
let(:matching_template_str_matcher) { match "example.com" }
|
107
123
|
let(:nonmatching_template_str_matcher) { match "hello" }
|
124
|
+
|
125
|
+
matcher :be_a_matcher do
|
126
|
+
match do |actual|
|
127
|
+
%w"matches?
|
128
|
+
description
|
129
|
+
failure_message
|
130
|
+
failure_message_when_negated".all? { |meth_name|
|
131
|
+
actual.respond_to? meth_name
|
132
|
+
}
|
133
|
+
end
|
134
|
+
end
|
108
135
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require_relative "../../../spec_helper"
|
2
|
+
require "rspec/version"
|
3
|
+
|
4
|
+
describe RSpec::Hal::Matchers::UriTemplateHasVariablesMatcher do
|
5
|
+
describe "creation" do
|
6
|
+
specify { expect{ described_class.new(a_templated_relation_matcher, ["foo"]) }.
|
7
|
+
not_to raise_error }
|
8
|
+
end
|
9
|
+
|
10
|
+
subject(:matcher) { described_class.new(a_templated_relation_matcher, ["foo", "bar"]) }
|
11
|
+
|
12
|
+
context "template with required variables" do
|
13
|
+
let(:template) { "http://example.com{?foo,bar}" }
|
14
|
+
|
15
|
+
specify { expect(matcher.matches?(json_doc_that_is_ignored)).to be_truthy }
|
16
|
+
end
|
17
|
+
|
18
|
+
context "template missing one required variabl" do
|
19
|
+
let(:template) { "http://example.com{?foo}" }
|
20
|
+
|
21
|
+
specify { expect(matcher.matches?(json_doc_that_is_ignored)).to be_falsy }
|
22
|
+
end
|
23
|
+
|
24
|
+
# Background
|
25
|
+
# ---
|
26
|
+
|
27
|
+
let(:template) { "http://example.com" }
|
28
|
+
let(:a_templated_relation_matcher) {
|
29
|
+
double(:a_templated_relation_matcher, uri_template: template) }
|
30
|
+
let(:json_doc_that_is_ignored) { "" }
|
31
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-hal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -47,7 +47,7 @@ dependencies:
|
|
47
47
|
version: '2.0'
|
48
48
|
- - "<"
|
49
49
|
- !ruby/object:Gem::Version
|
50
|
-
version: 4.0.0.
|
50
|
+
version: 4.0.0.a
|
51
51
|
type: :runtime
|
52
52
|
prerelease: false
|
53
53
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -57,7 +57,27 @@ dependencies:
|
|
57
57
|
version: '2.0'
|
58
58
|
- - "<"
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
version: 4.0.0.
|
60
|
+
version: 4.0.0.a
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rspec-expectations
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '2.0'
|
68
|
+
- - "<"
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 4.0.0.a
|
71
|
+
type: :runtime
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '2.0'
|
78
|
+
- - "<"
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 4.0.0.a
|
61
81
|
- !ruby/object:Gem::Dependency
|
62
82
|
name: hal-client
|
63
83
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,11 +114,13 @@ files:
|
|
94
114
|
- lib/rspec/hal/matchers/have_property_matcher.rb
|
95
115
|
- lib/rspec/hal/matchers/relation_matcher.rb
|
96
116
|
- lib/rspec/hal/matchers/templated_relation_matcher.rb
|
117
|
+
- lib/rspec/hal/matchers/uri_template_has_variables_matcher.rb
|
97
118
|
- lib/rspec/hal/version.rb
|
98
119
|
- rspec-hal.gemspec
|
99
120
|
- spec/rspec/hal/matchers/have_property_matcher_spec.rb
|
100
121
|
- spec/rspec/hal/matchers/relation_matcher_spec.rb
|
101
122
|
- spec/rspec/hal/matchers/templated_relation_matcher_spec.rb
|
123
|
+
- spec/rspec/hal/matchers/uri_template_has_variables_matcher_spec.rb
|
102
124
|
- spec/rspec/hal/matchers_spec.rb
|
103
125
|
- spec/spec_helper.rb
|
104
126
|
homepage: http://github.com/pezra/rspec-hal
|
@@ -129,5 +151,6 @@ test_files:
|
|
129
151
|
- spec/rspec/hal/matchers/have_property_matcher_spec.rb
|
130
152
|
- spec/rspec/hal/matchers/relation_matcher_spec.rb
|
131
153
|
- spec/rspec/hal/matchers/templated_relation_matcher_spec.rb
|
154
|
+
- spec/rspec/hal/matchers/uri_template_has_variables_matcher_spec.rb
|
132
155
|
- spec/rspec/hal/matchers_spec.rb
|
133
156
|
- spec/spec_helper.rb
|