
Testing with RSpec
RSpec fundamentals, model specs, request specs, system tests (Capybara), FactoryBot, mocking, testing jobs
1What is the main RSpec configuration file in a Rails application?
What is the main RSpec configuration file in a Rails application?
Câu trả lời
The spec/spec_helper.rb file (or spec/rails_helper.rb for Rails tests) is the main RSpec configuration file. It loads the test environment and configures global RSpec options. In modern Rails projects, rails_helper.rb loads spec_helper.rb and adds Rails-specific configurations like loading the test environment and Rails helpers.
2What is the correct syntax to define a test block (example) in RSpec?
What is the correct syntax to define a test block (example) in RSpec?
Câu trả lời
In RSpec, an individual test is defined with it or specify followed by a description in quotes and a block. The syntax it 'description' do ... end is most common. The describe or context block groups related tests, while it defines a specific example. This natural English-readable syntax is one of RSpec's strengths.
3What is the difference between describe and context in RSpec?
What is the difference between describe and context in RSpec?
Câu trả lời
describe and context are functionally identical in RSpec, but follow different semantic conventions. describe is used to describe what is being tested (a class, a method), while context describes the conditions or circumstances of the test. For example, describe User followed by context 'when email is valid'. This distinction improves spec readability.
Which RSpec matcher is used to verify that a value equals another?
How to run only the tests from a specific spec file with RSpec?
+21 câu hỏi phỏng vấn
Các chủ đề phỏng vấn Ruby on Rails khác
Ruby Basics
Ruby Object-Oriented Programming
Rails Fundamentals
Routing & Controllers
ActiveRecord Basics
Views & ERB Templates
ActiveRecord Associations
Advanced ActiveRecord Queries
Rails Forms
Authentication & Authorization
Modern Asset Pipeline & Frontend
Rails API Mode
ActiveJob & Background Jobs
ActionCable & WebSockets
ActionMailer
ActiveStorage
Caching Strategies
Advanced Migrations
Rails Engines & Modular Apps
Performance Optimization
Rails Design Patterns
Ruby Metaprogramming
Rails Security
GraphQL with Rails
Deployment & Production
Monitoring & Logging
Rails Upgrade Strategies
Nắm vững Ruby on Rails cho lần phỏng vấn tiếp theo
Truy cập tất cả câu hỏi, flashcards, bài kiểm tra kỹ thuật, bài tập code review và mô phỏng phỏng vấn.
Bắt đầu miễn phí