I have a Rails 3.0.7 application. In the functional test I have following code. I am not using rspec or anything. This is plain vanilla functional test that comes with rails.
assert_response :success
Above assertion is passing. However I need to assert on the full content that is returned as the body of the response. How do I access the response body?
What is Minitest? Minitest is a testing tool for Ruby that provides a complete suite of testing facilities. It also supports behaviour-driven development, mocking and benchmarking. With the release of Ruby 1.9, it was added to Ruby's standard library, which increased its popularity.
To run a Minitest test, the only setup you really need is to require the autorun file at the beginning of a test file: require 'minitest/autorun' . This is good if you'd like to keep the code small. A better way to get started with Minitest is to have Bundler create a template project for you.
Or we can run a single test file by passing the bin/rails test command the filename containing the test cases. This will run all test methods from the test case. You can also run a particular test method from the test case by providing the -n or --name flag and the test's method name.
You can access the response body in a functional test via:
response.body
Often, in this style of testing, you really want to use the method:
assert_select
A nice way to check out the assert_select API is via the cheat gem:
gem install cheat
cheat assert_select
This rails testing guide might help you some: http://guides.rubyonrails.org/testing.html#testing-views
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With