CommerceTesting In Ruby (Rspec, Minitest, Etc.) MCQs
Practice Testing In Ruby (Rspec, Minitest, Etc.) MCQs for competitive exams.
Testing In Ruby (Rspec, Minitest, Etc.) MCQs
Practice questions from this topic.
What is the purpose of the assert_match method in MiniTest?
- A. Asserts that a condition is true
- B. Asserts that a string matches a regular expression
- C. Asserts that a condition is false
- D. None of the above
Correct Answer: B
Which keyword is commonly used in Cucumber feature files to define a background?
- A. Scenario:
- B. Given:
- C. Background:
- D. When:
Correct Answer: C
What is the purpose of the should syntax in RSpec?
- A. Provides a way to define before and after hooks
- B. Provides a way to define shared examples
- C. Provides a way to define custom matchers
- D. Provides a more readable way to express expectations
Correct Answer: D
What is the purpose of the assert_empty method in MiniTest?
- A. Asserts that an object is empty
- B. Asserts that two objects are equal
- C. Asserts that a condition is true
- D. Asserts that a condition is false
Correct Answer: A
What is the purpose of a background section in a Cucumber feature file?
- A. Defines steps that should be run after each scenario
- B. Defines steps that are shared across multiple scenarios
- C. Defines steps that should be run before all scenarios
- D. Defines steps that should be run before each scenario
Correct Answer: D
Which command is commonly used to generate a new RSpec test file?
- A. rails generate rspec:feature FeatureName
- B. rails generate rspec:controller ControllerName
- C. rails generate rspec:model ModelName --spec
- D. rails generate rspec:model ModelName
Correct Answer: C
What is the purpose of a setup block in MiniTest?
- A. Executes code after each test case
- B. Executes code before all test cases
- C. Executes code after all test cases
- D. Executes code before each test case
Correct Answer: D
What is the purpose of a subject block in RSpec?
- A. Records the interactions between objects
- B. Overrides the behavior of a method to return a specific value
- C. Provides a target object for the example group
- D. Defines a memoized helper method that can be used in examples
Correct Answer: C
What is the purpose of a cucumber tag in Cucumber testing?
- A. Describes the behavior of an application in plain text
- B. Labels scenarios with metadata
- C. Overrides the behavior of a method to return a specific value
- D. None of the above
Correct Answer: B
Which method is commonly used to assert that a certain exception is raised in RSpec?
- A. assert_raises(ExceptionClass) { ... }
- B. expect { ... }.to throw_symbol(:exception_symbol)
- C. expect { ... }.to raise_error(ExceptionClass)
- D. assert_throw(:exception_symbol) { ... }
Correct Answer: C
What is the purpose of a scenario outline in Cucumber testing?
- A. Checks if a value meets certain conditions
- B. Provides a placeholder for a method that will be defined later
- C. Describes the behavior of an application in plain text
- D. Allows the same scenario to be run with different combinations of data
Correct Answer: D
Which command is commonly used to run MiniTest tests from the command line?
- A. ruby test.rb
- B. rake test
- C. ruby minitest.rb
- D. minitest run
Correct Answer: A