Skip to content
This repository was archived by the owner on Feb 16, 2018. It is now read-only.

tent/api-validator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ApiValidator Build Status

Framework for integration testing an API server.

Installation

Add this line to your application's Gemfile:

gem 'api-validator'

And then execute:

$ bundle

Or install it yourself as:

$ gem install api-validator

Usage

class MyValidation < ApiValidator::Spec

  def create_resource
    # ...
    set(:resource, data)
  end

  def fudge_resource
    # ...
    set(:resource, fudged_data)
  end

  describe "GET /posts/{entity}/{id}" do
    shared_examples :not_found do
      expect_response(:schema => :error, :status => 404) do
        # ...
        response
      end
    end

    context "when resource exists", :before => :create_resource do
      context "when authorized to read all posts" do
        authorize!(:server => :remote, :scopes => %w[ read_posts ], :read_types => %w[ all ])

        expect_response(:schema => :post, :status => 200) do
          expect_headers({ 'Content-Type' => /json\b/ })
          expect_properties(:entity => get(:resource, :entity), :id => get(:resource, :id))
          expect_schema(:post_content, "/content")

          # ...
          response
        end
      end

      context "when authorize to write resource but not read" do
        authorize!(:server => :remote, :scopes => %w[ write_posts ], :write_types => %w[ all ])
        behaves_as :not_found
      end

      context "when not authorized" do
        behaves_as :not_found
      end
    end

    context "when resource does not exist", :before => :fudge_resource do
      behaves_as :not_found
    end
  end

end

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages