Module: Hardmock::Stubbing
- Defined in:
- lib/hardmock/stubbing.rb
Overview
Hardmock: Stubbing and Mocking Concrete Methods
Hardmock lets you stub and/or mock methods on concrete classes or objects.
-
To “stub” a concrete method is to rig it to return the same thing always, disregarding any arguments.
-
To “mock” a concrete method is to surplant its funcionality by delegating to a mock object who will cover this behavior.
Mocked methods have their expectations considered along with all other mock object expectations.
If you use stubbing or concrete mocking in the absence (or before creation) of other mocks, you need to invoke prepare_hardmock_control
. Once verify_mocks
or clear_expectaions
is called, the overriden behavior in the target objects is restored.
Examples
River.stubs!(:sounds_like).returns("gurgle")
River.expects!(:jump).returns("splash")
rogue.stubs!(:sounds_like).returns("pshshsh")
rogue.expects!(:rawhide_tanning_solvents).returns("giant snapping turtles")