Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Expose RCCounter#decrement_if_negative

  • Loading branch information...
commit e7bda33f5fcf9a91261ba3182d9991863153921c 1 parent 8094c77
@jc00ke jc00ke authored
View
1  lib/ruby/1.8/maglev/rccounter.rb
@@ -22,4 +22,5 @@ class RCCounter
primitive 'increment_by', 'incrementBy:'
primitive 'decrement', 'decrement'
primitive 'decrement_by', 'decrementBy:'
+ primitive 'decrement_if_negative&', 'decrementIfNegative:'
end
View
23 spec/maglev/reducedconflict/counter/decrement_if_negative_spec.rb
@@ -0,0 +1,23 @@
+require File.expand_path('../../../../spec_helper', __FILE__)
+require 'maglev/rccounter'
+
+describe "RCCounter#decrement_if_negative" do
+
+ describe "when value is positive" do
+ it "subtracts 1 from the counter" do
+ counter = RCCounter.new
+ counter.increment_by 10
+ counter.decrement_if_negative { "won't get executed" }
+ counter.value.should == 9
+ end
+ end
+
+ describe "when value is negative" do
+ it "executes the block" do
+ counter = RCCounter.new
+ result = counter.decrement_if_negative { 'block executed' }
+ result.should == 'block executed'
+ end
+ end
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.