0
0
Ruby on Railsframework~10 mins

Integration tests in Ruby on Rails - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Integration tests
Write integration test
Setup test data and environment
Simulate user actions (visit, fill, click)
Check page content and responses
Pass or fail test
Fix code or test if needed
END
Integration tests simulate user actions across multiple parts of the app to check if they work together correctly.
Execution Sample
Ruby on Rails
test "user login flow" do
  visit login_path
  fill_in "Email", with: "user@example.com"
  fill_in "Password", with: "secret"
  click_button "Log in"
  assert_text "Welcome, user!"
end
This test simulates a user logging in and checks if the welcome message appears.
Execution Table
StepActionInput/ConditionResultTest Outcome
1Visit login pagelogin_pathLogin page loadsContinue
2Fill in Email"user@example.com"Email field filledContinue
3Fill in Password"secret"Password field filledContinue
4Click Log in buttonSubmit formForm submitted, server processes loginContinue
5Check page contentPage shows "Welcome, user!"Text found on pagePass
6Test endsAll assertions passedTest successfulEnd
💡 Test ends after all assertions pass or fail
Variable Tracker
VariableStartAfter Step 2After Step 3After Step 4Final
page_content"""Login page loaded""Email and Password fields filled""Form submitted, processing login""Welcome, user!" displayed
Key Moments - 2 Insights
Why do we simulate user actions like filling fields and clicking buttons instead of calling controller methods directly?
Integration tests mimic real user behavior by interacting with the app through the UI, ensuring all parts work together, as shown in steps 2-4 of the execution_table.
What happens if the expected text is not found on the page after login?
The assertion in step 5 fails, causing the test to fail, indicating a problem in the login flow or page rendering.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the page content after step 3?
A"Login page loaded"
B"Email and Password fields filled"
C"Form submitted, processing login"
D"Welcome, user!" displayed
💡 Hint
Check the 'Result' column for step 3 in the execution_table.
At which step does the test check if the login was successful?
AStep 2
BStep 4
CStep 5
DStep 6
💡 Hint
Look for the step where the page content is verified for the welcome message.
If the login page fails to load, how would the execution_table change?
AStep 1 result would show an error and test would end early
BStep 5 would fail because welcome text is missing
CStep 4 would not submit the form
DStep 6 would pass anyway
💡 Hint
Consider what happens if the first action (visiting the page) fails.
Concept Snapshot
Integration tests simulate real user actions across multiple parts of a Rails app.
Use Capybara methods like visit, fill_in, click_button.
Check page content with assertions like assert_text.
They ensure different components work together correctly.
Tests pass only if all assertions succeed.
Full Transcript
Integration tests in Rails simulate how a user interacts with the app by visiting pages, filling in forms, clicking buttons, and checking the results on the page. The test example shows a user logging in by visiting the login page, entering email and password, clicking the login button, and then verifying the welcome message appears. Each step changes the page content or state, which the test checks. If any check fails, the test fails, showing where the problem is. This helps ensure the app works correctly as a whole, not just in isolated parts.