# Create a mock object
book = MiniTest::Mock.new
# Set the mock to expect :title, return "War and Piece"
# (note that unless we call book.verify, minitest will
# not check that :title was called)
book.expect :title, "War and Piece"
# Stub Book.new to return the mock object
# (only within the scope of the block)
Book.stub :new, book do
wp = Book.new # returns the mock object
wp.title # => "War and Piece"
end
Related Contents:
- Is it possible to run a single test in MiniTest?
- What is the expected syntax for checking exception messages in MiniTest’s assert_raises/must_raise?
- How to run all tests with minitest?
- Before/After Suite when using Ruby MiniTest
- How do I pick randomly from an array?
- When monkey patching an instance method, can you call the overridden method from the new implementation?
- What is the difference between include and extend in Ruby?
- How to check whether a string contains a substring in Ruby
- Does ruby have real multithreading?
- Can’t install Ruby under Lion with RVM – GCC issues
- find_spec_for_exe’: can’t find gem bundler (>= 0.a) (Gem::GemNotFoundException)
- No increment operator (++) in Ruby? [duplicate]
- “for” vs “each” in Ruby
- How do I get ruby to print a full backtrace instead of a truncated one?
- How to get a substring of text?
- Get file name and extension in Ruby
- Can you supply arguments to the map(&:method) syntax in Ruby?
- How to update Ruby to 1.9.x on Mac?
- Merge and interleave two arrays in Ruby
- macOS Mojave ‘ruby/config.h’ file not found
- Why isn’t the eigenclass equivalent to self.class, when it looks so similar?
- therubyracer – Gem::Ext::BuildError: ERROR: Failed to build gem native extension
- what is the point of return in Ruby?
- Ruby: Proc#call vs yield
- OpenSSL vs GPG for encrypting off-site backups? [closed]
- Ruby: Is it possible to define a class method in a module?
- How to install RVM system requirements without giving sudo access for RVM user
- How to split string into only two parts with a given character in Ruby?
- How to get rid of non-ascii characters in ruby
- how to convert 270921sec into days + hours + minutes + sec ? (ruby)
- to_s vs. to_str (and to_i/to_a/to_h vs. to_int/to_ary/to_hash) in Ruby
- How to understand the difference between class_eval() and instance_eval()?
- How to make the class constructor private in Ruby?
- Should one use dashes or underscores when naming a gem with more than one word?
- How to get the number of days in a given month in Ruby, accounting for year?
- Is there simpler (one-line) syntax to alias one class method?
- How to get activerecord associations via reflection
- ActionController::UnknownFormat
- File.open, open and IO.foreach in Ruby, what is the difference?
- Remove/undef a class method
- How to install ruby-debug when needing necessary libraries and/or headers
- Can’t get Ruby DevKit configuration file autogenerated properly
- Ruby: how to tell if character is upper/lowercase
- jekyll debug or print all variables
- RSpec: stubbing Kernel::sleep?
- Installing Ruby with Homebrew
- troubles with RVM and OpenSSL
- How do I get the public methods of a class without inherited methods?
- How do you mark a Cucumber Scenario as Pending
- What’s the best way to search for a string in a file?