Ruby on Rails Research & Evidence-Based Practice 4 — Questions and Answers
Question 1: Which Rails testing approach provides the most evidence that a refactored method maintains correct behavior?
- Manual QA on staging
- Regression tests written before refactoring (Correct answer)
- Code review by a senior developer
- Linting with RuboCop
Correct answer: Regression tests written before refactoring
Writing regression tests before refactoring captures the existing behavior as a specification, providing evidence the refactor is safe.
Question 2: In evidence-based Rails development, what is the primary purpose of tracking `db_runtime` and `view_runtime` in production logs?
- To count the number of users online
- To identify whether bottlenecks are in the database or view rendering layer (Correct answer)
- To measure memory consumption per request
- To enforce query timeouts
Correct answer: To identify whether bottlenecks are in the database or view rendering layer
Rails logs `db_runtime` (SQL time) and `view_runtime` (template rendering time) separately, allowing developers to pinpoint which layer is slow.
Question 3: Which method of ActiveRecord::Calculations provides aggregate evidence about data distributions useful for optimizing scopes?
- ActiveRecord::Base.analyze
- relation.group(:column).count (Correct answer)
- relation.explain.summary
- ActiveRecord::Schema.stats
Correct answer: relation.group(:column).count
`group(:column).count` returns a hash of value frequencies, revealing data distributions to inform index and scope decisions.
Question 4: A developer uses `rails stats` to gather evidence about codebase growth. What does a declining `Code to Test ratio` indicate?
- The app is getting faster
- Test coverage is growing relative to application code (Correct answer)
- Dependencies are increasing
- Database migrations are accumulating
Correct answer: Test coverage is growing relative to application code
A lower or declining code-to-test ratio means more test code relative to application code, indicating improved test coverage.
Question 5: To collect evidence that a Rails background job completes within an SLA, which Sidekiq feature provides job timing data?
- Sidekiq::Stats (Correct answer)
- Sidekiq::Worker.perform_async latency
- Sidekiq Web UI's processed jobs list
- ActiveJob::Base.logger
Correct answer: Sidekiq::Stats
`Sidekiq::Stats` provides aggregate metrics including processed count, failed count, and queue latency for SLA monitoring.
Question 6: When selecting a Rails gem for a critical dependency, which evidence source is most authoritative for long-term maintenance viability?
- Number of closed GitHub issues
- Commit frequency, test suite presence, and maintainer responsiveness (Correct answer)
- Total download count on RubyGems.org
- The gem's README quality
Correct answer: Commit frequency, test suite presence, and maintainer responsiveness
Commit frequency, an active test suite, and responsive maintainers are the strongest predictors of a gem's long-term health.
Question 7: Which Rails feature allows developers to run an experiment comparing two implementations of a method with logged results before committing to one?
- ActiveSupport::Testing::Isolation
- GitHub Scientist-style branching via the Scientist gem (Correct answer)
- RSpec shared_examples
- Rails credentials diffing
Correct answer: GitHub Scientist-style branching via the Scientist gem
The Scientist gem (inspired by GitHub) runs both old and new code paths, compares results, and logs mismatches without affecting users.
Which Rails testing approach provides the most evidence that a refactored method maintains correct behavior?