-
-
Save 3014zhangshuo/d247f9a63a1ea321e84a4b85c1d83c7a to your computer and use it in GitHub Desktop.
Asserting on a JSON response in a Rails controller test with MiniTest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DummyController < ApplicationController | |
def do | |
render json: { balance: 50 } | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'test_helper' | |
class DummyControllerTest < ActionController::TestCase | |
test "should get do" do | |
get :do | |
json_response = JSON.parse(response.body) | |
assert_equal 50, json_response["balance"] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment