Challenge - 5 Problems
Capybara System Test Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What does this Capybara test check for?
Given the following system test code, what is the expected behavior when it runs?
Ruby on Rails
require "application_system_test_case" class PostsTest < ApplicationSystemTestCase test "visiting the index" do visit posts_url assert_selector "h1", text: "Posts" end end
Attempts:
2 left
💡 Hint
Look at the visit URL and the assert_selector method.
✗ Incorrect
The test visits the URL for posts index (posts_url) and asserts that an h1 element containing the text 'Posts' is present on the page.
📝 Syntax
intermediate2:00remaining
Identify the syntax error in this Capybara test snippet
Which option correctly fixes the syntax error in this test code?
Ruby on Rails
test "creating a post" do visit new_post_url fill_in "Title", with: "My Post" click_button "Create Post" assert_text "Post was successfully created" end
Attempts:
2 left
💡 Hint
System tests must be inside a test class inheriting from ApplicationSystemTestCase.
✗ Incorrect
In Rails system tests, test methods must be inside a test class that inherits from ApplicationSystemTestCase. The snippet is missing the class wrapper.
❓ state_output
advanced2:00remaining
What is the value of 'post_count' after this test runs?
Consider this system test code snippet. What will be the value of 'post_count' after the test completes?
Ruby on Rails
test "creating a post increases count" do post_count = Post.count visit new_post_url fill_in "Title", with: "New Post" click_button "Create Post" assert_text "Post was successfully created" post_count = Post.count end
Attempts:
2 left
💡 Hint
Think about when the count is checked and if the post creation was successful.
✗ Incorrect
The test checks the post count before and after creating a post. After clicking 'Create Post', the post is saved, so the count increases by 1.
🔧 Debug
advanced2:00remaining
Why does this Capybara test fail with a 'Capybara::ElementNotFound' error?
Given this test code, why does it raise 'Capybara::ElementNotFound'?
Ruby on Rails
test "deleting a post" do visit posts_url click_on "Delete", match: :first assert_text "Post was successfully destroyed" end
Attempts:
2 left
💡 Hint
Check if the page actually has a 'Delete' link or button visible.
✗ Incorrect
The error means Capybara cannot find any element with text 'Delete'. This usually happens if the link or button is missing or named differently.
🧠 Conceptual
expert2:00remaining
Which statement about Capybara's 'visit' method in system tests is true?
Select the correct statement about how Capybara's 'visit' method works in Rails system tests.
Attempts:
2 left
💡 Hint
Think about how Capybara interacts with the browser during system tests.
✗ Incorrect
Capybara's 'visit' method opens the given URL in a browser controlled by the test driver (like Selenium). This simulates a real user visiting the page.