Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

allow you to pass a fucking block

  • Loading branch information...
commit 3f279bc92ed0f3b38d6c996579afedb0d78d64f1 1 parent c33d5c9
@jjulian authored
Showing with 21 additions and 1 deletion.
  1. +5 −1 lib/can_has.rb
  2. +16 −0 spec/can_has_spec.rb
View
6 lib/can_has.rb
@@ -4,7 +4,11 @@ def can_has?(cheezburger = :cheezburger)
when :cheezburger
true
else
- rand(2) > 0
+ if block_given?
+ yield
+ else
+ rand(2) > 0
+ end
end
end
end
View
16 spec/can_has_spec.rb
@@ -13,4 +13,20 @@
struct.can_has?(:bukkit)
end
+ it "should always let you do something" do
+ struct = OpenStruct.new
+ struct.should_receive(:rand).with(2).and_return(1)
+ struct.can_has?(:bukkit).should be_true
+ end
+
+ it "should maybe let you do something if you pass a fucking block" do
+ struct = OpenStruct.new
+ struct.can_has?(:bukkit) { false }.should be_false
+ end
+
+ it "should always let you do something if you pass a fucking block" do
+ struct = OpenStruct.new
+ struct.can_has?(:bukkit) { true }.should be_true
+ end
+
end
Please sign in to comment.
Something went wrong with that request. Please try again.