test/test_syncem.rb in syncem-0.1.0 vs test/test_syncem.rb in syncem-0.1.1
- old
+ new
@@ -42,10 +42,14 @@
def add(amount)
now = File.exist?(@file) ? IO.read(@file).to_i : 0
IO.write(@file, (now + amount).to_s)
end
+
+ def read
+ yield balance
+ end
end
def test_wraps_simple_object
Dir.mktmpdir do |dir|
path = File.join(dir, 'f.txt')
@@ -62,9 +66,23 @@
Dir.mktmpdir do |dir|
path = File.join(dir, 'f.txt')
acc = SyncEm.new(Account.new(path))
assert(acc.respond_to?(:balance))
assert(acc.respond_to?(:add))
+ end
+ end
+
+ def test_works_with_block
+ Dir.mktmpdir do |dir|
+ path = File.join(dir, 'f.txt')
+ acc = SyncEm.new(Account.new(path))
+ acc.add(50)
+ before = 0
+ acc.read do |b|
+ assert_equal(50, b)
+ before = b
+ end
+ assert_equal(50, before)
end
end
def test_multiple_threads
Dir.mktmpdir do |dir|