Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend the class documentation a bit #950

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
45 changes: 45 additions & 0 deletions lib/minitest/mock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,47 @@ module Minitest # :nodoc:
# A simple and clean mock object framework.
#
# All mock objects are an instance of Mock
#
# Mocks and stubs defined using terminology by Fowler & Meszaros at www.martinfowler.com/bliki/TestDouble.html:
#
# “Mocks are pre-programmed with expectations which form a specification of the calls they are expected to receive. They can throw an exception if they receive a call they don’t expect and are checked during verification to ensure they got all the calls they were expecting.”
#
# class MemeAsker
# def initialize(meme)
# @meme = meme
# end
#
# def ask(question)
# method = question.tr(" ", "_") + "?"
# @meme.__send__(method)
# end
# end
#
# require "minitest/autorun"
#
# describe MemeAsker, :ask do
# describe "when passed an unpunctuated question" do
# it "should invoke the appropriate predicate method on the meme" do
# @meme = Minitest::Mock.new
# @meme_asker = MemeAsker.new @meme
# @meme.expect :will_it_blend?, :return_value
#
# @meme_asker.ask "will it blend"
#
# @meme.verify
# end
# end
# end
#
# A note on multi-threading: Minitest mocks do not support multi-threading. If it works, fine, if it doesn’t you can use regular ruby patterns and facilities like local variables. Here’s an example of asserting that code inside a thread is run:
#
# def test_called_inside_thread
# called = false
# pr = Proc.new { called = true }
# thread = Thread.new(&pr)
# thread.join
# assert called, "proc not called"
# end

class Mock
alias :__respond_to? :respond_to?
Expand Down Expand Up @@ -252,6 +293,10 @@ def assert_mock mock

##
# Object extensions for Minitest::Mock.
#
# Mocks and also stubs are defined using terminology by Fowler & Meszaros at www.martinfowler.com/bliki/TestDouble.html:
#
# “Stubs provide canned answers to calls made during the test”.

class Object

Expand Down
2 changes: 1 addition & 1 deletion lib/minitest/spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def describe desc, *additional_desc, &block # :doc:
##
# Minitest::Spec -- The faster, better, less-magical spec framework!
#
# For a list of expectations, see Minitest::Expectations.
# For a list of expectations, see Minitest::Expectations. To learn how to set up a basic spec see Kernel.

class Minitest::Spec < Minitest::Test

Expand Down