4 class YAMLStoreTest < Test::Unit::TestCase
6 @yamlstore_file = "yamlstore.tmp.#{Process.pid}"
7 @yamlstore = YAML::Store.new(@yamlstore_file)
11 File.unlink(@yamlstore_file) rescue nil
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]
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]
28 def test_data_should_be_loaded_correctly_when_in_readonly_mode
29 @yamlstore.transaction do
30 @yamlstore[:foo] = "bar"
32 @yamlstore.transaction(true) do
33 assert_equal "bar", @yamlstore[:foo]
37 def test_data_should_be_loaded_correctly_when_in_readwrite_mode
38 @yamlstore.transaction do
39 @yamlstore[:foo] = "bar"
41 @yamlstore.transaction do
42 assert_equal "bar", @yamlstore[:foo]
46 def test_changes_after_commit_are_discarded
47 @yamlstore.transaction do
48 @yamlstore[:foo] = "bar"
50 @yamlstore[:foo] = "baz"
52 @yamlstore.transaction(true) do
53 assert_equal "bar", @yamlstore[:foo]
57 def test_changes_are_not_written_on_abort
58 @yamlstore.transaction do
59 @yamlstore[:foo] = "bar"
62 @yamlstore.transaction(true) do
63 assert_nil @yamlstore[:foo]
67 def test_writing_inside_readonly_transaction_raises_error
68 assert_raise(PStore::Error) do
69 @yamlstore.transaction(true) do
70 @yamlstore[:foo] = "bar"