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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d42425270b70e6c59a6d6f3d86404e4fabb0ead3
4
- data.tar.gz: 89c326dffacabb1cd92a41989ae7b696041b1ee9
3
+ metadata.gz: 9463991d7f7b862e2979e8f110458daa8a005f8f
4
+ data.tar.gz: a28bf60caeb1602ea86ee49bf70cfbb87e6a14bf
5
5
  SHA512:
6
- metadata.gz: b2dacceb11c4904321a1f9157200c2f9c13394e573361feafb0559c8e4cc7fbf5df164823da0a473eeab0c2078044fbb08b465b07232ec95d362c4e0bbe0a370
7
- data.tar.gz: c69e18dfcfc05bc446d4aa958ca8cb82a81ad86aa891cdded1145fc015e7f01de8c08c314861898fce91db0144255948187e98a5faea08a6b48660a5e693010c
6
+ metadata.gz: 459b268f52a050327e80253dbffd0d9172f2c7ecf81b2687eb2953fcc0f7281dd4eea58efbf74e4d32ccd14731e18a099abf4231bb76e9713a5fae00e3dc0ae0
7
+ data.tar.gz: e48f6a959f34e8db673a2db0995b3c2cd5cde16f2e9b73c9bde3f76a42f119ca57d628df284dabd21ec3ffadfe6ba1548a9c4b99b78d7793a304ea411a1994f3
@@ -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 ||= ->(*_){ true }
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
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module Hal
3
- VERSION = "1.0.1"
3
+ VERSION = "1.1.0"
4
4
  end
5
5
  end
@@ -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 be true }
8
- specify { expect(matcher.matches?("What's HAL?")).to be false }
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 be true }
15
- specify { expect(matcher.matches?("What's HAL?")).to be false }
16
- specify { expect(matcher.matches?(hal_doc)).to be false }
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 be true}
23
- specify { expect(matcher.matches?("{}")).to be false}
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 be true}
30
- specify { expect(matcher.matches?("{}")).to be false}
31
- specify { expect(matcher.matches?(bob)).to be false}
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 be true}
39
- specify { expect(matcher.matches?("{}")).to be false}
40
- specify { expect(matcher.matches?(bob)).to be false}
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 be true}
49
- specify { expect(matcher.matches?("{}")).to be false}
50
- specify { expect(matcher.matches?(bob)).to be false}
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 be true}
57
- specify { expect(matcher.matches?("{}")).to be false}
58
- specify { expect(matcher.matches?(bob)).to be false}
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.1
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-24 00:00:00.000000000 Z
11
+ date: 2014-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler