rspec-hal 1.2.4 → 1.3.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: 185977ddedcf97a48cf29d25a4318265b25eca10
4
- data.tar.gz: 70f92063554495e242b6f875a69a1730a8b7e0ff
3
+ metadata.gz: e4f45bc788fb6dedb83b95f4e3c590675656f00f
4
+ data.tar.gz: 32d538a5f870c291400fa3bd9a009b6b874d185c
5
5
  SHA512:
6
- metadata.gz: 716f0875b0f39b16e705b8c42c03c88693e6a3e5dd14393593cadf48fa4fc1ee716c54e481c04ce18c62d8204a56ea3e985b2d1e1b56ddffae7bf87e8d0fc2ed
7
- data.tar.gz: b1923ce334d1fb91b33f8b601c1112ad54761faa3ef1f9199b97b4922e2a8ff90688a977053ec6626161652ae8e3e9aaa933f5b73551a79cac2d7a59b4f536ca
6
+ metadata.gz: 5d7d17141a06542082de424a0e5d435137fab68c4bff5a6dcabc568aa1c72aef7d4086a86539bf96a8a953865135c0a529982b4703c60f26780969b9da1e3b9a
7
+ data.tar.gz: a07578234ce02b41184b1e049a00f7d83307f978d040101bb9eb21b3951288e0668f63b5a19318f8ace245425042d3f602fe9217b1d8a36451d6cb039ada178b
data/Gemfile CHANGED
@@ -1,7 +1,8 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  #gem "rspec", "~>2.14"
4
- gem "rspec", "~>3.0.0.beta"
4
+ #gem "rspec", "~>3.0.0.beta"
5
+ gem "rspec", "~>3.0"
5
6
 
6
7
  # Specify your gem's dependencies in rspec-hal.gemspec
7
8
  gemspec
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
- [![Build Status](https://travis-ci.org/pezra/hal-interpretation.png?branch=master)](https://travis-ci.org/pezra/hal-interpretation)
2
- [![Code Climate](https://codeclimate.com/github/pezra/hal-interpretation.png)](https://codeclimate.com/github/pezra/hal-interpretation)
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", matching("{?q}"))
39
+ expect(a_user_doc).to have_templated_relation("search").with_variables("q", "limit")
40
40
  ```
41
41
 
42
42
  ## Installation
@@ -1,6 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem "rspec", "~>3.0.0.beta"
3
+ gem "rspec", "~>3.0"
4
4
 
5
5
  # Specify your gem's dependencies in rspec-hal.gemspec
6
6
  gemspec path: ".."
@@ -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
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module Hal
3
- VERSION = "1.2.4"
3
+ VERSION = "1.3.0"
4
4
  end
5
5
  end
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.pre"
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.2.4
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-07-10 00:00:00.000000000 Z
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.pre
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.pre
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