No commit activity in last 3 years
No release in over 3 years
Add useful JSON assertions to your Rails controller tests.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
~> 4.2
~> 0

Runtime

 Project Readme

WorkableJsonAssertions

This gem adds basic JSON assertions to your controller tests.

Installation

Add this line to your application's Gemfile:

group :test do
  gem 'workable_json_assertions'
end

And then execute:

$ bundle

Or install it yourself as:

$ gem install workable_json_assertions

Usage

assert_json_response_empty

class BasicControllerTest < ActionController::TestCase
  def test_success
    get :index # {}
    assert_json_response_empty
  end
end

assert_json_response_equal

class BasicControllerTest < ActionController::TestCase
  def test_success
    get :index # { 'key': 'value' }
    assert_json_response_equal { key: 'value' }
  end
end

assert_json_response_equal_except

class BasicControllerTest < ActionController::TestCase
  def test_success
    get :index # { 'key': 'value', 'created_at': '2016-07-25', 'updated_at': '2016-07-26' }
    assert_json_response_equal_except { key: 'value' }, %i(created_at updated_at)
  end
end

assert_json_response_includes

class BasicControllerTest < ActionController::TestCase
  def test_success
    get :index # { 'key': 'value', 'created_at': '2016-07-25', 'updated_at': '2016-07-26' }
    assert_json_response_includes({ key: 'value' })
    assert_json_response_includes({ created_at: '2016-07-25' })
  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