Ruby on Rails Quality Control & Assurance 4 — Questions and Answers
Question 1: When RSpec's `--bisect` flag is used, what problem does it solve?
- Identifies the minimum set of examples that reproduces an order-dependent failure (Correct answer)
- Splits the test suite in half for parallel execution
- Removes duplicate examples automatically
- Bisects slow tests into smaller units
Correct answer: Identifies the minimum set of examples that reproduces an order-dependent failure
`--bisect` uses binary search to find the smallest subset of tests whose ordering causes a specific example to fail, isolating order-dependent bugs.
Question 2: In Rails, what is the purpose of `config.action_mailer.delivery_method = :test` in the test environment?
- Stores sent emails in `ActionMailer::Base.deliveries` array instead of sending them (Correct answer)
- Silences mailer output in the test log
- Sends emails to a test inbox via SMTP
- Disables all mailer callbacks
Correct answer: Stores sent emails in `ActionMailer::Base.deliveries` array instead of sending them
The `:test` delivery method intercepts outgoing email into an in-memory array so tests can assert on email content without actual delivery.
Question 3: Which Capybara method asserts that a specific text is NOT visible on the page?
- expect(page).not_to have_text('...') (Correct answer)
- expect(page).to lack_text('...')
- expect(page).to have_no_content?('...')
- assert_missing_text(page, '...')
Correct answer: expect(page).not_to have_text('...')
RSpec's negation `not_to have_text` (or `have_no_text`) correctly waits for the text to disappear before asserting its absence.
Question 4: What does `rails test:system` run that `rails test` does not?
- System tests using a real browser driver like Selenium or Cuprite (Correct answer)
- Only model and controller unit tests
- Database migration tests
- Asset compilation tests
Correct answer: System tests using a real browser driver like Selenium or Cuprite
`rails test:system` runs tests in `test/system/` that use a browser driver, while `rails test` runs unit/integration tests without browser automation.
Question 5: In FactoryBot, what is a `trait` used for?
- Define optional attribute overrides that can be mixed into factory instances (Correct answer)
- Create a separate factory that inherits all parent attributes
- Validate factory attributes before building
- Register a factory under an alternate name
Correct answer: Define optional attribute overrides that can be mixed into factory instances
Traits group related attribute overrides (e.g., `trait :admin`) that can be applied selectively when building instances with `create(:user, :admin)`.
Question 6: Which metric does `rails stats` NOT report?
- Test coverage percentage (Correct answer)
- Lines of code per file type
- Number of classes and modules
- Code-to-test ratio
Correct answer: Test coverage percentage
`rails stats` reports LOC, class counts, and code-to-test ratio but does not instrument code paths, so it cannot report coverage percentage.
Question 7: What is the primary advantage of using `let` over `let!` in RSpec?
- `let` is lazily evaluated and only runs when the variable is first referenced, avoiding unnecessary setup (Correct answer)
- `let` persists across multiple examples in the same group
- `let!` cannot be used with FactoryBot
- `let` memoizes across the entire suite, not just per example
Correct answer: `let` is lazily evaluated and only runs when the variable is first referenced, avoiding unnecessary setup
`let` uses lazy evaluation so the block only executes if the example actually uses the variable, making tests that don't need it faster.
When RSpec's `--bisect` flag is used, what problem does it solve?