rspec-raml 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8ba735f8794e66e94088432feccc98f1862bbb43
4
- data.tar.gz: e9865f89a7be1a54e3204af11e723a518b6569d2
3
+ metadata.gz: ff971a245a14b37efeb8b65df683b7934efc1de8
4
+ data.tar.gz: 4532bec8ccfe0815fa04c505561c9f344b8adc7a
5
5
  SHA512:
6
- metadata.gz: f149720d4648d75f0e719594a6ac6ebb2e25cf347531e49ddc1e64eef3b632fb013995bb9547180f29585d5d9e45847492bbaae9de0aaa5a3788246fb8db9a68
7
- data.tar.gz: b0b14b47bdcaa2d7fa74540be7e7e1351198a40f660866629a39ec15f5f62a4b2b298e367f978aa9d9674dce03a3ca13e6e3c3f3f0f0d544767ec929b7dd2251
6
+ metadata.gz: f207d241cbf7505f24f69fefd1d8fc55e0af85efa551d290ea1b539dfed38fe487a910bb899d686e9a9e121c08571f0e34ed3a897e6827a01bef10c1c2d95aa4
7
+ data.tar.gz: a53252fab901a64d8f1980bdeb775470c96b427fe499b609399f8907936d3b6d247cf05133383b85fce5d7b2f0ecd4d8f0da90ae8431e2db981760a6507dbd50
@@ -4,6 +4,10 @@ module RSpec
4
4
  module Raml
5
5
  module Matchers
6
6
  class BeRamlContentType < Abstract
7
+ def description
8
+ 'be RAML content type'
9
+ end
10
+
7
11
  def failure_message
8
12
  "expected RAML to declare a response for content type: #{content_type}"
9
13
  end
@@ -6,6 +6,10 @@ module RSpec
6
6
  class MatchRaml < Abstract
7
7
  delegate :failure_message, :failure_message_when_negated, to: :failure
8
8
 
9
+ def description
10
+ 'match RAML'
11
+ end
12
+
9
13
  private
10
14
 
11
15
  def matches_raml?
@@ -17,10 +21,25 @@ module RSpec
17
21
  end
18
22
 
19
23
  def matchers
20
- (RSpec::Raml::Matchers::MATCHERS - [self.class]).map do |matcher|
24
+ @matchers ||= (RSpec::Raml::Matchers::MATCHERS - [self.class]).map do |matcher|
21
25
  matcher.new(raml, verb, url, status)
22
26
  end
23
27
  end
28
+
29
+ def respond_to_missing?(meth, *)
30
+ matchers.any? { |m| m.respond_to?(meth) } || super
31
+ end
32
+
33
+ def method_missing(meth, *args, &block)
34
+ valid = matchers.any? do |matcher|
35
+ if matcher.respond_to?(meth)
36
+ matcher.send(meth, *args, &block)
37
+ true
38
+ end
39
+ end
40
+
41
+ valid ? self : super
42
+ end
24
43
  end
25
44
  end
26
45
  end
@@ -4,6 +4,20 @@ module RSpec
4
4
  module Raml
5
5
  module Matchers
6
6
  class MatchRamlBody < Abstract
7
+ def initialize(*)
8
+ super
9
+ @except = []
10
+ end
11
+
12
+ def description
13
+ 'match RAML body'
14
+ end
15
+
16
+ def except(*keys)
17
+ @except |= keys.map(&:to_s)
18
+ self
19
+ end
20
+
7
21
  def failure_message
8
22
  diff = differ.diff_as_object(
9
23
  response_body,
@@ -24,16 +38,31 @@ module RSpec
24
38
  end
25
39
 
26
40
  def response_body
27
- @response_body ||= JSON.parse(response.body)
41
+ @response_body ||= comparable(response.body)
28
42
  end
29
43
 
30
44
  def raml_body
31
- @raml_body ||= JSON.parse(raml.bodies.fetch(content_type).example)
45
+ @raml_body ||= comparable(raml.bodies.fetch(content_type).example)
32
46
  end
33
47
 
34
48
  def differ
35
49
  @differ ||= RSpec::Support::Differ.new(color: true)
36
50
  end
51
+
52
+ def comparable(body)
53
+ remove_exceptions JSON.parse(body)
54
+ end
55
+
56
+ def remove_exceptions(data)
57
+ case data
58
+ when Array
59
+ data.map { |item| remove_exceptions(item) }
60
+ when Hash
61
+ data.slice(*(data.keys - @except))
62
+ else
63
+ data
64
+ end
65
+ end
37
66
  end
38
67
  end
39
68
  end
@@ -4,6 +4,10 @@ module RSpec
4
4
  module Raml
5
5
  module Matchers
6
6
  class MatchRamlStatus < Abstract
7
+ def description
8
+ 'match RAML status'
9
+ end
10
+
7
11
  def failure_message
8
12
  "expected the response to have a #{raml.name} status code, but got #{response.status}"
9
13
  end
@@ -1,5 +1,5 @@
1
1
  module Rspec
2
2
  module Raml
3
- VERSION = '0.1.2'
3
+ VERSION = '0.1.3'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-raml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ray Zane
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-11-08 00:00:00.000000000 Z
11
+ date: 2016-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: raml_ruby