Skip to content

Instantly share code, notes, and snippets.

@niku
Created March 8, 2011 23:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niku/861298 to your computer and use it in GitHub Desktop.
Save niku/861298 to your computer and use it in GitHub Desktop.
How do I check block given?
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