rspec-hal 1.3.0 → 1.3.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 +4 -4
- data/lib/rspec/hal/matchers/templated_relation_matcher.rb +1 -5
- data/lib/rspec/hal/matchers/uri_template_has_variables_matcher.rb +16 -8
- data/lib/rspec/hal/matchers.rb +15 -0
- data/lib/rspec/hal/version.rb +1 -1
- data/spec/rspec/hal/matchers/templated_relation_matcher_spec.rb +2 -14
- data/spec/rspec/hal/matchers/uri_template_has_variables_matcher_spec.rb +12 -8
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 459ebbc13de469d36a68fc9eecd02a9cdcc2db92
|
4
|
+
data.tar.gz: 0301e48952230c8ff6cda1058d7f23abf3293380
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3be160a4321735d850b19a38a808d1a108f34481696e47f8846b35aee065ac936b84ad5bd189cb4417a638ae1a07224e988d47c81893def2dabb5f3eb951ce92
|
7
|
+
data.tar.gz: e4313939011a4248ac5b92aeec8ec8bf0f0ddc1d380621df6ad497dcb863814731b0ca98ca8401ea2064a65b657c2eba4b35b4267fd2e4557f536c30675b5d2f
|
@@ -61,11 +61,7 @@ module RSpec
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def with_variables(*vars)
|
64
|
-
|
65
|
-
defined? RSpec::Matchers::BuiltIn::Compound::And
|
66
|
-
|
67
|
-
RSpec::Matchers::BuiltIn::Compound::And.
|
68
|
-
new(self, UriTemplateHasVariablesMatcher.new(self, vars))
|
64
|
+
self.class.new(link_rel, UriTemplateHasVariablesMatcher.new(vars))
|
69
65
|
end
|
70
66
|
alias_method :with_variable, :with_variables
|
71
67
|
|
@@ -5,39 +5,47 @@ module RSpec
|
|
5
5
|
module Hal
|
6
6
|
module Matchers
|
7
7
|
class UriTemplateHasVariablesMatcher
|
8
|
-
def initialize(
|
9
|
-
@tmpl_matcher = a_tmpl_relation_matcher
|
8
|
+
def initialize(vars)
|
10
9
|
@expected_vars = Set.new(vars)
|
11
10
|
end
|
12
11
|
|
13
12
|
def matches?(actual)
|
13
|
+
self.actual_tmpl = actual
|
14
|
+
|
14
15
|
expected_vars.subset? actual_vars
|
15
16
|
end
|
16
17
|
|
17
18
|
def description
|
18
|
-
"have variables #{expected_vars
|
19
|
+
"have variables #{as_human_list(expected_vars)}"
|
19
20
|
end
|
20
21
|
|
21
22
|
def failure_message
|
22
|
-
"Expected #{actual_tmpl.
|
23
|
+
"Expected #{actual_tmpl.pattern} to have #{as_human_list(expected_vars)}"
|
23
24
|
end
|
24
25
|
|
25
26
|
def failure_message_when_negated
|
26
|
-
"Expected #{actual_tmpl.
|
27
|
+
"Expected #{actual_tmpl.pattern} not to have #{as_human_list(expected_vars)}"
|
27
28
|
end
|
28
29
|
|
29
30
|
protected
|
30
31
|
|
31
|
-
attr_reader :tmpl_matcher, :expected_vars
|
32
|
+
attr_reader :tmpl_matcher, :expected_vars, :actual_tmpl
|
32
33
|
|
33
|
-
def actual_tmpl
|
34
|
-
|
34
|
+
def actual_tmpl=(a_template)
|
35
|
+
@actual_tmpl = if a_template.respond_to? :pattern
|
36
|
+
actual_tmpl
|
37
|
+
else
|
38
|
+
Addressable::Template.new(a_template)
|
39
|
+
end
|
35
40
|
end
|
36
41
|
|
37
42
|
def actual_vars
|
38
43
|
Set.new(actual_tmpl.variables)
|
39
44
|
end
|
40
45
|
|
46
|
+
def as_human_list(enum)
|
47
|
+
enum.to_a.join(", ")
|
48
|
+
end
|
41
49
|
end
|
42
50
|
end
|
43
51
|
end
|
data/lib/rspec/hal/matchers.rb
CHANGED
@@ -8,6 +8,7 @@ module RSpec
|
|
8
8
|
require "rspec/hal/matchers/relation_matcher"
|
9
9
|
require "rspec/hal/matchers/templated_relation_matcher"
|
10
10
|
require "rspec/hal/matchers/have_property_matcher"
|
11
|
+
require "rspec/hal/matchers/uri_template_has_variables_matcher"
|
11
12
|
|
12
13
|
# Examples
|
13
14
|
#
|
@@ -47,6 +48,20 @@ module RSpec
|
|
47
48
|
HavePropertyMatcher.new(*args)
|
48
49
|
end
|
49
50
|
|
51
|
+
# Signature
|
52
|
+
#
|
53
|
+
# expect(a_uri_template_str).to have_variables "q", "limit"
|
54
|
+
def have_variables(*args)
|
55
|
+
UriTemplateHasVariablesMatcher.new(*args)
|
56
|
+
end
|
57
|
+
|
58
|
+
# Signature
|
59
|
+
#
|
60
|
+
# expect(a_uri_template_str).to has_variable "q"
|
61
|
+
def has_variable(*args)
|
62
|
+
UriTemplateHasVariablesMatcher.new(*args)
|
63
|
+
end
|
64
|
+
|
50
65
|
module Document
|
51
66
|
extend RSpec::Matchers::DSL
|
52
67
|
|
data/lib/rspec/hal/version.rb
CHANGED
@@ -23,20 +23,8 @@ describe RSpec::Hal::Matchers::TemplatedRelationMatcher do
|
|
23
23
|
|
24
24
|
specify { expect(matcher.description).to match "have templated #{a_link_rel} link" }
|
25
25
|
|
26
|
-
|
27
|
-
|
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
|
26
|
+
specify { expect(matcher.with_variables("since", "before")).to be_a_matcher }
|
27
|
+
specify { expect(matcher.with_variable("since")).to be_a_matcher }
|
40
28
|
|
41
29
|
context "failed due to missing relation matcher" do
|
42
30
|
before do
|
@@ -3,22 +3,26 @@ require "rspec/version"
|
|
3
3
|
|
4
4
|
describe RSpec::Hal::Matchers::UriTemplateHasVariablesMatcher do
|
5
5
|
describe "creation" do
|
6
|
-
specify { expect{ described_class.new(
|
6
|
+
specify { expect{ described_class.new(["foo"]) }.
|
7
7
|
not_to raise_error }
|
8
8
|
end
|
9
9
|
|
10
|
-
subject(:matcher) { described_class.new(
|
10
|
+
subject(:matcher) { described_class.new(["foo", "bar"]) }
|
11
11
|
|
12
|
-
|
13
|
-
|
12
|
+
specify { expect(matcher.matches?("http://example.com{?foo,bar}")).to be_truthy }
|
13
|
+
specify { expect(matcher.matches?("http://example.com{?foo}")).to be_falsy }
|
14
|
+
specify { expect(matcher.description).to match /foo, bar/ }
|
14
15
|
|
15
|
-
|
16
|
+
describe "failed matcher" do
|
17
|
+
before do matcher.matches?("http://example.com{?foo}") end
|
18
|
+
|
19
|
+
specify { expect(matcher.failure_message).to match /foo, bar/ }
|
16
20
|
end
|
17
21
|
|
18
|
-
|
19
|
-
|
22
|
+
describe "passed matcher" do
|
23
|
+
before do matcher.matches?("http://example.com{?foo,bar}") end
|
20
24
|
|
21
|
-
specify { expect(matcher.
|
25
|
+
specify { expect(matcher.failure_message_when_negated).to match /foo, bar/ }
|
22
26
|
end
|
23
27
|
|
24
28
|
# Background
|