Search⌘ K
AI Features

Minitest Integration Tests

Explore how to write and run Minitest integration tests in Rails applications to perform end-to-end testing without JavaScript. Understand how to send parameters directly through routing, handle redirects, and use assert_select assertions for precise DOM element checks to ensure your application's behavior matches expectations.

Minitest integration testing

Rails uses integration tests for end-to-end tests when the runtime is not using JavaScript. These are a little different from the system tests in that they don’t use Capybara, and therefore typically pass parameters directly to the test.

We have end-to-end tests that we used to create projects. Here’s how those look as integration tests:

git clone --single-branch --branch railstest-ch13.8 https://241d062a6225a4b2479bd99500dd66633e519792@github.com/educative/course-content.git 
cd /usercode/course-content/
rm Gemfile
rm Gemfile.lock
cp -r /usercode/course-content/* /usr/local/educative/gatherer
rsync -avr --progress usercode/* /usr/local/educative/gatherer --exclude course-content --exclude execute1.sh --exclude execute.sh --exclude __ed_script.sh --exclude __ed_stderr.txt --exclude __ed_stdout.txt
cd /usr/local/educative/gatherer
npm install
clear
bundle exec rake test:integration

Adding code to add_project_test.rb file in test/integration

There are a few differences between these tests and the system tests we wrote before.

Rather than simulating filling out the form with Capybara, we’re sending arguments through the Rails routing table directly using the post helper. This ...