rspec-hal 1.0.1 → 1.1.0
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.rb +37 -3
- data/lib/rspec/hal/version.rb +1 -1
- data/spec/rspec/hal/matchers_spec.rb +21 -19
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9463991d7f7b862e2979e8f110458daa8a005f8f
|
4
|
+
data.tar.gz: a28bf60caeb1602ea86ee49bf70cfbb87e6a14bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 459b268f52a050327e80253dbffd0d9172f2c7ecf81b2687eb2953fcc0f7281dd4eea58efbf74e4d32ccd14731e18a099abf4231bb76e9713a5fae00e3dc0ae0
|
7
|
+
data.tar.gz: e48f6a959f34e8db673a2db0995b3c2cd5cde16f2e9b73c9bde3f76a42f119ca57d628df284dabd21ec3ffadfe6ba1548a9c4b99b78d7793a304ea411a1994f3
|
data/lib/rspec/hal/matchers.rb
CHANGED
@@ -69,6 +69,8 @@ module RSpec
|
|
69
69
|
# Signature
|
70
70
|
#
|
71
71
|
# expect(a_user_doc).to have_property "name"
|
72
|
+
# expect(a_user_doc).to have_property("name").that_is("Bob")
|
73
|
+
# expect(a_user_doc).to have_property("age").that_is kind_of Numeric
|
72
74
|
# expect(a_user_doc).to have_property("name").matching(/bob/i)
|
73
75
|
# expect(a_user_doc).to have_property("hobbies").including(matching("golf"))
|
74
76
|
matcher :have_property do |prop_name|
|
@@ -81,16 +83,31 @@ module RSpec
|
|
81
83
|
__value_matcher === a_doc.fetch(prop_name)
|
82
84
|
end
|
83
85
|
|
86
|
+
chain :that_is do |expected_val|
|
87
|
+
@value_matcher = expected_val
|
88
|
+
end
|
89
|
+
|
84
90
|
chain :matching do |val_pat|
|
85
|
-
@value_matcher = val_pat
|
91
|
+
@value_matcher = if Regexp === val_pat
|
92
|
+
RSpec::Matchers::BuiltIn::Match.new val_pat
|
93
|
+
else
|
94
|
+
val_pat
|
95
|
+
end
|
86
96
|
end
|
87
97
|
|
88
98
|
chain :including do |val_pat|
|
89
99
|
@value_matcher = RSpec::Matchers::BuiltIn::Include.new val_pat
|
90
100
|
end
|
91
101
|
|
102
|
+
failure_message do
|
103
|
+
msg = super()
|
104
|
+
if @value_matcher
|
105
|
+
msg + " " + @value_matcher.description.gsub(/^match /, "matching ")
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
92
109
|
define_method(:__value_matcher) do
|
93
|
-
@value_matcher
|
110
|
+
@value_matcher || ->(*_){ true }
|
94
111
|
end
|
95
112
|
end
|
96
113
|
|
@@ -106,11 +123,28 @@ module RSpec
|
|
106
123
|
repr = HalClient::Representation.new(parsed_json: a_doc)
|
107
124
|
|
108
125
|
begin
|
109
|
-
repr.related_hrefs(link_rel).any?
|
126
|
+
repr.related_hrefs(link_rel) .any?{|an_href|
|
127
|
+
next true if !defined? @href_matcher
|
128
|
+
@href_matcher === an_href
|
129
|
+
}
|
110
130
|
rescue KeyError
|
111
131
|
false
|
112
132
|
end
|
113
133
|
end
|
134
|
+
|
135
|
+
chain :with_href do |expected_href|
|
136
|
+
(fail ArgumentError, "#{expected_href.inspect} must be a matcher") unless expected_href.respond_to? :matches?
|
137
|
+
|
138
|
+
@href_matcher = expected_href
|
139
|
+
end
|
140
|
+
|
141
|
+
failure_message do
|
142
|
+
msg = super()
|
143
|
+
if @href_matcher
|
144
|
+
msg + " with href " + @href_matcher.description.gsub(/^match /, "matching ")
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
114
148
|
end
|
115
149
|
end
|
116
150
|
end
|
data/lib/rspec/hal/version.rb
CHANGED
@@ -1,43 +1,45 @@
|
|
1
1
|
require_relative "../../spec_helper"
|
2
|
+
require "rspec/version"
|
2
3
|
|
3
4
|
describe RSpec::Hal::Matchers::Document do
|
4
5
|
describe "be_hal" do
|
5
6
|
subject(:matcher) { be_hal }
|
6
7
|
|
7
|
-
specify { expect(matcher.matches?(hal_doc)).to
|
8
|
-
specify { expect(matcher.matches?("What's HAL?")).to
|
8
|
+
specify { expect(matcher.matches?(hal_doc)).to be_truthy }
|
9
|
+
specify { expect(matcher.matches?("What's HAL?")).to be_falsey }
|
9
10
|
end
|
10
11
|
|
11
12
|
describe "be_hal_collection" do
|
12
13
|
subject(:matcher) { be_hal_collection }
|
13
14
|
|
14
|
-
specify { expect(matcher.matches?(hal_collection)).to
|
15
|
-
specify { expect(matcher.matches?("What's HAL?")).to
|
16
|
-
specify { expect(matcher.matches?(hal_doc)).to
|
15
|
+
specify { expect(matcher.matches?(hal_collection)).to be_truthy }
|
16
|
+
specify { expect(matcher.matches?("What's HAL?")).to be_falsey }
|
17
|
+
specify { expect(matcher.matches?(hal_doc)).to be_falsey }
|
17
18
|
end
|
18
19
|
|
19
20
|
describe "have_property('name')" do
|
20
21
|
subject(:matcher) { have_property('name') }
|
21
22
|
|
22
|
-
specify { expect(matcher.matches?(hal_doc)).to
|
23
|
-
specify { expect(matcher.matches?("{}")).to
|
23
|
+
specify { expect(matcher.matches?(hal_doc)).to be_truthy}
|
24
|
+
specify { expect(matcher.matches?("{}")).to be_falsey}
|
24
25
|
end
|
25
26
|
|
26
27
|
describe "have_property('name').matching(/ice$/)" do
|
27
28
|
subject(:matcher) { have_property('name').matching(/ice$/) }
|
28
29
|
|
29
|
-
specify { expect(matcher.matches?(hal_doc)).to
|
30
|
-
specify { expect(matcher.matches?("{}")).to
|
31
|
-
specify { expect(matcher.matches?(bob)).to
|
30
|
+
specify { expect(matcher.matches?(hal_doc)).to be_truthy}
|
31
|
+
specify { expect(matcher.matches?("{}")).to be_falsey}
|
32
|
+
specify { expect(matcher.matches?(bob)).to be_falsey}
|
32
33
|
end
|
33
34
|
|
34
35
|
describe "have_property('name').matching(end_with('ice'))" do
|
36
|
+
before do skip("RSpec 3 feature") unless /3\./ === RSpec::Version::STRING end
|
35
37
|
subject(:matcher) { have_property('name')
|
36
38
|
.matching(RSpec::Matchers::BuiltIn::EndWith.new("ice")) }
|
37
39
|
|
38
|
-
specify { expect(matcher.matches?(hal_doc)).to
|
39
|
-
specify { expect(matcher.matches?("{}")).to
|
40
|
-
specify { expect(matcher.matches?(bob)).to
|
40
|
+
specify { expect(matcher.matches?(hal_doc)).to be_truthy}
|
41
|
+
specify { expect(matcher.matches?("{}")).to be_falsey}
|
42
|
+
specify { expect(matcher.matches?(bob)).to be_falsey}
|
41
43
|
end
|
42
44
|
|
43
45
|
describe "have_property('hobbies').including(a_hash_including('type' => 'sport'))" do
|
@@ -45,17 +47,17 @@ describe RSpec::Hal::Matchers::Document do
|
|
45
47
|
.including(RSpec::Matchers::BuiltIn::Include.new('type' => 'sport')) }
|
46
48
|
before do extend described_class end
|
47
49
|
|
48
|
-
specify { expect(matcher.matches?(hal_doc)).to
|
49
|
-
specify { expect(matcher.matches?("{}")).to
|
50
|
-
specify { expect(matcher.matches?(bob)).to
|
50
|
+
specify { expect(matcher.matches?(hal_doc)).to be_truthy}
|
51
|
+
specify { expect(matcher.matches?("{}")).to be_falsey}
|
52
|
+
specify { expect(matcher.matches?(bob)).to be_falsey}
|
51
53
|
end
|
52
54
|
|
53
55
|
describe "have_relation('tag')" do
|
54
56
|
subject(:matcher) { have_relation('tag') }
|
55
57
|
|
56
|
-
specify { expect(matcher.matches?(hal_doc)).to
|
57
|
-
specify { expect(matcher.matches?("{}")).to
|
58
|
-
specify { expect(matcher.matches?(bob)).to
|
58
|
+
specify { expect(matcher.matches?(hal_doc)).to be_truthy}
|
59
|
+
specify { expect(matcher.matches?("{}")).to be_falsey}
|
60
|
+
specify { expect(matcher.matches?(bob)).to be_falsey}
|
59
61
|
end
|
60
62
|
|
61
63
|
|
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.0
|
4
|
+
version: 1.1.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-03-
|
11
|
+
date: 2014-03-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|