This is my action:
def my_action
str = ... # get json str somehow
render :json => str
end
This is my test:
test "my test" do
post(:my_action, {'param' => "value"}
assert_response :success
end
I want to add another assertion that the emitted JSON contains some value. How can I do it in a controller unit-test, not via parsing the view result?
Just like people commented above, this would be a functional test.
The best way would probably be making a request, parsing the JSON response body, and matching it to the expected result.
If I have
companies_controllerin Rspec using FactoryGirl:You can test other attributes the same way. Also, I normally have
invalidcontext where I would try to pass invalid parameters.