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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e4f45bc788fb6dedb83b95f4e3c590675656f00f
4
- data.tar.gz: 32d538a5f870c291400fa3bd9a009b6b874d185c
3
+ metadata.gz: 459ebbc13de469d36a68fc9eecd02a9cdcc2db92
4
+ data.tar.gz: 0301e48952230c8ff6cda1058d7f23abf3293380
5
5
  SHA512:
6
- metadata.gz: 5d7d17141a06542082de424a0e5d435137fab68c4bff5a6dcabc568aa1c72aef7d4086a86539bf96a8a953865135c0a529982b4703c60f26780969b9da1e3b9a
7
- data.tar.gz: a07578234ce02b41184b1e049a00f7d83307f978d040101bb9eb21b3951288e0668f63b5a19318f8ace245425042d3f602fe9217b1d8a36451d6cb039ada178b
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
- 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))
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(a_tmpl_relation_matcher, vars)
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.join(", ")}"
19
+ "have variables #{as_human_list(expected_vars)}"
19
20
  end
20
21
 
21
22
  def failure_message
22
- "Expected #{actual_tmpl.to_s} to have #{expected_vars.join(", ")}"
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.to_s} not to have #{expected_vars.join(", ")}"
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
- Addressable::Template.new(tmpl_matcher.uri_template)
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
@@ -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
 
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module Hal
3
- VERSION = "1.3.0"
3
+ VERSION = "1.3.1"
4
4
  end
5
5
  end
@@ -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
- 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
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(a_templated_relation_matcher, ["foo"]) }.
6
+ specify { expect{ described_class.new(["foo"]) }.
7
7
  not_to raise_error }
8
8
  end
9
9
 
10
- subject(:matcher) { described_class.new(a_templated_relation_matcher, ["foo", "bar"]) }
10
+ subject(:matcher) { described_class.new(["foo", "bar"]) }
11
11
 
12
- context "template with required variables" do
13
- let(:template) { "http://example.com{?foo,bar}" }
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
- specify { expect(matcher.matches?(json_doc_that_is_ignored)).to be_truthy }
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
- context "template missing one required variabl" do
19
- let(:template) { "http://example.com{?foo}" }
22
+ describe "passed matcher" do
23
+ before do matcher.matches?("http://example.com{?foo,bar}") end
20
24
 
21
- specify { expect(matcher.matches?(json_doc_that_is_ignored)).to be_falsy }
25
+ specify { expect(matcher.failure_message_when_negated).to match /foo, bar/ }
22
26
  end
23
27
 
24
28
  # Background
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-hal
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Williams