GithubHelp home page GithubHelp logo

mariochavez / rack-minitest Goto Github PK

View Code? Open in Web Editor NEW

This project forked from brandonweiss/rack-minitest

0.0 2.0 0.0 183 KB

Adds convenience methods for dealing with JSON to rack-test and MiniTest spec-style matchers for checking response statuses

License: MIT License

Ruby 100.00%

rack-minitest's Introduction

rack-minitest

rack-minitest = rack-test + Minitest. See what I did there?

This gem adds some convenience methods to rack-test and Minitest that I found myself duplicating over and over for every application I wrote. It adds a few methods for dealing with JSON to rack-test, Minitest assertions, and spec-style matchers for checking response status. The specific methods are:

# json
last_json_response

get_json    path, params, headers
post_json   path, params, headers
put_json    path, params, headers
delete_json path, params, headers

# assertions
assert_ok
assert_created
assert_no_content
assert_moved_permanently
assert_bad_request
assert_unauthorized
assert_forbidden
assert_not_found
assert_unprocessable_entity
assert_internal_server_error

# matchers
last_response.must_be_ok
last_response.must_be_created
last_response.must_be_no_content
last_response.must_be_moved_permanently
last_response.must_be_bad_request
last_response.must_be_unauthorized
last_response.must_be_forbidden
last_response.must_be_not_found
last_response.must_be_unprocessable_entity
last_response.must_be_internal_server_error

NB: This is a quick and dirty gem to hack in some functionality that I was surprised to find didn't already exist. There are tests, and they pass, but they're pretty gross. All improvements are welcome.

Requirements

Installation

Add this line to your application's Gemfile:

gem "rack-minitest", git: "git://github.com/brandonweiss/rack-minitest.git"

And then execute:

$ bundle

Usage

You can use rack-minitest in one of two ways.

Require only the modules you need

require "rack-minitest/json"
require "rack-minitest/assertions"

class MyTestClass < Minitest::Test
  include Rack::Test::Methods
  include Rack::Minitest::JSON
  include Rack::Minitest::Assertions

  # use rack/test, the json methods, and assertions
end

All in one

require "rack-minitest/test"

describe SomeTestClass do
  # adds rack-test and all the rack-minitest modules
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

rack-minitest's People

Contributors

elskwid avatar brandonweiss avatar mariochavez avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.