Sha256: ee70af74e9378261aaf0b447a6073c10c2f7860303ec92158fcc7663e054e646

Contents?: true

Size: 1.29 KB

Versions: 2

Compression:

Stored size: 1.29 KB

Contents

require 'test_helper'

class JsonControllerTest < ActionController::TestCase

  def test_json_response_empty
    process :empty_response
    assert_json_response_empty

    process :dummy_response
    assert_raise(ActiveSupport::TestCase::Assertion) do
      assert_json_response_empty
    end
  end

  def test_json_response_equal
    process :dummy_response
    assert_json_response_equal expected_response
    assert_raise(ActiveSupport::TestCase::Assertion) do
      assert_json_response_equal slightly_altered_expected_response
    end
  end

  def test_json_response_equal_except
    process :dummy_response
    assert_json_response_equal_except slightly_altered_expected_response, %i(three four)
    assert_raise(ActiveSupport::TestCase::Assertion) do
      assert_json_response_equal_except slightly_altered_expected_response, %i(one two)
    end
  end

  def test_json_response_includes
    process :another_response
    assert_json_response_includes({ name: 'John', instrument: 'Guitar' })
  end

  private

  def expected_response
    {
      one:    'John',
      two:    'Paul',
      three:  'George',
      four:   'Ringo'
    }
  end

  def slightly_altered_expected_response
    {
      one:    'John',
      two:    'Paul',
      three:  'George Harrison',
      four:   'Ringo Star'
    }
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
workable_json_assertions-0.1.2 test/controllers/json_controller_test.rb
workable_json_assertions-0.1.1 test/controllers/json_controller_test.rb