Created
March 8, 2011 23:02
-
-
Save niku/861298 to your computer and use it in GitHub Desktop.
How do I check block given?
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
require 'rspec' | |
class Foo | |
def bar &block | |
block.call(:called) if block | |
:done | |
end | |
end | |
# Foo.new.bar{ |m| p m } | |
# # >> :called | |
describe Foo do | |
describe '#bar' do | |
context 'given block' do | |
it 'should call block' do | |
block = double() | |
block.should_receive(:call) | |
Foo.new.bar &block | |
end | |
end | |
end | |
end | |
# /Users/niku/junk/2011/03% rspec mock_block_spec.rb | |
# F | |
# | |
# Failures: | |
# | |
# 1) Foo#bar given block should call block | |
# Failure/Error: Foo.new.bar &block | |
# Double received unexpected message :to_proc with (no args) | |
# # ./mock_block_spec.rb:19:in `block (4 levels) in <top (required)>' | |
# | |
# Finished in 0.00087 seconds | |
# 1 example, 1 failure |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment