Skip to content

Commit

Permalink
allow you to pass a fucking block
Browse files Browse the repository at this point in the history
  • Loading branch information
jjulian committed Jun 9, 2010
1 parent c33d5c9 commit 3f279bc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/can_has.rb
Expand Up @@ -4,7 +4,11 @@ def can_has?(cheezburger = :cheezburger)
when :cheezburger when :cheezburger
true true
else else
rand(2) > 0 if block_given?
yield
else
rand(2) > 0
end
end end
end end
end end
Expand Down
16 changes: 16 additions & 0 deletions spec/can_has_spec.rb
Expand Up @@ -13,4 +13,20 @@
struct.can_has?(:bukkit) struct.can_has?(:bukkit)
end 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 end

0 comments on commit 3f279bc

Please sign in to comment.