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 background keyword in Cucumber?
- 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
What is the purpose of the assert_predicate method in MiniTest?
- A. Asserts that a condition is false
- B. Asserts that a condition is true
- C. Asserts that an object matches a specific predicate
- D. Asserts that two objects are equal
Correct Answer: C
Which command is commonly used to run Cucumber tests from the command line?
- A. cucumber run
- B. cucumber
- C. ruby cucumber.rb
- D. None of the above
Correct Answer: B
Which assertion method is commonly used in MiniTest for testing if an array is empty?
- A. assert_equal([], array)
- B. assert_nil(array)
- C. assert_empty(array)
- D. assert(array.empty?)
Correct Answer: C
What is the purpose of a setup method in Test::Unit?
- A. Executes code after all test cases
- B. Executes code before all test cases
- C. Executes code after each test case
- D. Executes code before each test case
Correct Answer: D
What is the purpose of a let! block in RSpec?
- A. Defines a memoized helper method that is executed before each example
- B. Defines a memoized helper method that can be used in examples
- C. Overrides the behavior of a method to return a specific value
- D. Records the interactions between objects
Correct Answer: A
Which command is commonly used to generate a new Cucumber feature file?
- A. cucumber create feature FeatureName
- B. rails generate cucumber:feature FeatureName
- C. rails generate feature:file FeatureName
- D. None of the above
Correct Answer: B
What is the purpose of the assert_includes method in MiniTest?
- A. Asserts that two objects are equal
- B. Asserts that a condition is true
- C. Asserts that a collection includes a certain value
- D. Asserts that a condition is false
Correct Answer: C
Which command is commonly used to run Test::Unit tests from the command line?
- A. ruby testunit.rb
- B. rake test
- C. ruby test.rb
- D. test
Correct Answer: D
Which assertion method is commonly used in RSpec for testing if an object responds to a method?
- A. expect(object).to respond_to(:method)
- B. assert_respond_to(object, :method)
- C. assert(object.respond_to?(:method))
- D. expect(object).to have_method(:method)
Correct Answer: A
What is the purpose of the pending keyword in RSpec?
- A. Skips a test or example without running it
- B. Marks a test or example as failing
- C. Marks a test or example as passing
- D. Marks a test or example as pending, meaning it has not been implemented yet
Correct Answer: D
What is the purpose of the be_a matcher in RSpec?
- A. Checks if an object is equal to another object
- B. Checks if a method is called with the correct arguments
- C. Checks if an object is an instance of a certain class
- D. Checks if a value meets certain conditions
Correct Answer: C