-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Spy::Instance#instead - initial test cases
- Loading branch information
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require 'test_helper' | ||
|
||
class InsteadTest < Minitest::Spec | ||
describe 'Spy::Instance#instead' do | ||
after do | ||
Spy.restore(:all) | ||
end | ||
|
||
it 'will run the instead block and not the original call' do | ||
o = Object.new | ||
o.instance_eval do | ||
def incr; @total ||= 0; @total += 1; end | ||
def total; @total; end | ||
def total=(n); @total = n; end | ||
end | ||
|
||
Spy.on(o, :incr).instead do |mc| | ||
mc.receiver.total += 2 | ||
end | ||
|
||
o.incr | ||
|
||
assert_equal 2, o.total | ||
end | ||
|
||
it 'will return the value returned by the block' do | ||
fail | ||
end | ||
|
||
it 'plays nicely with Spy::Instance#when' do | ||
fail | ||
end | ||
end | ||
end |