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,37 @@
1
+
2
+ require 'spec_helper'
3
+ require "plist4r/application"
4
+
5
+ describe Plist4r::Application, "#initialize" do
6
+ before(:each) do
7
+ @cli = Plist4r::CLI.new
8
+ Plist4r::CLI.stub(:new).and_return(@cli)
9
+ @mixlib_cli_args = {}
10
+ @cli.stub(:parse).and_return(@mixlib_cli_args)
11
+
12
+ @commands = Plist4r::Commands.new
13
+ Plist4r::Commands.stub(:new).and_return(@commands)
14
+
15
+ @application = Plist4r::Application.new
16
+ end
17
+
18
+ it "should set Plist4r::Config[:args] to a Hash" do
19
+ Plist4r::Config[:args].should be_a_kind_of(Hash)
20
+ end
21
+
22
+ it "should set @cli to a Plist4r::CLI object" do
23
+ @application.instance_eval { @cli }.should be_a_kind_of(Plist4r::CLI)
24
+ end
25
+
26
+ it "should set @commands to a Plist4r::Commands object" do
27
+ @application.instance_eval { @commands }.should be_a_kind_of(Plist4r::Commands)
28
+ end
29
+
30
+ it "should follow the default calling path" do
31
+ @cli.should_receive(:parse)
32
+ Plist4r::Config.should_receive(:[]=).with(:args,@mixlib_cli_args)
33
+ @commands.should_receive(:run)
34
+ @application.instance_eval { initialize }
35
+ end
36
+ end
37
+
@@ -0,0 +1,256 @@
1
+
2
+ require 'spec_helper'
3
+
4
+ describe Plist4r::Backend, "#initialize" do
5
+ before(:each) do
6
+ @plist = Plist4r::Plist.new
7
+ @backend = Plist4r::Backend.new @plist
8
+ end
9
+
10
+ it "should set @plist to the supplied plist" do
11
+ @backend.instance_eval { @plist }.should == @plist
12
+ end
13
+ end
14
+
15
+ describe Plist4r::Backend, "#generic_call" do
16
+ before(:each) do
17
+ class Plist4r::Backend::Test
18
+ def respond_to? meth, private=false
19
+ return true if meth.to_s == "to_format"
20
+ return true if meth.to_s == "from_format"
21
+ return false
22
+ end
23
+ end
24
+ @backend_module_const = Plist4r::Backend::Test.new
25
+
26
+ @plist_cache = Plist4r::PlistCache.new "@plist"
27
+ Plist4r::PlistCache.stub(:new).and_return(@plist_cache)
28
+
29
+ @plist_cache.stub!(:send).with(:to_format).and_return("plist_string_of_type_format")
30
+ @plist_cache.stub!(:send).with(:from_string).and_return(@plist)
31
+
32
+ @plist = Plist4r::Plist.new
33
+ @plist.stub!(:file_format).and_return(:format)
34
+ @plist.stub!(:filename_path).and_return("filename_path")
35
+ @plist.stub!(:from_string).and_return("plist_string_of_type_format")
36
+
37
+ @backend = Plist4r::Backend.new @plist
38
+ File.stub(:open).with("filename_path",'w').and_yield("plist_string_of_type_format")
39
+
40
+ File.stub(:read).with("filename_path").and_return("plist_string_of_type_format")
41
+ Plist4r.stub!(:string_detect_format).with("plist_string_of_type_format").and_return("format")
42
+ end
43
+
44
+ it "should follow the :save calling path when he supplied method_sym is :save" do
45
+ @plist.should_receive(:file_format).and_return(:format)
46
+ @backend_module_const.stub!(:respond_to?).and_return(true)
47
+ @backend_module_const.should_receive(:respond_to?).with("to_format")
48
+ File.should_receive(:open).with("filename_path",'w').and_yield("plist_string_of_type_format")
49
+ @backend.generic_call(@backend_module_const,:save)
50
+ end
51
+
52
+ it "should call Plist4r::Config[:default_format] if @plist.file_format is nil" do
53
+ @plist.stub!(:file_format).and_return(nil)
54
+ Plist4r::Config.stub!(:[]).with(:default_format).and_return(:format)
55
+ Plist4r::Config.should_receive(:[]).with(:default_format).and_return(:format)
56
+ @backend.generic_call(@backend_module_const,:save)
57
+ end
58
+
59
+ it "should return an exception when the supplied backend has no matching to_fmt save method" do
60
+ @backend_module_const.stub!(:respond_to?).and_return(false)
61
+ @backend.generic_call(@backend_module_const,:save).should be_a_kind_of(Exception)
62
+ end
63
+
64
+ it "should follow the :open calling path when he supplied method_sym is :open" do
65
+ # @plist.should_receive(:instance_eval).with("@from_string = File.read(filename_path)")
66
+ # @plist.should_receive(:instance_eval)
67
+ Plist4r.should_receive(:string_detect_format).with("plist_string_of_type_format").and_return("format")
68
+ @plist_cache.should_receive(:send).with(:from_string)
69
+ @backend_module_const.stub!(:respond_to?).and_return(true)
70
+ @backend_module_const.should_receive(:respond_to?).with("from_format")
71
+
72
+ @backend.generic_call(@backend_module_const,:open)
73
+ @backend.instance_eval { @from_string_fmt }.should == "format"
74
+ end
75
+
76
+ it "should return an exception when the supplied backend has no matching from_fmt open method" do
77
+ @backend_module_const.stub!(:respond_to?).and_return(false)
78
+ @backend.generic_call(@backend_module_const,:open).should be_a_kind_of(Exception)
79
+ end
80
+
81
+ it "should follow the :from_string calling path when he supplied method_sym is :from_string" do
82
+ Plist4r.should_receive(:string_detect_format).with("plist_string_of_type_format").and_return("format")
83
+ @backend_module_const.stub!(:respond_to?).and_return(true)
84
+ @backend_module_const.should_receive(:respond_to?).with("from_format")
85
+ @backend_module_const.stub!(:send).with(:from_format, @plist)
86
+ @backend_module_const.should_receive(:send).with(:from_format, @plist)
87
+ @plist.should_receive(:file_format).with("format")
88
+
89
+ @backend.generic_call(@backend_module_const,:from_string)
90
+ end
91
+
92
+ it "should return an exception when the supplied backend has no matching from_fmt method" do
93
+ @backend_module_const.stub!(:respond_to?).and_return(false)
94
+ @backend.generic_call(@backend_module_const,:from_string).should be_a_kind_of(Exception)
95
+ end
96
+ end
97
+
98
+ describe Plist4r::Backend, "#call" do
99
+ before(:each) do
100
+ module Plist4r::Backend::Backend1
101
+ end
102
+ module Plist4r::Backend::Backend2
103
+ end
104
+ module Plist4r::Backend::Backend3
105
+ end
106
+
107
+ @plist = Plist4r::Plist.new
108
+ @backend = Plist4r::Backend.new @plist
109
+ Plist4r::Config.stub(:[]).with(:backend_timeout).and_return(15)
110
+ Plist4r::Config.stub(:[]).with(:raise_any_failure).and_return(false)
111
+ $stderr.stub(:puts)
112
+ end
113
+
114
+ it "should raise an error if the supplied method_sym isnt a PlistCacheApiMethod" do
115
+ lambda { @backend.call :not_a_plist_cache_api_method }.should raise_error(Exception)
116
+ end
117
+
118
+ describe "when method_sym is any type of PlistCacheApiMethod" do
119
+ before(:each) do
120
+ @method_sym = :open
121
+ end
122
+
123
+ describe "when there is only one backend that implements method_sym" do
124
+ before(:each) do
125
+ @backends = [:backend1]
126
+ @plist.stub!(:backends).and_return(@backends)
127
+ end
128
+
129
+ it "should follow the default calling path when the supplied method_sym is valid and the first backend implements it" do
130
+ module Plist4r::Backend::Backend1
131
+ class << self
132
+ def open plist
133
+ return plist
134
+ end
135
+ end
136
+ end
137
+ @plist.should_receive(:backends).and_return(@backends)
138
+ @backends.should_receive(:each).and_yield(:backend1)
139
+ Plist4r::Config.should_receive(:[]).with(:backend_timeout)
140
+ # Timeout.should_receive(:timeout)
141
+ # Plist4r::Backend::Backend.should_receive(:respond_to?).with(@method_sym)
142
+ # Plist4r::Backend::Backend.should_receive(:send).with(@method_sym, @plist)
143
+ Plist4r::Backend::Backend1.should_receive(@method_sym).with(@plist).and_return(@plist)
144
+ @backend.call(@method_sym).should == @plist
145
+ end
146
+
147
+ it "should raise an error when the only backend that implements method_sym raises an error" do
148
+ @plist.should_receive(:backends).and_return(@backends)
149
+ @backends.should_receive(:each).and_yield(:backend1)
150
+ Plist4r::Config.should_receive(:[]).with(:backend_timeout)
151
+ # Timeout.should_receive(:timeout)
152
+ # Plist4r::Backend::Backend.should_receive(:respond_to?).with(@method_sym)
153
+ # Plist4r::Backend::Backend.should_receive(:send).with(@method_sym, @plist)
154
+ Plist4r::Backend::Backend1.stub(@method_sym).with(@plist).and_raise(Exception)
155
+ Plist4r::Backend::Backend1.should_receive(@method_sym).with(@plist).and_raise(Exception)
156
+ lambda { @backend.call @method_sym }.should raise_error(Exception)
157
+ end
158
+ end
159
+ end
160
+
161
+ describe "when method_sym is a direct call ApiMethod (eg to_xml, to_binary, etc)" do
162
+ before(:each) do
163
+ @method_sym = :to_xml
164
+ end
165
+
166
+ describe "when there are 2 matching backends which implement method_sym and one which does not" do
167
+ before(:each) do
168
+ module Plist4r::Backend::Backend1
169
+ class << self
170
+ def to_xml plist
171
+ return "xml_string"
172
+ end
173
+ end
174
+ end
175
+ module Plist4r::Backend::Backend3
176
+ class << self
177
+ def to_xml plist
178
+ return "xml_string"
179
+ end
180
+ end
181
+ end
182
+ @backends = [:backend1,:backend2,:backend3]
183
+ @plist.stub!(:backends).and_return(@backends)
184
+ end
185
+
186
+ it "should not raise an error when at least 1 backend which implements method_sym does not raise an error" do
187
+ Plist4r::Backend::Backend1.stub(@method_sym).with(@plist).and_raise(Exception)
188
+ lambda { @backend.call @method_sym }.should_not raise_error(Exception)
189
+ end
190
+
191
+ it "should raise an error when all backends which implement method_sym raise an error" do
192
+ Plist4r::Backend::Backend1.stub(@method_sym).with(@plist).and_raise(Exception)
193
+ Plist4r::Backend::Backend3.stub(@method_sym).with(@plist).and_raise(Exception)
194
+ lambda { @backend.call @method_sym }.should raise_error(Exception)
195
+ end
196
+
197
+ describe "when the first backend raises an error, and the second backend does not" do
198
+ before(:each) do
199
+ Plist4r::Backend::Backend1.stub(@method_sym).with(@plist).and_raise(Exception)
200
+ end
201
+
202
+ it "should call method_sym on the second available backend" do
203
+ Plist4r::Backend::Backend1.stub(@method_sym).with(@plist).and_raise(Exception)
204
+ Plist4r::Backend::Backend3.should_receive(@method_sym).with(@plist)
205
+ lambda { @backend.call @method_sym }.should_not raise_error(Exception)
206
+ end
207
+
208
+ it "should raise an error when Config[:raise_any_failure] is true" do
209
+ Plist4r::Config.stub(:[]).with(:raise_any_failure).and_return(true)
210
+ lambda { @backend.call @method_sym }.should raise_error(Exception)
211
+ end
212
+ end
213
+ end
214
+ end
215
+
216
+ describe "when method_sym is a PrivateApiMethod (eg from_string, open, save etc)" do
217
+ before(:each) do
218
+ @method_sym = :from_string
219
+ end
220
+
221
+ describe "when the highest priority backend does not implement method_sym directly" do
222
+ before(:each) do
223
+ @backends = [:backend1,:backend2,:backend3]
224
+ @plist.stub!(:backends).and_return(@backends)
225
+ @backend.stub(:generic_call)
226
+ end
227
+
228
+ it "should call generic_call with the first backend module constant and the PrivateApiMethod method_sym" do
229
+ @backend.should_receive(:generic_call).with(Plist4r::Backend::Backend1,@method_sym)
230
+ @backend.call @method_sym
231
+ end
232
+
233
+ describe "when generic_call returns a valid value which is not an Exception" do
234
+ before(:each) do
235
+ @backend.stub(:generic_call).and_return(@plist)
236
+ end
237
+
238
+ it "should not call subsequent backends" do
239
+ @backend.should_not_receive(:generic_call).with(Plist4r::Backend::Backend2,@method_sym)
240
+ @backend.should_not_receive(:generic_call).with(Plist4r::Backend::Backend3,@method_sym)
241
+ @backend.call @method_sym
242
+ end
243
+
244
+ it "should not raise an error" do
245
+ lambda { @backend.call @method_sym }.should_not raise_error(Exception)
246
+ end
247
+
248
+ it "should return that value" do
249
+ @backend.call(@method_sym).should == @plist
250
+ end
251
+ end
252
+ end
253
+ end
254
+
255
+ end
256
+
@@ -0,0 +1,25 @@
1
+
2
+ require 'spec_helper'
3
+ require "plist4r/cli"
4
+
5
+ describe Plist4r::CLI, "#plist4r_cli_options" do
6
+ it "should call option to define cli options" do
7
+ Plist4r::CLI.should_receive(:option).at_least(:once)
8
+ Plist4r::CLI.plist4r_cli_options
9
+ end
10
+ end
11
+
12
+ describe Plist4r::CLI, "#parse" do
13
+ before(:each) do
14
+ @cli = Plist4r::CLI.new
15
+ @cli.stub(:parse_options)
16
+ @cli.stub(:config)
17
+ @argv = ["arg1","arg2","etc..."]
18
+ end
19
+
20
+ it "should follow the default calling path" do
21
+ @cli.should_receive(:parse_options).with(@argv)
22
+ @cli.should_receive(:config)
23
+ @cli.parse(@argv)
24
+ end
25
+ end
@@ -0,0 +1,20 @@
1
+
2
+ require 'spec_helper'
3
+ require "plist4r/commands"
4
+
5
+ describe Plist4r::Commands, "#run" do
6
+ before(:each) do
7
+ Plist4r::Config[:args] = { :ruby_lib => true }
8
+ @commands = Plist4r::Commands.new
9
+ @commands.stub(:ruby_lib)
10
+ end
11
+ it "should follow the default calling path" do
12
+ Plist4r::Commands::PriorityOrder.should_receive(:each).and_yield(:ruby_lib)
13
+ Plist4r::Config[:args].should_receive(:[]).with(:ruby_lib).and_return(true)
14
+ Plist4r::Config[:args].should_receive(:keys).and_return([:ruby_lib])
15
+ Plist4r::Config[:args].should_receive(:each).and_yield(:ruby_lib,true)
16
+ @commands.run
17
+ end
18
+ end
19
+
20
+
@@ -0,0 +1,38 @@
1
+
2
+ require 'spec_helper'
3
+
4
+ describe Plist4r::Config, "#default_backends" do
5
+ describe "when the supplied sym is :brew" do
6
+ it "should return the RubyCocoa backend" do
7
+ Plist4r::Config.default_backends(:brew).should == ["ruby_cocoa"]
8
+ end
9
+ end
10
+
11
+ describe "when the supplied sym is nil" do
12
+
13
+ describe "when there is no File at the path CoreFoundationFramework" do
14
+ it "should return DefaultBackendsAny" do
15
+ File.stub(:exists?).with(Plist4r::Config::CoreFoundationFramework).and_return(false)
16
+ Plist4r::Config.default_backends.should == Plist4r::Config::DefaultBackendsAny
17
+ end
18
+ end
19
+
20
+ describe "when there is a File at the path CoreFoundationFramework" do
21
+ describe "when there is a File at the path RubycocoaFramework" do
22
+ it "should return DefaultBackendsOsx + the RubyCocoa backend" do
23
+ File.stub(:exists?).with(Plist4r::Config::CoreFoundationFramework).and_return(true)
24
+ File.stub(:exists?).with(Plist4r::Config::RubycocoaFramework).and_return(true)
25
+ Plist4r::Config.default_backends.should == Plist4r::Config::DefaultBackendsOsx + ["ruby_cocoa"]
26
+ end
27
+ end
28
+ describe "when there is no File at the path RubycocoaFramework" do
29
+ it "should return DefaultBackendsOsx" do
30
+ File.stub(:exists?).with(Plist4r::Config::CoreFoundationFramework).and_return(true)
31
+ File.stub(:exists?).with(Plist4r::Config::RubycocoaFramework).and_return(false)
32
+ Plist4r::Config.default_backends.should == Plist4r::Config::DefaultBackendsOsx
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+
@@ -0,0 +1,120 @@
1
+
2
+ require 'spec_helper'
3
+
4
+ describe Plist4r::ArrayDict, "#initialize" do
5
+ before(:each) do
6
+ @orig = Plist4r::OrderedHash.new
7
+ @array_dict = Plist4r::ArrayDict.new @orig
8
+ end
9
+
10
+ it "should follow the default calling path when the supplied index is nil" do
11
+ orig = Plist4r::OrderedHash.new
12
+ @array_dict.instance_eval { initialize orig }
13
+ @array_dict.instance_eval { @orig }.should == @orig
14
+ @array_dict.instance_eval { @hash }.should be_a_kind_of(Plist4r::OrderedHash)
15
+ end
16
+
17
+ it "should follow the alternate calling path when the supplied index is not nil" do
18
+ orig = [nil,nil,@orig]
19
+ @array_dict.instance_eval { initialize orig, 2 }
20
+ @array_dict.instance_eval { @orig }.should == @orig
21
+ @array_dict.instance_eval { @hash }.should be_a_kind_of(Plist4r::OrderedHash)
22
+ end
23
+ end
24
+
25
+ describe Plist4r::ArrayDict, "#hash" do
26
+ before(:each) do
27
+ @orig = Plist4r::OrderedHash.new
28
+ @array_dict = Plist4r::ArrayDict.new @orig
29
+ end
30
+
31
+ it "should return @hash" do
32
+ @array_dict.instance_eval { @hash = "hash" }
33
+ @array_dict.hash.should == "hash"
34
+ end
35
+ end
36
+
37
+ describe Plist4r::ArrayDict, "#select" do
38
+ before(:each) do
39
+ @orig = Plist4r::OrderedHash.new
40
+ @array_dict = Plist4r::ArrayDict.new @orig
41
+ end
42
+
43
+ it "should follow the default calling path" do
44
+ @key1 = "key1"
45
+ @key1.stub(:class).and_return(Symbol)
46
+ @key1.stub(:to_s).and_return("key1")
47
+ @key1.stub(:camelcase).and_return("Key1")
48
+ @key2.stub(:class).and_return(Symbol)
49
+ @key2.stub(:to_s).and_return("key2")
50
+ @key2.stub(:camelcase).and_return("Key2")
51
+ @keys = [@key1, @key2]
52
+ @keys.stub(:flatten).and_return(@keys)
53
+
54
+ @array_dict.instance_eval { @orig = { "Key1" => "value1", "Key2" => "value2", "Key3" => "value3" } }
55
+
56
+ @array_dict.select(@keys)
57
+ @array_dict.instance_eval { @hash }.should have_key("Key1")
58
+ @array_dict.instance_eval { @hash }.should have_key("Key2")
59
+ @array_dict.instance_eval { @hash }.should_not have_key("Key3")
60
+ end
61
+ end
62
+
63
+ describe Plist4r::ArrayDict, "#unselect" do
64
+ before(:each) do
65
+ @orig = Plist4r::OrderedHash.new
66
+ @array_dict = Plist4r::ArrayDict.new @orig
67
+ end
68
+
69
+ it "should follow the default calling path" do
70
+ @key1 = "key1"
71
+ @key1.stub(:class).and_return(Symbol)
72
+ @key1.stub(:to_s).and_return("key1")
73
+ @key1.stub(:camelcase).and_return("Key1")
74
+ @key2.stub(:class).and_return(Symbol)
75
+ @key2.stub(:to_s).and_return("key2")
76
+ @key2.stub(:camelcase).and_return("Key2")
77
+ @keys = [@key1, @key2]
78
+ @keys.stub(:flatten).and_return(@keys)
79
+
80
+ @array_dict.instance_eval { @orig = { "Key1" => "value1", "Key2" => "value2", "Key3" => "value3" } }
81
+
82
+ @array_dict.unselect(@keys)
83
+ @array_dict.instance_eval { @hash }.should_not have_key("Key1")
84
+ @array_dict.instance_eval { @hash }.should_not have_key("Key2")
85
+ @array_dict.instance_eval { @hash }.should have_key("Key3")
86
+ end
87
+ end
88
+
89
+ describe Plist4r::ArrayDict, "#unselect_all" do
90
+ before(:each) do
91
+ @orig = Plist4r::OrderedHash.new
92
+ @array_dict = Plist4r::ArrayDict.new @orig
93
+ end
94
+
95
+ it "should clear all keys in @hash" do
96
+ @array_dict.instance_eval { @hash = { "Key1" => "value1", "Key2" => "value2", "Key3" => "value3" } }
97
+
98
+ @array_dict.unselect_all
99
+ @array_dict.instance_eval { @hash }.should be_a_kind_of(Plist4r::OrderedHash)
100
+
101
+ @array_dict.instance_eval { @hash }.should_not have_key("Key1")
102
+ @array_dict.instance_eval { @hash }.should_not have_key("Key2")
103
+ @array_dict.instance_eval { @hash }.should_not have_key("Key3")
104
+ end
105
+ end
106
+
107
+ describe Plist4r::ArrayDict, "#select_all" do
108
+ before(:each) do
109
+ @orig = Plist4r::OrderedHash.new
110
+ @array_dict = Plist4r::ArrayDict.new @orig
111
+ end
112
+
113
+ it "should set @hash to @orig" do
114
+ @array_dict.instance_eval { @orig = "orig" }
115
+ @array_dict.instance_eval { @hash = nil }
116
+ @array_dict.select_all
117
+ @array_dict.instance_eval { @hash }.should == "orig"
118
+ end
119
+ end
120
+