plist4r 0.2.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. data/.gitignore +4 -0
  2. data/.yardopts +11 -0
  3. data/LICENSE +3 -1
  4. data/README.rdoc +25 -122
  5. data/Rakefile +14 -0
  6. data/VERSION +1 -1
  7. data/bin/plist4r +2 -0
  8. data/ext/osx_plist/Makefile +157 -0
  9. data/ext/osx_plist/extconf.rb +9 -0
  10. data/ext/osx_plist/plist.c +606 -0
  11. data/ext/osx_plist/plist.o +0 -0
  12. data/lib/plist4r.rb +6 -3
  13. data/lib/plist4r/application.rb +1 -2
  14. data/lib/plist4r/backend.rb +102 -34
  15. data/lib/plist4r/backend/c_f_property_list.rb +65 -0
  16. data/lib/plist4r/backend/c_f_property_list/LICENSE +19 -0
  17. data/lib/plist4r/backend/c_f_property_list/README +34 -0
  18. data/lib/plist4r/backend/c_f_property_list/cfpropertylist.rb +6 -0
  19. data/lib/plist4r/backend/c_f_property_list/rbBinaryCFPropertyList.rb +663 -0
  20. data/lib/plist4r/backend/c_f_property_list/rbCFPlistError.rb +26 -0
  21. data/lib/plist4r/backend/c_f_property_list/rbCFPropertyList.rb +348 -0
  22. data/lib/plist4r/backend/c_f_property_list/rbCFTypes.rb +241 -0
  23. data/lib/plist4r/backend/c_f_property_list/rbXMLCFPropertyList.rb +116 -0
  24. data/lib/plist4r/backend/example.rb +37 -52
  25. data/lib/plist4r/backend/haml.rb +47 -36
  26. data/lib/plist4r/backend/libxml4r.rb +24 -20
  27. data/lib/plist4r/backend/osx_plist.rb +82 -0
  28. data/lib/plist4r/backend/ruby_cocoa.rb +172 -54
  29. data/lib/plist4r/backend/test/data_types.rb +163 -0
  30. data/lib/plist4r/backend/test/harness.rb +255 -0
  31. data/lib/plist4r/backend/test/output.rb +47 -0
  32. data/lib/plist4r/backend_base.rb +4 -2
  33. data/lib/plist4r/{options.rb → cli.rb} +2 -1
  34. data/lib/plist4r/commands.rb +13 -8
  35. data/lib/plist4r/config.rb +36 -9
  36. data/lib/plist4r/docs/Backends.html +59 -0
  37. data/lib/plist4r/docs/DeveloperGuide.rdoc +53 -0
  38. data/lib/plist4r/docs/EditingPlistFiles.rdoc +88 -0
  39. data/lib/plist4r/docs/InfoPlistExample.rdoc +33 -0
  40. data/lib/plist4r/docs/LaunchdPlistExample.rdoc +33 -0
  41. data/lib/plist4r/docs/PlistKeyNames.rdoc +47 -0
  42. data/lib/plist4r/mixin/array_dict.rb +61 -0
  43. data/lib/plist4r/mixin/data_methods.rb +178 -54
  44. data/lib/plist4r/mixin/haml4r.rb +4 -0
  45. data/lib/plist4r/mixin/haml4r/css_attributes.rb +19 -0
  46. data/lib/plist4r/mixin/haml4r/examples.rb +261 -0
  47. data/lib/plist4r/mixin/haml4r/haml_table_example.rb +79 -0
  48. data/lib/plist4r/mixin/haml4r/table.rb +157 -0
  49. data/lib/plist4r/mixin/haml4r/table_cell.rb +160 -0
  50. data/lib/plist4r/mixin/haml4r/table_cells.rb +485 -0
  51. data/lib/plist4r/mixin/haml4r/table_section.rb +101 -0
  52. data/lib/plist4r/mixin/ordered_hash.rb +9 -1
  53. data/lib/plist4r/mixin/popen4.rb +1 -1
  54. data/lib/plist4r/mixin/ruby_stdlib.rb +154 -1
  55. data/lib/plist4r/mixin/script.rb +133 -0
  56. data/lib/plist4r/mixin/table.rb +435 -0
  57. data/lib/plist4r/plist.rb +272 -94
  58. data/lib/plist4r/plist_cache.rb +42 -43
  59. data/lib/plist4r/plist_type.rb +31 -74
  60. data/lib/plist4r/plist_type/info.rb +157 -3
  61. data/lib/plist4r/plist_type/launchd.rb +54 -48
  62. data/lib/plist4r/plist_type/plist.rb +1 -3
  63. data/plist4r.gemspec +74 -14
  64. data/spec/{examples.rb → launchd_examples.rb} +131 -139
  65. data/spec/plist4r/application_spec.rb +37 -0
  66. data/spec/plist4r/backend_spec.rb +256 -0
  67. data/spec/plist4r/cli_spec.rb +25 -0
  68. data/spec/plist4r/commands_spec.rb +20 -0
  69. data/spec/plist4r/config_spec.rb +38 -0
  70. data/spec/plist4r/mixin/array_dict_spec.rb +120 -0
  71. data/spec/plist4r/mixin/data_methods_spec.rb +96 -0
  72. data/spec/plist4r/mixin/haml4r/examples.rb +261 -0
  73. data/spec/plist4r/mixin/ruby_stdlib_spec.rb +228 -0
  74. data/spec/plist4r/plist_cache_spec.rb +261 -0
  75. data/spec/plist4r/plist_spec.rb +841 -23
  76. data/spec/plist4r/plist_type_spec.rb +126 -0
  77. data/spec/plist4r_spec.rb +53 -27
  78. data/spec/scratchpad.rb +226 -0
  79. data/spec/spec_helper.rb +5 -1
  80. metadata +109 -23
  81. data/lib/plist4r/backend/plutil.rb +0 -25
  82. data/lib/plist4r/mixin.rb +0 -7
  83. data/plists/array_mini.xml +0 -14
  84. data/plists/example_big_binary.plist +0 -0
  85. data/plists/example_medium_binary_launchd.plist +0 -0
  86. data/plists/example_medium_launchd.xml +0 -53
  87. data/plists/mini.xml +0 -12
  88. data/test.rb +0 -40
@@ -0,0 +1,261 @@
1
+
2
+ require 'spec_helper'
3
+
4
+ describe Plist4r::PlistCache, "#intialize" do
5
+ before(:each) do
6
+
7
+ @backend = Plist4r::Backend.new "@plist"
8
+ Plist4r::Backend.stub(:new).and_return(@backend)
9
+
10
+ @plist_cache = Plist4r::PlistCache.new "@plist"
11
+ end
12
+
13
+ it "should set @checksum to {}" do
14
+ @plist_cache.instance_eval { @checksum }.should == {}
15
+ end
16
+
17
+ it "should set @plist to the supplied parameter" do
18
+ @plist_cache.instance_eval { @plist }.should == "@plist"
19
+ end
20
+
21
+ it "should set @backends to a Plist4r::Backend object" do
22
+ @plist_cache.instance_eval { @backend }.should == @backend
23
+ end
24
+ end
25
+
26
+ describe Plist4r::PlistCache, "#from_string" do
27
+ before(:each) do
28
+ @backend = Plist4r::Backend.new "@plist"
29
+ Plist4r::Backend.stub(:new).and_return(@backend)
30
+ @backend.stub!(:call).and_return("from_string")
31
+
32
+ @plist = Plist4r::Plist.new
33
+ @plist_cache = Plist4r::PlistCache.new @plist
34
+ @plist.stub!(:detect_plist_type).and_return("plist_type")
35
+ @plist.stub!(:file_format).and_return("file_format")
36
+ end
37
+
38
+ it "should follow the default calling path if the cached @from_string has not changed" do
39
+ @plist.instance_eval { @from_string = "from_string" }
40
+ @plist_cache.instance_eval { @from_string = "from_string" }
41
+ @plist_cache.instance_eval { @from_string_plist_type = "plist_type" }
42
+ @backend.should_not_receive(:call).with(:from_string)
43
+ @plist_cache.from_string
44
+ end
45
+
46
+ it "should call @plist.detect_plist_type if the cached @from_string_plist_type is stale, or empty" do
47
+ @plist.instance_eval { @from_string = "from_string" }
48
+ @plist.instance_eval { @plist_type = "plist_type" }
49
+ @plist.should_receive(:detect_plist_type)
50
+ @plist_cache.instance_eval { @from_string = "from_string" }
51
+ @plist_cache.instance_eval { @from_string_plist_type = "stale" }
52
+ @plist_cache.from_string
53
+ end
54
+
55
+ it "should call @plist.file_format if the @plist.file_format was changed from the cached @from_string_file_format" do
56
+ @plist.instance_eval { @from_string = "from_string" }
57
+ @plist.instance_eval { @file_format = "file_format" }
58
+ @plist.should_receive(:file_format).with("cached_file_format")
59
+ @plist_cache.instance_eval { @from_string = "from_string" }
60
+ @plist_cache.instance_eval { @from_string_file_format = "cached_file_format" }
61
+ @plist_cache.from_string
62
+ end
63
+
64
+ it "should follow the alternate calling path if the cached @from_string is stale, or empty" do
65
+ @plist.instance_eval { @from_string = "from_string" }
66
+ @plist.instance_eval { @plist_type = "plist_type" }
67
+ @plist_cache.instance_eval { @from_string = "stale" }
68
+ @plist_cache.instance_eval { @from_string_plist_type = "stale" }
69
+ @backend.should_receive(:call).with(:from_string)
70
+ @plist.should_receive(:detect_plist_type)
71
+
72
+ @plist_cache.from_string
73
+ @plist_cache.instance_eval { @from_string }.should == "from_string"
74
+ @plist_cache.instance_eval { @from_string_plist_type }.should == "plist_type".to_sym
75
+ end
76
+
77
+ it "should return @plist" do
78
+ @plist_cache.from_string.should == @plist
79
+ end
80
+ end
81
+
82
+ describe Plist4r::PlistCache, "#update_checksum_for" do
83
+ before(:each) do
84
+ @plist = Plist4r::Plist.new
85
+ @hash = @plist.instance_eval { @hash }
86
+ @plist_cache = Plist4r::PlistCache.new @plist
87
+ @checksum = @plist_cache.instance_eval { @checksum }
88
+ end
89
+
90
+ it "should call @plist.to_hash" do
91
+ @plist.should_receive(:to_hash)
92
+ @plist_cache.update_checksum_for(:fmt)
93
+ end
94
+
95
+ it "should call hash on @hash" do
96
+ @hash.should_receive(:hash)
97
+ @plist_cache.update_checksum_for(:fmt)
98
+ end
99
+
100
+ it "should call []= on @checksum with the supplied fmt" do
101
+ @checksum.should_receive(:[]=).with(:fmt,@hash.hash)
102
+ @plist_cache.update_checksum_for(:fmt)
103
+ end
104
+ end
105
+
106
+ describe Plist4r::PlistCache, "#needs_update_for" do
107
+ before(:each) do
108
+ @plist = Plist4r::Plist.new
109
+ @hash = @plist.instance_eval { @hash }
110
+ @plist_cache = Plist4r::PlistCache.new @plist
111
+ @checksum = @plist_cache.instance_eval { @checksum }
112
+ end
113
+
114
+ it "should call @plist.to_hash" do
115
+ @plist.should_receive(:to_hash)
116
+ @plist_cache.needs_update_for(:fmt)
117
+ end
118
+
119
+ it "should call hash on @hash" do
120
+ @hash.should_receive(:hash)
121
+ @plist_cache.needs_update_for(:fmt)
122
+ end
123
+
124
+ it "should call [] on @checksum with the supplied fmt" do
125
+ @checksum.should_receive(:[]).with(:fmt)
126
+ @plist_cache.needs_update_for(:fmt)
127
+ end
128
+ end
129
+
130
+ describe Plist4r::Plist, "#to_xml" do
131
+ before(:each) do
132
+ @backend = Plist4r::Backend.new "@plist"
133
+ Plist4r::Backend.stub(:new).and_return(@backend)
134
+ @backend.stub!(:call).and_return("xml_string")
135
+
136
+ @plist = Plist4r::Plist.new
137
+ @plist_cache = Plist4r::PlistCache.new @plist
138
+ @plist_cache.instance_eval { @xml = "cached_xml_string" }
139
+ @plist_cache.stub!(:needs_update_for).and_return(false)
140
+ @plist_cache.stub!(:update_checksum_for)
141
+ end
142
+
143
+ it "should follow the default calling path when the xml checksum for @hash is stale" do
144
+ @plist_cache.stub!(:needs_update_for).and_return(true)
145
+ @backend.should_receive(:call).with(:to_xml)
146
+ @plist_cache.should_receive(:update_checksum_for).with(:xml)
147
+ @plist_cache.to_xml
148
+ @plist_cache.instance_eval { @xml }.should == "xml_string"
149
+ end
150
+
151
+ it "should follow the default calling path when @xml is nil" do
152
+ @plist_cache.instance_eval { @xml = nil }
153
+ @backend.should_receive(:call).with(:to_xml)
154
+ @plist_cache.should_receive(:update_checksum_for).with(:xml)
155
+ @plist_cache.to_xml
156
+ @plist_cache.instance_eval { @xml }.should == "xml_string"
157
+ end
158
+ end
159
+
160
+ describe Plist4r::Plist, "#to_binary" do
161
+ before(:each) do
162
+ @backend = Plist4r::Backend.new "@plist"
163
+ Plist4r::Backend.stub(:new).and_return(@backend)
164
+ @backend.stub!(:call).and_return("binary_string")
165
+
166
+ @plist = Plist4r::Plist.new
167
+ @plist_cache = Plist4r::PlistCache.new @plist
168
+ @plist_cache.instance_eval { @binary = "cached_binary_string" }
169
+ @plist_cache.stub!(:needs_update_for).and_return(false)
170
+ @plist_cache.stub!(:update_checksum_for)
171
+ end
172
+
173
+ it "should follow the default calling path when the binary checksum for @hash is stale" do
174
+ @plist_cache.stub!(:needs_update_for).and_return(true)
175
+ @backend.should_receive(:call).with(:to_binary)
176
+ @plist_cache.should_receive(:update_checksum_for).with(:binary)
177
+ @plist_cache.to_binary
178
+ @plist_cache.instance_eval { @binary }.should == "binary_string"
179
+ end
180
+
181
+ it "should follow the default calling path when @binary is nil" do
182
+ @plist_cache.instance_eval { @binary = nil }
183
+ @backend.should_receive(:call).with(:to_binary)
184
+ @plist_cache.should_receive(:update_checksum_for).with(:binary)
185
+ @plist_cache.to_binary
186
+ @plist_cache.instance_eval { @binary }.should == "binary_string"
187
+ end
188
+ end
189
+
190
+ describe Plist4r::Plist, "#to_gnustep" do
191
+ before(:each) do
192
+ @backend = Plist4r::Backend.new "@plist"
193
+ Plist4r::Backend.stub(:new).and_return(@backend)
194
+ @backend.stub!(:call).and_return("gnustep_string")
195
+
196
+ @plist = Plist4r::Plist.new
197
+ @plist_cache = Plist4r::PlistCache.new @plist
198
+ @plist_cache.instance_eval { @gnustep = "cached_gnustep_string" }
199
+ @plist_cache.stub!(:needs_update_for).and_return(false)
200
+ @plist_cache.stub!(:update_checksum_for)
201
+ end
202
+
203
+ it "should follow the default calling path when the gnustep checksum for @hash is stale" do
204
+ @plist_cache.stub!(:needs_update_for).and_return(true)
205
+ @backend.should_receive(:call).with(:to_gnustep)
206
+ @plist_cache.should_receive(:update_checksum_for).with(:gnustep)
207
+ @plist_cache.to_gnustep
208
+ @plist_cache.instance_eval { @gnustep }.should == "gnustep_string"
209
+ end
210
+
211
+ it "should follow the default calling path when @gnustep is nil" do
212
+ @plist_cache.instance_eval { @gnustep = nil }
213
+ @backend.should_receive(:call).with(:to_gnustep)
214
+ @plist_cache.should_receive(:update_checksum_for).with(:gnustep)
215
+ @plist_cache.to_gnustep
216
+ @plist_cache.instance_eval { @gnustep }.should == "gnustep_string"
217
+ end
218
+ end
219
+
220
+ describe Plist4r::PlistCache, "#open" do
221
+ before(:each) do
222
+ @backend = Plist4r::Backend.new "@plist"
223
+ Plist4r::Backend.stub(:new).and_return(@backend)
224
+ @backend.stub!(:call).and_return("gnustep_string")
225
+
226
+ @plist = Plist4r::Plist.new
227
+ @plist_cache = Plist4r::PlistCache.new @plist
228
+ end
229
+
230
+ it "should call @backend.call with :open" do
231
+ @backend.should_receive(:call).with(:open)
232
+ @plist_cache.open
233
+ end
234
+
235
+ it "should return @plist" do
236
+ @plist_cache.open.should == @plist
237
+ end
238
+ end
239
+
240
+ describe Plist4r::PlistCache, "#save" do
241
+ before(:each) do
242
+ @backend = Plist4r::Backend.new "@plist"
243
+ Plist4r::Backend.stub(:new).and_return(@backend)
244
+ @backend.stub!(:call).and_return("gnustep_string")
245
+
246
+ @plist = Plist4r::Plist.new
247
+ @plist_cache = Plist4r::PlistCache.new @plist
248
+ end
249
+
250
+ it "should call @backend.call with :save" do
251
+ @plist.filename_path "filename_path"
252
+ @backend.should_receive(:call).with(:save)
253
+ @plist_cache.save
254
+ end
255
+
256
+ it "should return @plist.filename_path" do
257
+ @plist.filename_path "filename_path"
258
+ @plist_cache.save.should == @plist.filename_path
259
+ end
260
+ end
261
+
@@ -1,42 +1,860 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper"))
2
1
 
3
- module PlistSpecHelper
4
- def test_xml_plist
5
- @test_xml_plist ||= <<-'EOC'
6
- <?xml version="1.0" encoding="UTF-8"?>
7
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
8
- <plist version="1.0"><dict></dict></plist>
9
- EOC
2
+ require 'spec_helper'
3
+
4
+ describe Plist4r::Plist, "#initialize" do
5
+
6
+ before(:each) do
7
+ Plist4r::Config.stub!(:[]).with(:strict_keys).and_return("Config[:strict_keys]")
8
+ Plist4r::Config.stub!(:[]).with(:backends).and_return("Config[:backends]")
9
+ Plist4r::Config.stub!(:[]).with(:default_path).and_return("Config[:default_path]")
10
+
11
+ @plist_cache = Plist4r::PlistCache.new "@plist"
12
+ Plist4r::PlistCache.stub(:new).and_return(@plist_cache)
13
+
14
+ @plist.stub(:edit)
15
+ @plist = Plist4r::Plist.new
16
+ end
17
+
18
+ it "should return a Plist4r::Plist object" do
19
+ @plist.should be_a_kind_of(Plist4r::Plist)
20
+ end
21
+
22
+ it "should set @hash to a Plist4r::OrderedHash" do
23
+ @plist.instance_eval { @hash }.should be_a_kind_of(Plist4r::OrderedHash)
24
+ end
25
+
26
+ it "should set @strict_keys to Config[:strict_keys]" do
27
+ @plist.instance_eval { @strict_keys }.should == "Config[:strict_keys]"
28
+ end
29
+
30
+ it "should set @backends to Config[:backends]" do
31
+ @plist.instance_eval { @backends }.should == "Config[:backends]"
32
+ end
33
+
34
+ it "should set @path to Config[:default_path]" do
35
+ @plist.instance_eval { @path }.should == "Config[:default_path]"
36
+ end
37
+
38
+ it "should call parse_opts if the first argument is a Hash" do
39
+ hash = { "key" => "value" }
40
+ @plist.should_receive(:parse_opts).with(hash)
41
+ @plist.instance_eval{ initialize(hash) }
42
+ end
43
+
44
+ it "should set @filename if the first argument is a String or Symbol" do
45
+ @plist = Plist4r::Plist.new("filename")
46
+ @plist.instance_eval { @filename }.should == "filename"
47
+ @plist = Plist4r::Plist.new(:filename)
48
+ @plist.instance_eval { @filename }.should == :filename.to_s
49
+ end
50
+
51
+ it "should raise an error when the first argument is not a Hash, String, Symbol, or nil" do
52
+ not_a_hash_string_symbol_or_nil = false
53
+ lambda { Plist4r::Plist.new(not_a_hash_string_symbol_or_nil) }.should raise_error(Exception)
54
+ end
55
+
56
+ it "should set @plist_cache to a Plist4r::PlistCache object" do
57
+ @plist.instance_eval { @plist_cache }.should == @plist_cache
58
+ end
59
+
60
+ it "should call edit with block if a block is given" do
61
+ @plist.should_receive(:edit)
62
+ @plist.instance_eval{ initialize(){} }
63
+ end
64
+
65
+ it "should not call edit with block if no block is given" do
66
+ @plist.should_not_receive(:edit)
67
+ @plist.instance_eval{ initialize() }
68
+ end
69
+
70
+ end
71
+
72
+ describe Plist4r::Plist, "#from_string" do
73
+ before(:each) do
74
+ Plist4r.stub!(:string_detect_format).with("string").and_return(:plist_format)
75
+
76
+ @plist_cache = Plist4r::PlistCache.new "@plist"
77
+ @plist_cache.stub!(:from_string).and_return(@plist)
78
+ Plist4r::PlistCache.stub(:new).and_return(@plist_cache)
79
+
80
+ @plist = Plist4r::Plist.new
81
+ end
82
+
83
+ it "should call Plist4r.string_detect_format with the supplied string" do
84
+ Plist4r.should_receive(:string_detect_format).and_return(:plist_format)
85
+ @plist.from_string("string")
86
+ end
87
+
88
+ it "should not raise an exception if Plist4r.string_detect_format returns a value" do
89
+ lambda { @plist.from_string("string") }.should_not raise_error(Exception)
90
+ end
91
+
92
+ it "should call Plist4r::PlistCache.new with self when @plist_cache is nil" do
93
+ Plist4r::PlistCache.should_receive(:new).with(@plist)
94
+ @plist.instance_eval { @plist_cache = nil }
95
+ @plist.from_string("string")
96
+ end
97
+
98
+ it "should set @from_string to the supplied string and call @plist.cache.from_string" do
99
+ @plist_cache.should_receive(:from_string)
100
+ @plist.from_string("string")
101
+ @plist.instance_eval { @from_string }.should == "string"
102
+ end
103
+
104
+ it "should raise an exception if Plist4r.string_detect_format returns nil" do
105
+ Plist4r.stub!(:string_detect_format).with("string").and_return(nil)
106
+ lambda { @plist.from_string("string") }.should raise_error(Exception)
107
+ end
108
+
109
+ it "should return @from_string for an argument of nil" do
110
+ from_string = "string"
111
+ @plist.instance_eval { @from_string = from_string }
112
+ @plist.from_string.should == from_string
113
+ end
114
+
115
+ it "should raise an error for an argument that is not a string, or nil" do
116
+ not_a_string_or_nil = false
117
+ lambda { @plist.from_string(not_a_string_or_nil) }.should raise_error(Exception)
118
+ end
119
+
120
+ end
121
+
122
+ describe Plist4r::Plist, "#filename" do
123
+ before(:each) do
124
+ @plist = Plist4r::Plist.new
125
+ end
126
+
127
+ it "should raise an error when the supplied argument is not a string, or nil" do
128
+ not_a_string_or_nil = false
129
+ lambda { @plist.filename not_a_string_or_nil }.should raise_error(Exception)
130
+ end
131
+ end
132
+
133
+ describe Plist4r::Plist, "#path" do
134
+ before(:each) do
135
+ @plist = Plist4r::Plist.new
136
+ end
137
+
138
+ it "should raise an error when the supplied argument is not a string, or nil" do
139
+ not_a_string_or_nil = false
140
+ lambda { @plist.path not_a_string_or_nil }.should raise_error(Exception)
141
+ end
142
+ end
143
+
144
+ describe Plist4r::Plist, "#filename_path" do
145
+ before(:each) do
146
+ @plist = Plist4r::Plist.new
147
+ @plist.filename_path "/dirname/basename"
148
+ end
149
+
150
+ it "should set @filename to basename when given a filename path" do
151
+ @plist.instance_eval { @filename }.should == "basename"
152
+ end
153
+
154
+ it "should set @path to /dirname when given a filename path" do
155
+ @plist.instance_eval { @path }.should == "/dirname"
156
+ end
157
+
158
+ it "should return /dirname/basename when no argument is given" do
159
+ @plist.filename_path.should == "/dirname/basename"
160
+ end
161
+
162
+ it "should call File.expand_path with @filename, @path when no argument is given" do
163
+ File.should_receive(:expand_path).with("basename", "/dirname")
164
+ @plist.filename_path
165
+ end
166
+
167
+ it "should raise an error when the supplied argument is not a string, or nil" do
168
+ not_a_string_or_nil = false
169
+ lambda { @plist.filename_path not_a_string_or_nil }.should raise_error(Exception)
170
+ end
171
+ end
172
+
173
+ describe Plist4r::Plist, "#file_format" do
174
+ before(:each) do
175
+ @plist = Plist4r::Plist.new
176
+ end
177
+
178
+ it "should return @file_format when the supplied argument is nil" do
179
+ @plist.file_format "xml"
180
+ @plist.file_format.should == "xml"
181
+ @plist.file_format :xml
182
+ @plist.file_format.should == :xml.to_s
10
183
  end
11
184
 
12
- def valid_plist_attributes
13
- {
14
- :from_string => test_xml_plist,
15
- :filename => "test_xml.plist"
16
- :plist_type => "test_type"
17
- :backends => ["test"]
18
- }
185
+ it "should raise an error when the supplied argument is not a recognised plist file format" do
186
+ not_a_recognised_plist_file_format = false
187
+ lambda { @plist.file_format not_a_recognised_plist_file_format }.should raise_error(Exception)
188
+ end
189
+
190
+ it "should raise an error when the supplied argument is not a string, symbol, or nil" do
191
+ not_a_string_symbol_or_nil = false
192
+ lambda { @plist.file_format not_a_string_symbol_or_nil }.should raise_error(Exception)
193
+ end
194
+ end
195
+
196
+ describe Plist4r::Plist, "#detect_plist_type" do
197
+ before(:each) do
198
+ class Plist4r::PlistType::Type < Plist4r::PlistType
199
+ end
200
+ class Plist4r::PlistType::Type2 < Plist4r::PlistType
201
+ end
202
+ @plist = Plist4r::Plist.new
203
+ end
204
+
205
+ it "should iterate over the array of known plist types and evaluate any strings, or symbols" do
206
+ Plist4r::Config.stub!(:[]).with(:types).and_return(["type",:type])
207
+ # @plist.stub!(:eval).with("::Plist4r::PlistType::Type").and_return(Plist4r::PlistType::Type)
208
+ @plist.stub!(:eval).and_return(Plist4r::PlistType::Type)
209
+ @plist.detect_plist_type
210
+ end
211
+
212
+ it "should raise an error for a Config[:types] array element that is not a string, symbol, Class, or nil" do
213
+ Plist4r::Config.stub!(:[]).with(:types).and_return([false])
214
+ lambda { @plist.detect_plist_type }.should raise_error(Exception)
215
+ end
216
+
217
+ it "should call match_stat on each known Plist4r::PlistType" do
218
+ Plist4r::Config.stub!(:[]).with(:types).and_return([:type,:type2])
219
+ @stat_t = { :matches => 0, :ratios => "ratios" }
220
+ Plist4r::PlistType::Type.should_receive(:match_stat).and_return(@stat_t)
221
+ Plist4r::PlistType::Type2.should_receive(:match_stat).and_return(@stat_t)
222
+ Plist4r::PlistType::Type.stub!(:match_stat).and_return(@stat_t)
223
+ @plist.detect_plist_type
19
224
  end
20
225
  end
21
226
 
227
+ describe Plist4r::Plist, "#plist_type" do
228
+ before(:each) do
229
+ class Plist4r::PlistType::Type < Plist4r::PlistType
230
+ end
231
+ @plist = Plist4r::Plist.new
232
+ end
22
233
 
23
- describe Plist4r::Plist, "initialize" do
24
- before do
25
- # set expected plist object
26
- # mock and stub the method call
234
+ it "should set the default @plist_type to a kind of Plist4r::PlistType" do
235
+ @plist.instance_eval { @plist_type }.should be_a_kind_of(Plist4r::PlistType)
27
236
  end
28
237
 
29
- describe "when the first argument is not a Hash, String, or Symbol"
30
- before do
238
+ it "should set @plist_type to an instance of the supplied class" do
239
+ @plist.plist_type(Plist4r::PlistType::Type)
240
+ @plist.instance_eval { @plist_type }.should be_a_kind_of(Plist4r::PlistType::Type)
241
+ end
242
+
243
+ it "should set @plist_type to an instance of the class evaluated of the supplied string or symbol" do
244
+ @plist.stub!(:eval).and_return(Plist4r::PlistType::Type)
245
+ @plist.should_receive(:eval).with("::Plist4r::PlistType::Type")
246
+ @plist.plist_type("type")
247
+ @plist.instance_eval { @plist_type }.should be_a_kind_of(Plist4r::PlistType::Type)
248
+ end
249
+
250
+ it "should return a symbol representing the classname of the @plist_type instance" do
251
+ @plist.plist_type("type").should == :type
252
+ @plist.plist_type.should == :type
253
+ end
254
+
255
+ it "should raise an error if the supplied class is not a Plist4r::PlistType" do
256
+ not_a_plist4r_plist_type = Object
257
+ lambda { @plist.plist_type(not_a_plist4r_plist_type) }.should raise_error(Exception)
258
+ end
259
+
260
+ it "should raise an error when the supplied argument is not a class, symbol, string or nil" do
261
+ not_a_class_symbol_string_or_nil = false
262
+ lambda { @plist.plist_type(not_a_class_symbol_string_or_nil) }.should raise_error(Exception)
263
+ end
264
+ end
265
+
266
+ describe Plist4r::Plist, "#backends" do
267
+ before(:each) do
268
+ module Plist4r::Backend::Backend1
31
269
  end
270
+ module Plist4r::Backend::Backend2
271
+ end
272
+ @plist = Plist4r::Plist.new
273
+ end
274
+
275
+ it "should raise an error if one of the supplied symbols or strings are not a recognised Plist4r::Backend" do
276
+ not_a_plist4r_backend = "not_a_plist4r_backend"
277
+ lambda { @plist.backends([not_a_plist4r_backend]) }.should raise_error(Exception)
278
+ end
279
+
280
+ it "should set @backends to an array of valid backend symbols (or strings)" do
281
+ @plist.backends([:backend1, :backend2])
282
+ @plist.instance_eval { @backends }.should == [:backend1, :backend2]
283
+ @plist.backends(["backend1", "backend2"])
284
+ @plist.instance_eval { @backends }.should == [:backend1, :backend2]
285
+ end
286
+
287
+ it "should raise an error if the supplied array contains an element that is not a symbol, string, or nil" do
288
+ not_a_symbol_string_or_nil = false
289
+ lambda { @plist.backends([not_a_symbol_string_or_nil]) }.should raise_error(Exception)
290
+ end
291
+
292
+ it "should return @backends when supplied with a nil argument" do
293
+ @plist.instance_eval { @backends = "backends" }
294
+ @plist.backends.should == "backends"
295
+ end
296
+
297
+ it "should raise an error when the supplied argument is not an array, or nil" do
298
+ not_an_array_or_nil = false
299
+ lambda { @plist.backends(not_an_array_or_nil) }.should raise_error(Exception)
300
+ end
301
+ end
302
+
303
+ describe Plist4r::Plist, "#parse_opts" do
304
+ before(:each) do
305
+ class Plist4r::Plist
306
+ OldOptionsHash = OptionsHash
307
+ end
308
+ @plist = Plist4r::Plist.new
309
+ end
310
+
311
+ it "should call any methods on @plist, that are included in OptionsHash and the supplied hash of options" do
312
+ Plist4r::Plist::OptionsHash.replace [:meth1, "meth2"]
313
+ @plist.stub!(:meth1)
314
+ @plist.stub!(:meth2)
315
+ @plist.should_receive(:meth1).with("meth1arg")
316
+ @plist.should_receive(:meth2).with("meth2arg")
317
+ @plist.parse_opts({ :meth1 => "meth1arg", :meth2 => "meth2arg" })
318
+
319
+ end
320
+
321
+ after(:all) do
322
+ class Plist4r::Plist
323
+ OptionsHash.replace OldOptionsHash
324
+ end
325
+ end
326
+ end
327
+
328
+ describe Plist4r::Plist, "#open" do
329
+ before(:each) do
330
+ @plist_cache = Plist4r::PlistCache.new "@plist"
331
+ @plist_cache.stub(:open)
332
+ Plist4r::PlistCache.stub(:new).and_return(@plist_cache)
333
+ @plist = Plist4r::Plist.new
334
+ end
335
+
336
+ it "should set @filename to the supplied string" do
337
+ @plist.open("filename")
338
+ @plist.instance_eval { @filename }.should == "filename"
339
+ end
340
+
341
+ it "should raise an error unless @filename is non-nil" do
342
+ lambda { @plist.open }.should raise_error(Exception)
343
+ end
344
+
345
+ it "should call @plist_cache.open" do
346
+ @plist_cache.should_receive(:open).twice
347
+ @plist.open("filename")
348
+ @plist.open
349
+ end
350
+ end
351
+
352
+ describe Plist4r::Plist, "#<<" do
353
+ before(:each) do
354
+ @plist = Plist4r::Plist.new
355
+ end
356
+
357
+ it "should call edit with the supplied arguments" do
358
+ edit_args = [:arg1, :arg2, :etc]
359
+ @plist.should_receive(:edit).with(edit_args)
360
+ @plist.<< edit_args
361
+ end
362
+ end
363
+
364
+ describe Plist4r::Plist, "#edit" do
365
+ before(:each) do
366
+ @plist = Plist4r::Plist.new
367
+ @plist.stub(:instance_eval)
368
+ end
369
+
370
+ it "should call instance_eval with the supplied arguments" do
371
+ edit_args = [:arg1, :arg2, :etc]
372
+ @plist.should_receive(:instance_eval).with(edit_args)
373
+ @plist.edit edit_args
374
+ end
375
+
376
+ it "should call detect_plist_type" do
377
+ edit_args = [:arg1, :arg2, :etc]
378
+ @plist.should_receive(:detect_plist_type)
379
+ @plist.edit edit_args
380
+ end
381
+ end
382
+
383
+ describe Plist4r::Plist, "#method_missing" do
384
+ before(:each) do
385
+ @plist = Plist4r::Plist.new
386
+ @plist_type = Plist4r::PlistType::Plist.new @plist
387
+ @plist_type.stub(:method_missing)
388
+ Plist4r::PlistType::Plist.stub(:new).and_return(@plist_type)
389
+ @plist = Plist4r::Plist.new
390
+ end
32
391
 
392
+ it "should call @plist_type.send with the supplied arguments" do
393
+ method_missing_args = [:method_sym, :arg1, :arg2, :etc]
394
+ @plist_type.should_receive(:method_missing).with(method_missing_args)
395
+ @plist.method_missing(method_missing_args)
396
+ end
397
+ end
398
+
399
+ describe Plist4r::Plist, "#import_hash" do
400
+ before(:each) do
401
+ @plist = Plist4r::Plist.new
402
+ end
403
+
404
+ it "should set @hash to be a kind of ordered hash when the supplied argument is nil" do
405
+ @plist.import_hash
406
+ @plist.instance_eval { @hash }.should be_a_kind_of(Plist4r::OrderedHash)
407
+ end
408
+
409
+ it "should set @hash to be the supplied ordered hash" do
410
+ ordered_hash = Plist4r::OrderedHash.new :key1 => "value1", :key2 => "value2"
411
+ @plist.import_hash(ordered_hash)
412
+ @plist.instance_eval { @hash }.should == ordered_hash
413
+ end
414
+
415
+ it "should raise an error when the supplied argument is not an ordered hash, or nil" do
416
+ not_an_ordered_hash_or_nil = false
417
+ lambda { @plist.import_hash(not_an_ordered_hash_or_nil) }.should raise_error(Exception)
418
+ end
419
+ end
420
+
421
+ describe Plist4r::Plist, "#[]" do
422
+ before(:each) do
423
+ @plist = Plist4r::Plist.new
424
+ @plist_type = Plist4r::PlistType::Plist.new @plist
425
+ @plist_type.stub(:method_missing)
426
+ Plist4r::PlistType::Plist.stub(:new).and_return(@plist_type)
427
+
428
+ @plist = Plist4r::Plist.new do
429
+ key1 "value1"
430
+ key2 "value2"
431
+ end
432
+ end
433
+
434
+ it "should call set_or_return on @plist_type with the supplied key" do
435
+ @plist_type.should_receive(:set_or_return).with("Key1")
436
+ @plist["Key1"]
437
+ end
438
+ end
439
+
440
+ describe Plist4r::Plist, "#[]=" do
441
+ before(:each) do
442
+ @plist = Plist4r::Plist.new
443
+ end
444
+
445
+ it "should call store with the supplied key and value" do
446
+ @plist.should_receive(:store).with("Key1","value1")
447
+ @plist["Key1"] = "value1"
448
+ end
449
+ end
450
+
451
+ describe Plist4r::Plist, "#store" do
452
+ before(:each) do
453
+ @plist = Plist4r::Plist.new
454
+ @plist_type = Plist4r::PlistType::Plist.new @plist
455
+ @plist_type.stub(:method_missing)
456
+ Plist4r::PlistType::Plist.stub(:new).and_return(@plist_type)
457
+ @plist = Plist4r::Plist.new
458
+ end
459
+
460
+ it "should call set_or_return on @plist_type with the supplied key and value" do
461
+ @plist_type.should_receive(:set_or_return).with("Key1","value1")
462
+ @plist["Key1"] = "value1"
463
+ end
464
+ end
465
+
466
+ describe Plist4r::Plist, "#select" do
467
+ before(:each) do
468
+ @plist = Plist4r::Plist.new
469
+ @plist_type = Plist4r::PlistType::Plist.new @plist
470
+ @plist_type.stub(:method_missing)
471
+ Plist4r::PlistType::Plist.stub(:new).and_return(@plist_type)
472
+ @plist = Plist4r::Plist.new do
473
+ key1 "value1"
474
+ key2 "value2"
475
+ end
476
+
477
+ @hash = @plist.to_hash
478
+ @hash.stub(:select).and_return([["Key1", "value1"],["Key2", "value2"]])
479
+ @hash_copy = Plist4r::OrderedHash.new
480
+ @hash_copy.store "Key1", "value1"
481
+ @hash_copy.store "Key2", "value2"
482
+ @hash.stub(:deep_clone).and_return(@hash_copy)
483
+ end
484
+
485
+ it "should call block_given?" do
486
+ @plist.stub!(:block_given?).and_return(true)
487
+ @plist.should_receive(:block_given?)
488
+ @plist.select
489
+ end
490
+
491
+ describe "when a block is given" do
492
+ it "should follow the default calling path" do
493
+ @hash.should_receive(:select)
494
+ @hash.should_receive(:deep_clone)
495
+ @plist.should_receive(:clear)
496
+ @plist.should_receive(:store).exactly(4).times
497
+
498
+ @plist.select :key1, :key2 do
499
+ true
500
+ end
501
+ end
502
+ end
503
+
504
+ describe "when no block is given" do
505
+ it "should follow the alternate calling path" do
506
+ @plist_type.should_receive(:array_dict).with(:select, :key1, :key2)
507
+ @plist.select :key1, :key2
508
+ end
509
+ end
510
+ end
511
+
512
+ describe Plist4r::Plist, "#map" do
513
+ before(:each) do
514
+ @plist = Plist4r::Plist.new
515
+ @plist_type = Plist4r::PlistType::Plist.new @plist
516
+ @plist_type.stub(:method_missing)
517
+ Plist4r::PlistType::Plist.stub(:new).and_return(@plist_type)
518
+
519
+ @plist = Plist4r::Plist.new do
520
+ key1 "value1"
521
+ key2 "value2"
522
+ end
523
+
524
+ @hash = @plist.to_hash
525
+ @hash.stub(:select).and_return([["Key1", "value1"],["Key2", "value2"]])
526
+ @hash_copy = Plist4r::OrderedHash.new
527
+ @hash_copy.store "Key1", "value1"
528
+ @hash_copy.store "Key2", "value2"
529
+ @hash.stub(:deep_clone).and_return(@hash_copy)
530
+ end
531
+
532
+ it "should call block_given?" do
533
+ @plist.stub!(:block_given?).and_return(true)
534
+ @plist.should_receive(:block_given?)
535
+ @plist.map do
536
+ end
537
+ end
538
+
539
+ describe "when a block is given" do
540
+ it "should follow the default calling path" do
541
+ @plist.stub!(:yield).and_return(["SomeKey","some value"])
542
+ @hash.should_receive(:deep_clone)
543
+ @plist.should_receive(:clear)
544
+ @hash_copy.should_receive(:each).once
545
+
546
+ @plist.map do |k,v|
547
+ [k,v]
548
+ end
549
+ end
550
+ end
551
+
552
+ describe "when no block is given" do
33
553
  it "should raise an error" do
554
+ lambda { @plist.map }.should raise_error(Exception)
34
555
  end
35
556
  end
557
+ end
36
558
 
37
- it "should return the new Plist object" do
38
- # .should_be an_instance_of(::Plist4r::Plist)
559
+ describe Plist4r::Plist, "#collect" do
560
+ before(:each) do
561
+ @plist = Plist4r::Plist.new
562
+ end
563
+
564
+ it "should call map" do
565
+ @plist.should_receive(:map)
566
+ @plist.collect do |k,v|
567
+ [k,v]
568
+ end
569
+ end
570
+ end
571
+
572
+ describe Plist4r::Plist, "#unselect" do
573
+ before(:each) do
574
+ @plist = Plist4r::Plist.new
575
+ end
576
+
577
+ it "should call delete with the supplied keys" do
578
+ @plist.should_receive(:delete).with(:arg1, :arg2)
579
+ @plist.unselect :arg1, :arg2
580
+ end
581
+ end
582
+
583
+ describe Plist4r::Plist, "#delete" do
584
+ before(:each) do
585
+ @plist = Plist4r::Plist.new
586
+ @plist_type = Plist4r::PlistType::Plist.new @plist
587
+ @plist_type.stub(:method_missing)
588
+ Plist4r::PlistType::Plist.stub(:new).and_return(@plist_type)
589
+ @plist = Plist4r::Plist.new do
590
+ key1 "value1"
591
+ key2 "value2"
592
+ end
593
+ end
594
+
595
+ it "should call @plist_type.array_dict with :unselect and the suppled keys" do
596
+ @plist_type.should_receive(:array_dict).with(:unselect, :key1, :key2)
597
+ @plist.unselect :key1, :key2
598
+ end
599
+ end
600
+
601
+ describe Plist4r::Plist, "#delete_if" do
602
+ before(:each) do
603
+ @plist = Plist4r::Plist.new
604
+ @plist_type = Plist4r::PlistType::Plist.new @plist
605
+ @plist_type.stub(:method_missing)
606
+ Plist4r::PlistType::Plist.stub(:new).and_return(@plist_type)
607
+ @plist = Plist4r::Plist.new do
608
+ key1 "value1"
609
+ key2 "value2"
610
+ end
611
+
612
+ @hash = @plist.to_hash
613
+ @hash.stub(:select).and_return([["Key1", "value1"],["Key2", "value2"]])
614
+ @hash_copy = Plist4r::OrderedHash.new
615
+ @hash_copy.store "Key1", "value1"
616
+ @hash_copy.store "Key2", "value2"
617
+ # @hash.stub(:deep_clone).and_return(@hash_copy)
618
+ end
619
+
620
+ it "should call delete with the supplied keys" do
621
+ @plist.should_receive(:delete).with(:arg1, :arg2)
622
+ @plist.delete_if :arg1, :arg2
623
+ end
624
+
625
+ it "should call @hash.delete_if" do
626
+ @hash.should_receive(:delete_if)
627
+ @plist.delete_if :arg1, :arg2
628
+ end
629
+
630
+ it "should call @plist_type.hash with @hash" do
631
+ @plist_type.should_receive(:hash).with(@hash)
632
+ @plist.delete_if :arg1, :arg2
633
+ end
634
+ end
635
+
636
+ describe Plist4r::Plist, "#clear" do
637
+ before(:each) do
638
+ @plist = Plist4r::Plist.new
639
+ @plist_type = Plist4r::PlistType::Plist.new @plist
640
+ @plist_type.stub(:method_missing)
641
+ Plist4r::PlistType::Plist.stub(:new).and_return(@plist_type)
642
+ @plist = Plist4r::Plist.new do
643
+ key1 "value1"
644
+ key2 "value2"
645
+ end
646
+ end
647
+
648
+ it "should call @plist_type.array_dict with :unselect_all" do
649
+ @plist_type.should_receive(:array_dict).with(:unselect_all)
650
+ @plist.clear
39
651
  end
40
652
  end
41
653
 
654
+ describe Plist4r::Plist, "#merge!" do
655
+ before(:each) do
656
+ @plist = Plist4r::Plist.new
657
+ @plist_type = Plist4r::PlistType::Plist.new @plist
658
+ @plist_type.stub(:method_missing)
659
+ Plist4r::PlistType::Plist.stub(:new).and_return(@plist_type)
660
+
661
+ @plist = Plist4r::Plist.new
662
+ @hash = @plist.to_hash
663
+
664
+ @other_plist = Plist4r::Plist.new
665
+ @other_hash = @other_plist.to_hash
666
+ end
667
+
668
+ it "should call plist_type" do
669
+ @plist.should_receive(:plist_type)
670
+ @other_plist.should_receive(:plist_type)
671
+ @plist.merge! @other_plist
672
+ end
673
+
674
+ it "should follow the default calling path is the plist_type matches" do
675
+ @plist.stub!(:plist_type).and_return(:plist_type)
676
+ @other_plist.stub!(:plist_type).and_return(:plist_type)
677
+ @hash.should_receive(:merge!).with(@other_hash)
678
+ @plist_type.should_receive(:hash).with(@hash)
679
+
680
+ @plist.merge! @other_plist
681
+ end
682
+
683
+ it "should raise an error if the plist_type differs" do
684
+ @plist.stub!(:plist_type).and_return(:plist_type1)
685
+ @other_plist.stub!(:plist_type).and_return(:plist_type2)
686
+ lambda { @plist.merge! @other_plist }.should raise_error(Exception)
687
+ end
688
+
689
+ end
690
+
691
+ describe Plist4r::Plist, "#include?" do
692
+ before(:each) do
693
+ @plist = Plist4r::Plist.new
694
+ @hash = @plist.to_hash
695
+ @key = "Key"
696
+ end
697
+
698
+ it "should call @hash.include? with the supplied key" do
699
+ @hash.should_receive(:include?).with(@key)
700
+ @plist.include? @key
701
+ end
702
+ end
703
+
704
+ describe Plist4r::Plist, "#has_key?" do
705
+ before(:each) do
706
+ @plist = Plist4r::Plist.new
707
+ @hash = @plist.to_hash
708
+ @key = "Key"
709
+ end
710
+
711
+ it "should call @hash.has_key? with the supplied key" do
712
+ @hash.should_receive(:has_key?).with(@key)
713
+ @plist.has_key? @key
714
+ end
715
+ end
716
+
717
+ describe Plist4r::Plist, "#empty?" do
718
+ before(:each) do
719
+ @plist = Plist4r::Plist.new
720
+ @hash = @plist.to_hash
721
+ end
722
+
723
+ it "should call @hash.empty?" do
724
+ @hash.should_receive(:empty?)
725
+ @plist.empty?
726
+ end
727
+ end
728
+
729
+ describe Plist4r::Plist, "#each" do
730
+ before(:each) do
731
+ @plist = Plist4r::Plist.new
732
+ @hash = @plist.to_hash
733
+ end
734
+
735
+ it "should call @hash.each" do
736
+ @hash.should_receive(:each)
737
+ @plist.each
738
+ end
739
+ end
740
+
741
+ describe Plist4r::Plist, "#length" do
742
+ before(:each) do
743
+ @plist = Plist4r::Plist.new
744
+ @hash = @plist.to_hash
745
+ end
746
+
747
+ it "should call @hash.length" do
748
+ @hash.should_receive(:length)
749
+ @plist.length
750
+ end
751
+ end
752
+
753
+ describe Plist4r::Plist, "#size" do
754
+ before(:each) do
755
+ @plist = Plist4r::Plist.new
756
+ @hash = @plist.to_hash
757
+ end
758
+
759
+ it "should call @hash.size" do
760
+ @hash.should_receive(:size)
761
+ @plist.size
762
+ end
763
+ end
764
+
765
+ describe Plist4r::Plist, "#keys" do
766
+ before(:each) do
767
+ @plist = Plist4r::Plist.new
768
+ @hash = @plist.to_hash
769
+ end
770
+
771
+ it "should call @hash.keys" do
772
+ @hash.should_receive(:keys)
773
+ @plist.keys
774
+ end
775
+ end
776
+
777
+ describe Plist4r::Plist, "#to_hash" do
778
+ before(:each) do
779
+ @plist = Plist4r::Plist.new
780
+ end
781
+
782
+ it "should return @hash" do
783
+ @plist.to_hash.should == @plist.instance_eval { @hash }
784
+ end
785
+ end
786
+
787
+ describe Plist4r::Plist, "#to_xml" do
788
+ before(:each) do
789
+ @plist_cache = Plist4r::PlistCache.new "@plist"
790
+ Plist4r::PlistCache.stub(:new).and_return(@plist_cache)
791
+ @plist = Plist4r::Plist.new
792
+ end
793
+
794
+ it "should call @plist_cache.to_xml" do
795
+ @plist_cache.should_receive(:to_xml)
796
+ @plist.to_xml
797
+ end
798
+ end
799
+
800
+ describe Plist4r::Plist, "#to_binary" do
801
+ before(:each) do
802
+ @plist_cache = Plist4r::PlistCache.new "@plist"
803
+ Plist4r::PlistCache.stub(:new).and_return(@plist_cache)
804
+ @plist = Plist4r::Plist.new
805
+ end
806
+
807
+ it "should call @plist_cache.to_binary" do
808
+ @plist_cache.should_receive(:to_binary)
809
+ @plist.to_binary
810
+ end
811
+ end
812
+
813
+ describe Plist4r::Plist, "#to_gnustep" do
814
+ before(:each) do
815
+ @plist_cache = Plist4r::PlistCache.new "@plist"
816
+ Plist4r::PlistCache.stub(:new).and_return(@plist_cache)
817
+ @plist = Plist4r::Plist.new
818
+ end
819
+
820
+ it "should call @plist_cache.to_gnustep" do
821
+ @plist_cache.should_receive(:to_gnustep)
822
+ @plist.to_gnustep
823
+ end
824
+ end
825
+
826
+ describe Plist4r::Plist, "#save" do
827
+ before(:each) do
828
+ @plist_cache = Plist4r::PlistCache.new "@plist"
829
+ Plist4r::PlistCache.stub(:new).and_return(@plist_cache)
830
+ @plist = Plist4r::Plist.new
831
+ end
832
+
833
+ it "should raise an error if @filename is nil" do
834
+ lambda { @plist.save }.should raise_error(Exception)
835
+ end
836
+
837
+ it "should call @plist_cache.save" do
838
+ @plist.filename "filename"
839
+ @plist_cache.should_receive(:save)
840
+ @plist.save
841
+ end
842
+ end
843
+
844
+ describe Plist4r::Plist, "#save_as" do
845
+ before(:each) do
846
+ @plist = Plist4r::Plist.new
847
+ @plist.stub!(:save)
848
+ end
849
+
850
+ it "should set @filename to the supplied filename" do
851
+ @plist.save_as "filename"
852
+ @plist.instance_eval { @filename }.should == "filename"
853
+ end
854
+
855
+ it "should call save" do
856
+ @plist.should_receive(:save)
857
+ @plist.save_as "filename"
858
+ end
859
+ end
42
860