* test/ruby/envutil.rb (assert_normal_exit): show pid when fail.
[ruby-svn.git] / test / yaml / test_yamlstore.rb
blob7a3d90469eb089e4c1cddffe892e92c99958b8ad
1 require 'test/unit'
2 require 'yaml/store'
4 class YAMLStoreTest < Test::Unit::TestCase
5   def setup
6     @yamlstore_file = "yamlstore.tmp.#{Process.pid}"
7     @yamlstore = YAML::Store.new(@yamlstore_file)
8   end
10   def teardown
11     File.unlink(@yamlstore_file) rescue nil
12   end
14   def test_opening_new_file_in_readonly_mode_should_result_in_empty_values
15     @yamlstore.transaction(true) do
16       assert_nil @yamlstore[:foo]
17       assert_nil @yamlstore[:bar]
18     end
19   end
20   
21   def test_opening_new_file_in_readwrite_mode_should_result_in_empty_values
22     @yamlstore.transaction do
23       assert_nil @yamlstore[:foo]
24       assert_nil @yamlstore[:bar]
25     end
26   end
27   
28   def test_data_should_be_loaded_correctly_when_in_readonly_mode
29     @yamlstore.transaction do
30       @yamlstore[:foo] = "bar"
31     end
32     @yamlstore.transaction(true) do
33       assert_equal "bar", @yamlstore[:foo]
34     end
35   end
36   
37   def test_data_should_be_loaded_correctly_when_in_readwrite_mode
38     @yamlstore.transaction do
39       @yamlstore[:foo] = "bar"
40     end
41     @yamlstore.transaction do
42       assert_equal "bar", @yamlstore[:foo]
43     end
44   end
45   
46   def test_changes_after_commit_are_discarded
47     @yamlstore.transaction do
48       @yamlstore[:foo] = "bar"
49       @yamlstore.commit
50       @yamlstore[:foo] = "baz"
51     end
52     @yamlstore.transaction(true) do
53       assert_equal "bar", @yamlstore[:foo]
54     end
55   end
56   
57   def test_changes_are_not_written_on_abort
58     @yamlstore.transaction do
59       @yamlstore[:foo] = "bar"
60       @yamlstore.abort
61     end
62     @yamlstore.transaction(true) do
63       assert_nil @yamlstore[:foo]
64     end
65   end
66   
67   def test_writing_inside_readonly_transaction_raises_error
68     assert_raise(PStore::Error) do
69       @yamlstore.transaction(true) do
70         @yamlstore[:foo] = "bar"
71       end
72     end
73   end
74 end