Skip to content

Instantly share code, notes, and snippets.

@kevgathuku
Forked from psobocinski/dummy_controller.rb
Created August 9, 2022 06:51
Show Gist options
  • Save kevgathuku/5ba243070332a8e9f7a52e780163b6c7 to your computer and use it in GitHub Desktop.
Save kevgathuku/5ba243070332a8e9f7a52e780163b6c7 to your computer and use it in GitHub Desktop.
Asserting on a JSON response in a Rails controller test with MiniTest
class DummyController < ApplicationController
def do
render json: { balance: 50 }
end
end
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