jsonapi-rspec 0.0.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 +7 -0
- data/README.md +65 -0
- data/lib/jsonapi/rspec/attributes.rb +25 -0
- data/lib/jsonapi/rspec/id.rb +9 -0
- data/lib/jsonapi/rspec/jsonapi_object.rb +12 -0
- data/lib/jsonapi/rspec/links.rb +25 -0
- data/lib/jsonapi/rspec/meta.rb +12 -0
- data/lib/jsonapi/rspec/relationships.rb +34 -0
- data/lib/jsonapi/rspec/type.rb +9 -0
- data/lib/jsonapi/rspec.rb +19 -0
- metadata +81 -0
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA1:
         | 
| 3 | 
            +
              metadata.gz: 2c18e0598e541bf12401287dfcaa86a8dac978bc
         | 
| 4 | 
            +
              data.tar.gz: 9043ba44228a6e7c2d655447baace7db637be81b
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: 137f12232b91ae146be8b7bf8ec73cf64c8259547cec667685010942da126054859a7045cea4dc0e4b07b5be14321ae2722705183be99aba7184864a2e0653cf
         | 
| 7 | 
            +
              data.tar.gz: 3b372af8e591982007a21bfa54dd7e96f2f4b577d8855ca870eca6832d1f9a0161d8d7b274d16497911a042f200c640080e9b71fd34d481f1c9d7b0023c432f9
         | 
    
        data/README.md
    ADDED
    
    | @@ -0,0 +1,65 @@ | |
| 1 | 
            +
            # jsonapi-rspec
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            RSpec matchers for [JSON API](http://jsonapi.org).
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            ## Status
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            [](https://badge.fury.io/rb/jsonapi-rspec)
         | 
| 8 | 
            +
            [](http://travis-ci.org/jsonapi-rb/jsonapi-rspec?branch=master)
         | 
| 9 | 
            +
            [](https://gitter.im/jsonapi-rb/Lobby)
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            ## Resources
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            * Chat: [gitter](http://gitter.im/jsonapi-rb)
         | 
| 14 | 
            +
            * Twitter: [@jsonapirb](http://twitter.com/jsonapirb)
         | 
| 15 | 
            +
             | 
| 16 | 
            +
            ## Installation
         | 
| 17 | 
            +
             | 
| 18 | 
            +
            Add the following to your application's Gemfile:
         | 
| 19 | 
            +
            ```ruby
         | 
| 20 | 
            +
            gem 'jsonapi-rspec'
         | 
| 21 | 
            +
            ```
         | 
| 22 | 
            +
            And then execute:
         | 
| 23 | 
            +
            ```
         | 
| 24 | 
            +
            $ bundle
         | 
| 25 | 
            +
            ```
         | 
| 26 | 
            +
             | 
| 27 | 
            +
            Add to your `spec/spec_helpers.rb`:
         | 
| 28 | 
            +
             | 
| 29 | 
            +
            ```ruby
         | 
| 30 | 
            +
            # spec/spec_helpers.rb
         | 
| 31 | 
            +
            RSpec.configure do |config|
         | 
| 32 | 
            +
              # ...
         | 
| 33 | 
            +
              config.include JSONAPI::RSpec
         | 
| 34 | 
            +
            end
         | 
| 35 | 
            +
            ```
         | 
| 36 | 
            +
             | 
| 37 | 
            +
            ## Usage and documentation
         | 
| 38 | 
            +
             | 
| 39 | 
            +
            Available matchers:
         | 
| 40 | 
            +
             | 
| 41 | 
            +
            * `expect(document['data']).to have_id('12')`
         | 
| 42 | 
            +
            * `expect(document['data']).to have_type('users')`
         | 
| 43 | 
            +
            * `expect(document['data']).to have_attributes(:name, :email)`
         | 
| 44 | 
            +
            * `expect(document['data']).to have_attribute(:name).with_value('Lucas')`
         | 
| 45 | 
            +
            * `expect(document['data']).to have_relationships(:posts, :comments)`
         | 
| 46 | 
            +
            * `expect(document['data']).to have_relationship(:posts).with_data([{ 'id' => '1', 'type' => 'posts' }])`
         | 
| 47 | 
            +
            * `expect(document['data']['relationships']['posts']).to have_links(:self, :related)`
         | 
| 48 | 
            +
            * `expect(document['data']).to have_link(:self).with_value('http://api.example.com/users/12')`
         | 
| 49 | 
            +
            * `expect(document).to have_meta`
         | 
| 50 | 
            +
            * `expect(document).to have_meta('foo' => 'bar')`
         | 
| 51 | 
            +
            * `expect(document).to have_jsonapi_object`
         | 
| 52 | 
            +
            * `expect(document).to have_jsonapi_object('version' => '1.0')`
         | 
| 53 | 
            +
             | 
| 54 | 
            +
            ## Advanced examples
         | 
| 55 | 
            +
             | 
| 56 | 
            +
            Checking for an included resource:
         | 
| 57 | 
            +
             | 
| 58 | 
            +
            ```ruby
         | 
| 59 | 
            +
            expect(response_body['included'])
         | 
| 60 | 
            +
              .to include(have_type('posts').and have_id('1'))
         | 
| 61 | 
            +
            ```
         | 
| 62 | 
            +
             | 
| 63 | 
            +
            ## License
         | 
| 64 | 
            +
             | 
| 65 | 
            +
            jsonapi-rspec is released under the [MIT License](http://www.opensource.org/licenses/MIT).
         | 
| @@ -0,0 +1,25 @@ | |
| 1 | 
            +
            module JSONAPI
         | 
| 2 | 
            +
              module RSpec
         | 
| 3 | 
            +
                module Attributes
         | 
| 4 | 
            +
                  ::RSpec::Matchers.define :have_attribute do |attr|
         | 
| 5 | 
            +
                    match do |actual|
         | 
| 6 | 
            +
                      (actual['attributes'] || {}).key?(attr.to_s) &&
         | 
| 7 | 
            +
                        (!@val_set || actual['attributes'][attr.to_s] == @val)
         | 
| 8 | 
            +
                    end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                    chain :with_value do |val|
         | 
| 11 | 
            +
                      @val_set = true
         | 
| 12 | 
            +
                      @val = val
         | 
| 13 | 
            +
                    end
         | 
| 14 | 
            +
                  end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                  ::RSpec::Matchers.define :have_attributes do |*attrs|
         | 
| 17 | 
            +
                    match do |actual|
         | 
| 18 | 
            +
                      return false unless actual.key?('attributes')
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                      attrs.all? { |attr| actual['attributes'].key?(attr.to_s) }
         | 
| 21 | 
            +
                    end
         | 
| 22 | 
            +
                  end
         | 
| 23 | 
            +
                end
         | 
| 24 | 
            +
              end
         | 
| 25 | 
            +
            end
         | 
| @@ -0,0 +1,25 @@ | |
| 1 | 
            +
            module JSONAPI
         | 
| 2 | 
            +
              module RSpec
         | 
| 3 | 
            +
                module Links
         | 
| 4 | 
            +
                  ::RSpec::Matchers.define :have_link do |link|
         | 
| 5 | 
            +
                    match do |actual|
         | 
| 6 | 
            +
                      actual.key?('links') && actual['links'].key?(link.to_s) &&
         | 
| 7 | 
            +
                        (!@val_set || actual['links'] == @val)
         | 
| 8 | 
            +
                    end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                    chain :with_value do |val|
         | 
| 11 | 
            +
                      @val_set = true
         | 
| 12 | 
            +
                      @val = val
         | 
| 13 | 
            +
                    end
         | 
| 14 | 
            +
                  end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                  ::RSpec::Matchers.define :have_links do |*links|
         | 
| 17 | 
            +
                    match do |actual|
         | 
| 18 | 
            +
                      return false unless actual.key?('links')
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                      links.all? { |link| actual['links'].key?(link) }
         | 
| 21 | 
            +
                    end
         | 
| 22 | 
            +
                  end
         | 
| 23 | 
            +
                end
         | 
| 24 | 
            +
              end
         | 
| 25 | 
            +
            end
         | 
| @@ -0,0 +1,34 @@ | |
| 1 | 
            +
            module JSONAPI
         | 
| 2 | 
            +
              module RSpec
         | 
| 3 | 
            +
                module Relationships
         | 
| 4 | 
            +
                  ::RSpec::Matchers.define :have_relationship do |rel|
         | 
| 5 | 
            +
                    match do |actual|
         | 
| 6 | 
            +
                      return false unless (actual['relationships'] || {}).key?(rel.to_s)
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                      !@data_set || actual['relationships'][rel.to_s]['data'] == @data_val
         | 
| 9 | 
            +
                    end
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                    chain :with_data do |val|
         | 
| 12 | 
            +
                      @data_set = true
         | 
| 13 | 
            +
                      @data_val = val
         | 
| 14 | 
            +
                    end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                    failure_message do |actual|
         | 
| 17 | 
            +
                      if !(actual['relationships'] || {}).key?(rel.to_s)
         | 
| 18 | 
            +
                        "expected #{actual} to have relationship #{rel}"
         | 
| 19 | 
            +
                      else
         | 
| 20 | 
            +
                        "expected #{actual['relationships'][rel.to_s]} to have data #{@data_val}"
         | 
| 21 | 
            +
                      end
         | 
| 22 | 
            +
                    end
         | 
| 23 | 
            +
                  end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                  ::RSpec::Matchers.define :have_relationships do |*rels|
         | 
| 26 | 
            +
                    match do |actual|
         | 
| 27 | 
            +
                      return false unless actual.key?('relationships')
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                      rels.all? { |rel| actual['relationships'].key?(rel) }
         | 
| 30 | 
            +
                    end
         | 
| 31 | 
            +
                  end
         | 
| 32 | 
            +
                end
         | 
| 33 | 
            +
              end
         | 
| 34 | 
            +
            end
         | 
| @@ -0,0 +1,19 @@ | |
| 1 | 
            +
            require 'jsonapi/rspec/id'
         | 
| 2 | 
            +
            require 'jsonapi/rspec/type'
         | 
| 3 | 
            +
            require 'jsonapi/rspec/attributes'
         | 
| 4 | 
            +
            require 'jsonapi/rspec/relationships'
         | 
| 5 | 
            +
            require 'jsonapi/rspec/links'
         | 
| 6 | 
            +
            require 'jsonapi/rspec/meta'
         | 
| 7 | 
            +
            require 'jsonapi/rspec/jsonapi_object'
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            module JSONAPI
         | 
| 10 | 
            +
              module RSpec
         | 
| 11 | 
            +
                include Id
         | 
| 12 | 
            +
                include Type
         | 
| 13 | 
            +
                include Attributes
         | 
| 14 | 
            +
                include Relationships
         | 
| 15 | 
            +
                include Links
         | 
| 16 | 
            +
                include Meta
         | 
| 17 | 
            +
                include JsonapiObject
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
            end
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,81 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: jsonapi-rspec
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 0.0.1
         | 
| 5 | 
            +
            platform: ruby
         | 
| 6 | 
            +
            authors:
         | 
| 7 | 
            +
            - Lucas Hosseini
         | 
| 8 | 
            +
            autorequire: 
         | 
| 9 | 
            +
            bindir: bin
         | 
| 10 | 
            +
            cert_chain: []
         | 
| 11 | 
            +
            date: 2017-09-14 00:00:00.000000000 Z
         | 
| 12 | 
            +
            dependencies:
         | 
| 13 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 14 | 
            +
              name: rspec
         | 
| 15 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 | 
            +
                requirements:
         | 
| 17 | 
            +
                - - ">="
         | 
| 18 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            +
                    version: '0'
         | 
| 20 | 
            +
              type: :development
         | 
| 21 | 
            +
              prerelease: false
         | 
| 22 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 | 
            +
                requirements:
         | 
| 24 | 
            +
                - - ">="
         | 
| 25 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 26 | 
            +
                    version: '0'
         | 
| 27 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 28 | 
            +
              name: rake
         | 
| 29 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 | 
            +
                requirements:
         | 
| 31 | 
            +
                - - ">="
         | 
| 32 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            +
                    version: '0'
         | 
| 34 | 
            +
              type: :development
         | 
| 35 | 
            +
              prerelease: false
         | 
| 36 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 | 
            +
                requirements:
         | 
| 38 | 
            +
                - - ">="
         | 
| 39 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 40 | 
            +
                    version: '0'
         | 
| 41 | 
            +
            description: Helpers for validating JSON API payloads
         | 
| 42 | 
            +
            email:
         | 
| 43 | 
            +
            - lucas.hosseini@gmail.com
         | 
| 44 | 
            +
            executables: []
         | 
| 45 | 
            +
            extensions: []
         | 
| 46 | 
            +
            extra_rdoc_files: []
         | 
| 47 | 
            +
            files:
         | 
| 48 | 
            +
            - README.md
         | 
| 49 | 
            +
            - lib/jsonapi/rspec.rb
         | 
| 50 | 
            +
            - lib/jsonapi/rspec/attributes.rb
         | 
| 51 | 
            +
            - lib/jsonapi/rspec/id.rb
         | 
| 52 | 
            +
            - lib/jsonapi/rspec/jsonapi_object.rb
         | 
| 53 | 
            +
            - lib/jsonapi/rspec/links.rb
         | 
| 54 | 
            +
            - lib/jsonapi/rspec/meta.rb
         | 
| 55 | 
            +
            - lib/jsonapi/rspec/relationships.rb
         | 
| 56 | 
            +
            - lib/jsonapi/rspec/type.rb
         | 
| 57 | 
            +
            homepage: https://github.com/jsonapi-rb/jsonapi-rspec
         | 
| 58 | 
            +
            licenses:
         | 
| 59 | 
            +
            - MIT
         | 
| 60 | 
            +
            metadata: {}
         | 
| 61 | 
            +
            post_install_message: 
         | 
| 62 | 
            +
            rdoc_options: []
         | 
| 63 | 
            +
            require_paths:
         | 
| 64 | 
            +
            - lib
         | 
| 65 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 66 | 
            +
              requirements:
         | 
| 67 | 
            +
              - - ">="
         | 
| 68 | 
            +
                - !ruby/object:Gem::Version
         | 
| 69 | 
            +
                  version: '0'
         | 
| 70 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 71 | 
            +
              requirements:
         | 
| 72 | 
            +
              - - ">="
         | 
| 73 | 
            +
                - !ruby/object:Gem::Version
         | 
| 74 | 
            +
                  version: '0'
         | 
| 75 | 
            +
            requirements: []
         | 
| 76 | 
            +
            rubyforge_project: 
         | 
| 77 | 
            +
            rubygems_version: 2.6.13
         | 
| 78 | 
            +
            signing_key: 
         | 
| 79 | 
            +
            specification_version: 4
         | 
| 80 | 
            +
            summary: RSpec matchers for JSON API.
         | 
| 81 | 
            +
            test_files: []
         |