ygg 0.0.2 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,364 @@
1
+ require "spec_helper"
2
+
3
+ describe Ygg do
4
+
5
+ # Helpers, helpers, helpers
6
+ def warrant_me_that_does_not_exist(full_path)
7
+ File.should_not exist(full_path)
8
+ end
9
+ def unavailable_resource_raises_with(*args)
10
+ expect { Ygg.ygg *args
11
+ }.to raise_error(
12
+ Ygg::UnavailableResourceException,
13
+ "No resource was found in #{non_existent_full_path}" )
14
+ end
15
+ def no_interaction_done
16
+ Ygg.reset
17
+ expect { Ygg.events.should be_empty
18
+ }.to raise_error(
19
+ Ygg::NoInteractionDoneException,
20
+ "No events to load in the log." )
21
+ end
22
+ def do_demo_interaction(*args)
23
+ if args.empty?
24
+ return Ygg.ygg full_base_path, valid_file_identifier
25
+ else
26
+ return Ygg.ygg *args
27
+ end
28
+ end
29
+ def demo_user
30
+ user = YggDemo::User.new
31
+ user.name = "Jane Eyre"
32
+ user
33
+ end
34
+ def do_interaction_with_block(*args)
35
+ args << full_base_path << valid_file_identifier if args.empty?
36
+ Ygg.ygg(*args) do
37
+ Ygg.add demo_user
38
+ end
39
+ end
40
+ def is_valid_resource?(path)
41
+ File.should exist(path)
42
+ content = File.read(path)
43
+ content.should include("- !ruby/object:")
44
+ end
45
+ def reset_valid_file
46
+ File.open valid_full_path, "w" do |file|
47
+ file.write [demo_user].to_yaml
48
+ end
49
+ end
50
+
51
+ describe ".base_dir" do
52
+ context "no interaction done" do
53
+ it "should be empty" do
54
+ no_interaction_done
55
+ Ygg.base_dir.should == "."
56
+ end
57
+ end
58
+
59
+ context "base dir setted" do
60
+ it "should return a valid path" do
61
+ do_demo_interaction
62
+ Dir.should exist(Ygg.base_dir)
63
+ end
64
+ end
65
+ end
66
+
67
+ describe ".ygg" do
68
+ before :each do
69
+ Ygg.base_dir = "."
70
+ is_valid_resource? valid_full_path
71
+ end
72
+
73
+ after :each do
74
+ File.unlink to_create_full_path if File.exists? to_create_full_path
75
+ end
76
+
77
+ context "called with no arguments" do
78
+ it "should return the Ygg module constant" do
79
+ Ygg.ygg.should be(Ygg)
80
+ end
81
+ end
82
+
83
+ context "called with a symbol argument" do
84
+ before :each do
85
+ Ygg.base_dir = full_base_path
86
+ end
87
+
88
+ it "should fail if no resource available" do
89
+ warrant_me_that_does_not_exist non_existent_full_path
90
+ unavailable_resource_raises_with non_existent_file_identifier
91
+ end
92
+
93
+ it "should return a bundle of data" do
94
+ data_bundle = do_demo_interaction valid_file_identifier
95
+ data_bundle.should_not be_empty
96
+ end
97
+ end
98
+
99
+ context "called with a path argument" do
100
+ it "should fail if no resource available" do
101
+ warrant_me_that_does_not_exist non_existent_full_path
102
+ unavailable_resource_raises_with non_existent_full_path
103
+ end
104
+
105
+ it "should return a bundle of data" do
106
+ data_bundle = do_demo_interaction valid_full_path
107
+ data_bundle.should_not be_empty
108
+ end
109
+ end
110
+
111
+ context "called with two arguments" do
112
+ it "should fail if no resource available" do
113
+ warrant_me_that_does_not_exist non_existent_full_path
114
+ unavailable_resource_raises_with full_base_path, non_existent_file_identifier
115
+ end
116
+
117
+ it "should setup the base directory" do
118
+ do_demo_interaction
119
+ Ygg.base_dir.should == full_base_path
120
+ end
121
+
122
+ it "should return a bundle of data" do
123
+ data_bundle = do_demo_interaction full_base_path, valid_file_identifier
124
+ data_bundle.should_not be_empty
125
+ end
126
+ end
127
+
128
+ context "called with an argument and a block" do
129
+ context "inexistent resource" do
130
+ it "should be created" do
131
+ warrant_me_that_does_not_exist to_create_full_path
132
+ do_interaction_with_block to_create_full_path
133
+ is_valid_resource? to_create_full_path
134
+ end
135
+ end
136
+
137
+ context "existent resource" do
138
+ it "should have its modification date changed" do
139
+ is_valid_resource? to_modify_full_path
140
+ original_mtime = File.mtime to_modify_full_path
141
+ do_interaction_with_block to_modify_full_path
142
+ original_mtime.should_not == File.mtime(to_modify_full_path)
143
+ end
144
+ end
145
+ end
146
+
147
+ context "called with two arguments and a block" do
148
+ context "inexistent resource" do
149
+ it "should be created" do
150
+ warrant_me_that_does_not_exist to_create_full_path
151
+ do_interaction_with_block full_base_path, to_create_file_identifier
152
+ is_valid_resource? to_create_full_path
153
+ end
154
+ end
155
+
156
+ context "existent resource" do
157
+ it "should have its modification date changed" do
158
+ is_valid_resource? to_modify_2_full_path
159
+ original_mtime = File.mtime to_modify_2_full_path
160
+ do_interaction_with_block full_base_path, to_modify_2_file_identifier
161
+ original_mtime.should_not == File.mtime(to_modify_2_full_path)
162
+ end
163
+ end
164
+ end
165
+ end
166
+
167
+ describe ".add" do
168
+ it "should fail when no argument is passed" do
169
+ expect { Ygg.add }.to raise_error( ArgumentError )
170
+ end
171
+
172
+ context "no previous activity" do
173
+ it "should fail for no resource was found" do
174
+ no_interaction_done
175
+ expect { Ygg.add demo_user
176
+ }.to raise_error(
177
+ Ygg::UnavailableResourceException,
178
+ "No resource was loaded, impossible to add the object" )
179
+ end
180
+ end
181
+
182
+ context "block session" do
183
+ it "should initialize records" do
184
+ Ygg.reset
185
+ do_interaction_with_block
186
+ Ygg.records.should_not be_empty
187
+ end
188
+
189
+ it "should increment the resource size by 1" do
190
+ expect { do_interaction_with_block
191
+ }.to change { Ygg.records.length }.by(1)
192
+ end
193
+
194
+ it "should be the same the element passed and the last" do
195
+ user = YggDemo::User.new
196
+ user.name = "Ximena Krius"
197
+ Ygg.ygg valid_full_path do
198
+ Ygg.add user
199
+ Ygg.records.last.should be(user)
200
+ end
201
+ end
202
+
203
+ it "should be present on the saved file" do
204
+ user = YggDemo::User.new
205
+ user.name = "Xandria Ymanus"
206
+ Ygg.ygg valid_full_path do
207
+ Ygg.add user
208
+ end
209
+ File.read(valid_full_path).should include(user.to_yaml[6,15])
210
+ end
211
+ end
212
+
213
+ context "closed session" do
214
+ it "should increment the last resource size by 1" do
215
+ no_interaction_done
216
+ do_demo_interaction
217
+ user = YggDemo::User.new
218
+ user.name = "Yvonna Malygas"
219
+ expect { Ygg.add user
220
+ }.to change { Ygg.records.length }.by(1)
221
+ end
222
+
223
+ it "should be the same the element passed and the last" do
224
+ do_demo_interaction
225
+ user = demo_user
226
+ Ygg.add user
227
+ Ygg.records.last.should be(user)
228
+ end
229
+
230
+ it "should not be present on the resource file" do
231
+ do_demo_interaction
232
+ user = YggDemo::User.new
233
+ user.name = "Nemo Anonymous"
234
+ Ygg.add user
235
+ File.read(valid_full_path)
236
+ .should_not include(user.to_yaml[6,35])
237
+ end
238
+ end
239
+ end
240
+
241
+ describe ".save" do
242
+ it "should fail if no resource is available"
243
+
244
+ it "should create the resource if doesn't exist"
245
+
246
+ it "should be written in the file the last inserted data"
247
+ end
248
+
249
+ describe ".records" do
250
+ context "no previous activity" do
251
+ it "should fail for no resource was found" do
252
+ no_interaction_done
253
+ expect { Ygg.records
254
+ }.to raise_error(
255
+ Ygg::NoInteractionDoneException,
256
+ "No events to load in the log." )
257
+ end
258
+ end
259
+
260
+ context "transaction done and closed" do
261
+ it "should return some data" do
262
+ do_interaction_with_block
263
+ Ygg.records.should_not be_empty
264
+ end
265
+ end
266
+ end
267
+
268
+ describe ".path_to" do
269
+ it "should fail when no argument is passed" do
270
+ expect { Ygg.path_to
271
+ }.to raise_error( ArgumentError )
272
+ end
273
+
274
+ context "symbol argument" do
275
+ it "should return combination of base_dir and the argument" do
276
+ no_interaction_done
277
+ Ygg.base_dir = full_base_path
278
+ Ygg.path_to(:resource).should == "#{full_base_path}/resource.ygg"
279
+ end
280
+ end
281
+
282
+ context "string argument" do
283
+ it "should return the same string" do
284
+ Ygg.path_to("some/path").should == "some/path"
285
+ end
286
+ end
287
+ end
288
+
289
+ describe ".resource" do
290
+ context "out of block" do
291
+ def fail_resource_fail!
292
+ expect { Ygg.resource
293
+ }.to raise_error(
294
+ Ygg::OutOfBlockException,
295
+ "The resource is not available outside an ygg block." )
296
+ end
297
+
298
+ it "should fail when no session is opened" do
299
+ fail_resource_fail!
300
+ end
301
+
302
+ it "should fail after a block was used" do
303
+ do_interaction_with_block
304
+ fail_resource_fail!
305
+ end
306
+ end
307
+
308
+ context "no arguments passed" do
309
+ it "should return the current session" do
310
+ Ygg.ygg valid_full_path do
311
+ Ygg.resource.should be( Ygg.events.last )
312
+ end
313
+ end
314
+ end
315
+
316
+ context ":path required" do
317
+ it "should return the current resource path" do
318
+ Ygg.ygg valid_full_path do
319
+ Ygg.resource(:path).should == valid_full_path
320
+ end
321
+ end
322
+ end
323
+ end
324
+
325
+ describe ".events" do
326
+ context "ygg has done nothing yet" do
327
+ it "should fail" do
328
+ no_interaction_done
329
+ expect { Ygg.events
330
+ }.to raise_error(
331
+ Ygg::NoInteractionDoneException,
332
+ "No events to load in the log.")
333
+ end
334
+ end
335
+
336
+ context "ygg had one interaction" do
337
+ it "should return an array with at least one session" do
338
+ do_demo_interaction
339
+ Ygg.events.first.should be_a(Ygg::Session)
340
+ end
341
+ end
342
+ end
343
+
344
+ describe ".reset" do
345
+ before :each do
346
+ Ygg.reset
347
+ end
348
+
349
+ it "should set base_dir as '.'" do
350
+ Ygg.base_dir.should == "."
351
+ end
352
+
353
+ it "should make events empty" do
354
+ expect { Ygg.events
355
+ }.to raise_error(
356
+ Ygg::NoInteractionDoneException,
357
+ "No events to load in the log.")
358
+ end
359
+ end
360
+
361
+ after :all do
362
+ reset_valid_file
363
+ end
364
+ end
@@ -12,6 +12,11 @@ Gem::Specification.new do |s|
12
12
  s.summary = %q{Pure Ruby persistence solution}
13
13
  s.description = %q{Pure Ruby persistence solution}
14
14
 
15
+ s.add_dependency "metafun"
16
+
17
+ s.add_development_dependency "rspec"
18
+ s.add_development_dependency "cucumber"
19
+
15
20
  s.rubyforge_project = "ygg"
16
21
 
17
22
  s.files = `git ls-files`.split("\n")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ygg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 1.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,9 +9,42 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-06-03 00:00:00.000000000 -03:00
12
+ date: 2011-09-04 00:00:00.000000000 -03:00
13
13
  default_executable:
14
- dependencies: []
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: metafun
17
+ requirement: &21890304 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *21890304
26
+ - !ruby/object:Gem::Dependency
27
+ name: rspec
28
+ requirement: &22215888 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: *22215888
37
+ - !ruby/object:Gem::Dependency
38
+ name: cucumber
39
+ requirement: &22441776 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *22441776
15
48
  description: Pure Ruby persistence solution
16
49
  email:
17
50
  - xavierviacanel@gmail.com
@@ -23,9 +56,39 @@ files:
23
56
  - Gemfile
24
57
  - README.rdoc
25
58
  - Rakefile
59
+ - emulations/samples/event.ygg
60
+ - emulations/samples/invalid_resource.ygg
61
+ - emulations/samples/to_modify.ygg
62
+ - emulations/samples/to_modify_2.ygg
63
+ - emulations/samples/user.ygg
64
+ - emulations/samples/valid.ygg
65
+ - emulations/save_yaml_object.rb
66
+ - emulations/tree.ygg
67
+ - features/accessors.feature
68
+ - features/dsl.feature
69
+ - features/events.feature
70
+ - features/simple_record.feature
71
+ - features/steps/accessors.rb
72
+ - features/steps/dsl.rb
73
+ - features/steps/events.rb
74
+ - features/steps/simple_record.rb
75
+ - features/support/env.rb
76
+ - features/support/hooks.rb
26
77
  - lib/ygg.rb
27
- - lib/ygg/base.rb
78
+ - lib/ygg/bck/base.rb
79
+ - lib/ygg/bck/branch.rb
80
+ - lib/ygg/bck/exceptions.rb
81
+ - lib/ygg/bck/link.rb
82
+ - lib/ygg/bck/model.rb
83
+ - lib/ygg/databundle.rb
84
+ - lib/ygg/exceptions.rb
85
+ - lib/ygg/record.rb
86
+ - lib/ygg/session.rb
28
87
  - lib/ygg/version.rb
88
+ - spec/spec_helper.rb
89
+ - spec/ygg/databundle_spec.rb
90
+ - spec/ygg/session_spec.rb
91
+ - spec/ygg/ygg_spec.rb
29
92
  - ygg.gemspec
30
93
  has_rdoc: true
31
94
  homepage: ''