Skip to content

Instantly share code, notes, and snippets.

@mikbe
Created July 6, 2011 01:20
Show Gist options
  • Save mikbe/1066328 to your computer and use it in GitHub Desktop.
Save mikbe/1066328 to your computer and use it in GitHub Desktop.
What's a better way to test if a block is passed on?
it "should pass along blocks if given" do
class Baz3
def initialize(attributes = nil, &block)
yield if block_given?
end
end
class Qiz3 < Baz3
include Eventable
end
@cheesy = nil
Qiz3.new() { @cheesy = "but it works" }
@cheesy.should == "but it works"
end
@semmons99
Copy link

Coming from #rmu, I'm not sure why you'd directly test if a block was given. You should only be testing the results of calling Qiz3#new with and without a block.

@mikbe
Copy link
Author

mikbe commented Jul 6, 2011

I'm testing that my library can accept a block and passes it along properly. My library doesn't actually use a block but it needs to support a class that inherits from a class that does.

Since my library doesn't actually use a block I need to fabricate a situation where one is used to test that I pass it along properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment