rspec-raml 0.1.3 → 0.1.4
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 +4 -4
 - data/Gemfile +1 -0
 - data/lib/rspec/raml/exclusion_filter.rb +49 -0
 - data/lib/rspec/raml/matchers/match_raml_body.rb +17 -30
 - data/lib/rspec/raml/version.rb +1 -1
 - metadata +4 -3
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 7de945d07b40d207a1b110b76a995b6c3a552c08
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 10195e8ffcf8b88ba2ac1f0ab398120a3bf811b3
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 31da8166980933912104a0783a75e577155a8bea07302edf79adb76be2986d1faf61a23d13991bb09a16b5bd99e825705ba9968c7ae32270a46068eba016e6de
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 0a4d867a376e43e8dcc6fdf51724dc183ee910d320b23acd7888e233fa87a579f08b15e1649b2a4b94be82bf2160b4e00cabba527c95df044fafd7e803f60b16
         
     | 
    
        data/Gemfile
    CHANGED
    
    
| 
         @@ -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 
     | 
    
         
            -
                      @ 
     | 
| 
      
 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  
     | 
| 
       17 
     | 
    
         
            -
                      @ 
     | 
| 
      
 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 
     | 
    
         
            -
                       
     | 
| 
       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  
     | 
| 
       45 
     | 
    
         
            -
                      @ 
     | 
| 
      
 39 
     | 
    
         
            +
                    def actual
         
     | 
| 
      
 40 
     | 
    
         
            +
                      @actual ||= JSON.parse(response.body)
         
     | 
| 
       46 
41 
     | 
    
         
             
                    end
         
     | 
| 
       47 
42 
     | 
    
         | 
| 
       48 
     | 
    
         
            -
                    def  
     | 
| 
       49 
     | 
    
         
            -
                      @ 
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
       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  
     | 
| 
       57 
     | 
    
         
            -
                       
     | 
| 
       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
         
     | 
    
        data/lib/rspec/raml/version.rb
    CHANGED
    
    
    
        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. 
     | 
| 
      
 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:  
     | 
| 
      
 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. 
     | 
| 
      
 116 
     | 
    
         
            +
            rubygems_version: 2.6.10
         
     | 
| 
       116 
117 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       117 
118 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       118 
119 
     | 
    
         
             
            summary: RSpec matchers for working with RAML.
         
     |