rspec-raml 0.1.3 → 0.1.4

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: ff971a245a14b37efeb8b65df683b7934efc1de8
4
- data.tar.gz: 4532bec8ccfe0815fa04c505561c9f344b8adc7a
3
+ metadata.gz: 7de945d07b40d207a1b110b76a995b6c3a552c08
4
+ data.tar.gz: 10195e8ffcf8b88ba2ac1f0ab398120a3bf811b3
5
5
  SHA512:
6
- metadata.gz: f207d241cbf7505f24f69fefd1d8fc55e0af85efa551d290ea1b539dfed38fe487a910bb899d686e9a9e121c08571f0e34ed3a897e6827a01bef10c1c2d95aa4
7
- data.tar.gz: a53252fab901a64d8f1980bdeb775470c96b427fe499b609399f8907936d3b6d247cf05133383b85fce5d7b2f0ecd4d8f0da90ae8431e2db981760a6507dbd50
6
+ metadata.gz: 31da8166980933912104a0783a75e577155a8bea07302edf79adb76be2986d1faf61a23d13991bb09a16b5bd99e825705ba9968c7ae32270a46068eba016e6de
7
+ data.tar.gz: 0a4d867a376e43e8dcc6fdf51724dc183ee910d320b23acd7888e233fa87a579f08b15e1649b2a4b94be82bf2160b4e00cabba527c95df044fafd7e803f60b16
data/Gemfile CHANGED
@@ -2,3 +2,4 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in rspec-raml.gemspec
4
4
  gemspec
5
+ gem 'pry'
@@ -0,0 +1,49 @@
1
+ module RSpec
2
+ module Raml
3
+ class ExclusionFilter
4
+ ANYTHING = RSpec::Mocks::ArgumentMatchers::AnyArgMatcher::INSTANCE
5
+
6
+ def initialize(excludes)
7
+ @excludes = excludes
8
+ end
9
+
10
+ def filter(object)
11
+ @excludes.reduce object do |acc, exclude|
12
+ replace(acc, exclude)
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ def replace(body, exclude)
19
+ case exclude
20
+ when Hash
21
+ replace_hash(body, exclude)
22
+ when Array
23
+ replace_array(body, exclude)
24
+ when Symbol, String
25
+ body.merge(exclude.to_s => ANYTHING)
26
+ else
27
+ body
28
+ end
29
+ end
30
+
31
+ def replace_hash(body, exclude)
32
+ exclude.reduce(body) do |acc, (k, v)|
33
+ acc.merge(k.to_s => replace(acc[k.to_s], v))
34
+ end
35
+ end
36
+
37
+ def replace_array(body, exclude)
38
+ case body
39
+ when Array
40
+ body.map { |item| replace(item, exclude) }
41
+ when Hash
42
+ exclude.reduce(body) { |acc, key| replace(acc, key) }
43
+ else
44
+ body
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -1,3 +1,4 @@
1
+ require 'rspec/raml/exclusion_filter'
1
2
  require 'rspec/raml/matchers/abstract'
2
3
 
3
4
  module RSpec
@@ -6,24 +7,22 @@ module RSpec
6
7
  class MatchRamlBody < Abstract
7
8
  def initialize(*)
8
9
  super
9
- @except = []
10
+ @excludes = []
11
+ @differ = RSpec::Support::Differ.new(color: true)
10
12
  end
11
13
 
12
14
  def description
13
15
  'match RAML body'
14
16
  end
15
17
 
16
- def except(*keys)
17
- @except |= keys.map(&:to_s)
18
+ def exclude(*values)
19
+ @excludes += values
18
20
  self
19
21
  end
22
+ alias except exclude
20
23
 
21
24
  def failure_message
22
- diff = differ.diff_as_object(
23
- response_body,
24
- raml_body
25
- )
26
-
25
+ diff = @differ.diff_as_object(actual, expected)
27
26
  "expected response bodies to match:#{diff}"
28
27
  end
29
28
 
@@ -34,34 +33,22 @@ module RSpec
34
33
  private
35
34
 
36
35
  def matches_raml?
37
- response_body == raml_body
38
- end
39
-
40
- def response_body
41
- @response_body ||= comparable(response.body)
36
+ RSpec::Support::FuzzyMatcher.values_match?(expected, actual)
42
37
  end
43
38
 
44
- def raml_body
45
- @raml_body ||= comparable(raml.bodies.fetch(content_type).example)
39
+ def actual
40
+ @actual ||= JSON.parse(response.body)
46
41
  end
47
42
 
48
- def differ
49
- @differ ||= RSpec::Support::Differ.new(color: true)
50
- end
51
-
52
- def comparable(body)
53
- remove_exceptions JSON.parse(body)
43
+ def expected
44
+ @expected ||= begin
45
+ example = raml.bodies.fetch(content_type).example
46
+ exclusion_filter.filter JSON.parse(example)
47
+ end
54
48
  end
55
49
 
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
50
+ def exclusion_filter
51
+ ExclusionFilter.new(@excludes)
65
52
  end
66
53
  end
67
54
  end
@@ -1,5 +1,5 @@
1
1
  module Rspec
2
2
  module Raml
3
- VERSION = '0.1.3'
3
+ VERSION = '0.1.4'
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.3
4
+ version: 0.1.4
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-09 00:00:00.000000000 Z
11
+ date: 2017-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: raml_ruby
@@ -82,6 +82,7 @@ files:
82
82
  - Rakefile
83
83
  - lib/rspec-raml.rb
84
84
  - lib/rspec/raml.rb
85
+ - lib/rspec/raml/exclusion_filter.rb
85
86
  - lib/rspec/raml/finder.rb
86
87
  - lib/rspec/raml/matchers.rb
87
88
  - lib/rspec/raml/matchers/abstract.rb
@@ -112,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
113
  version: '0'
113
114
  requirements: []
114
115
  rubyforge_project:
115
- rubygems_version: 2.4.8
116
+ rubygems_version: 2.6.10
116
117
  signing_key:
117
118
  specification_version: 4
118
119
  summary: RSpec matchers for working with RAML.