batsir 0.1.0 → 0.3.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. data/.travis.yml +9 -1
  2. data/CHANGES.md +54 -0
  3. data/Gemfile +7 -10
  4. data/README.md +49 -5
  5. data/Rakefile +23 -16
  6. data/batsir.gemspec +43 -15
  7. data/lib/batsir/acceptors/acceptor.rb +31 -5
  8. data/lib/batsir/acceptors/amqp_acceptor.rb +36 -8
  9. data/lib/batsir/amqp.rb +35 -7
  10. data/lib/batsir/amqp_consumer.rb +8 -0
  11. data/lib/batsir/compiler/stage_worker_compiler.rb +86 -0
  12. data/lib/batsir/config.rb +208 -24
  13. data/lib/batsir/dsl/conditional_notifier_declaration.rb +31 -0
  14. data/lib/batsir/dsl/dsl_mappings.rb +27 -2
  15. data/lib/batsir/errors.rb +18 -0
  16. data/lib/batsir/filter.rb +5 -0
  17. data/lib/batsir/log.rb +7 -0
  18. data/lib/batsir/logger.rb +37 -0
  19. data/lib/batsir/logo.rb +3 -8
  20. data/lib/batsir/notifiers/amqp_notifier.rb +14 -4
  21. data/lib/batsir/notifiers/conditional_notifier.rb +29 -0
  22. data/lib/batsir/notifiers/notifier.rb +6 -5
  23. data/lib/batsir/registry.rb +6 -2
  24. data/lib/batsir/stage.rb +9 -4
  25. data/lib/batsir/stage_worker.rb +3 -56
  26. data/lib/batsir/strategies/retry_strategy.rb +35 -0
  27. data/lib/batsir/strategies/strategy.rb +20 -0
  28. data/lib/batsir/transformers/field_transformer.rb +2 -3
  29. data/lib/batsir/transformers/json_input_transformer.rb +6 -2
  30. data/lib/batsir/transformers/json_output_transformer.rb +6 -2
  31. data/lib/batsir/transformers/transformer.rb +5 -1
  32. data/lib/batsir/version.rb +10 -0
  33. data/lib/batsir.rb +31 -13
  34. data/spec/batsir/acceptors/acceptor_spec.rb +7 -78
  35. data/spec/batsir/acceptors/amqp_acceptor_spec.rb +55 -66
  36. data/spec/batsir/acceptors/shared_examples.rb +102 -0
  37. data/spec/batsir/amqp_spec.rb +58 -0
  38. data/spec/batsir/chain_spec.rb +4 -4
  39. data/spec/batsir/config_spec.rb +97 -0
  40. data/spec/batsir/dsl/chain_mapping_spec.rb +5 -6
  41. data/spec/batsir/dsl/conditional_notifier_mapping_spec.rb +80 -0
  42. data/spec/batsir/dsl/stage_mapping_spec.rb +38 -20
  43. data/spec/batsir/filter_queue_spec.rb +9 -15
  44. data/spec/batsir/filter_spec.rb +4 -5
  45. data/spec/batsir/log_spec.rb +10 -0
  46. data/spec/batsir/logger_spec.rb +46 -0
  47. data/spec/batsir/notifiers/amqp_notifier_spec.rb +43 -22
  48. data/spec/batsir/notifiers/conditional_notifier_spec.rb +62 -0
  49. data/spec/batsir/notifiers/notifier_spec.rb +4 -66
  50. data/spec/batsir/notifiers/shared_examples.rb +100 -0
  51. data/spec/batsir/registry_spec.rb +48 -0
  52. data/spec/batsir/stage_spec.rb +91 -85
  53. data/spec/batsir/stage_worker_spec.rb +13 -13
  54. data/spec/batsir/strategies/retry_strategy_spec.rb +58 -0
  55. data/spec/batsir/strategies/strategy_spec.rb +28 -0
  56. data/spec/batsir/support/bunny_mocks.rb +78 -5
  57. data/spec/batsir/transformers/field_transformer_spec.rb +22 -22
  58. data/spec/batsir/transformers/json_input_transformer_spec.rb +8 -3
  59. data/spec/batsir/transformers/json_output_transformer_spec.rb +2 -2
  60. data/spec/batsir/transformers/transformer_spec.rb +18 -4
  61. data/spec/spec_helper.rb +6 -2
  62. metadata +78 -23
  63. data/VERSION +0 -1
@@ -1,24 +1,24 @@
1
1
  require File.join( File.dirname(__FILE__), "..", "spec_helper" )
2
2
 
3
3
  describe Batsir::Chain do
4
- it "should have a list of stages" do
4
+ it "has a list of stages" do
5
5
  chain = Batsir::Chain.new
6
6
  chain.stages.should_not be_nil
7
7
  end
8
8
 
9
- it "should initially have an empty list of stages" do
9
+ it "initially has an empty list of stages" do
10
10
  chain = Batsir::Chain.new
11
11
  chain.stages.should be_empty
12
12
  end
13
13
 
14
- it "should be possible to add a stage" do
14
+ it "can add a stage" do
15
15
  chain = Batsir::Chain.new
16
16
  stage = Batsir::Stage.new(:name => "Stage")
17
17
  chain.add_stage(stage)
18
18
  chain.stages.should include stage
19
19
  end
20
20
 
21
- it "should be possible to compile a chain" do
21
+ it "can compile a chain" do
22
22
  chain = Batsir::Chain.new
23
23
  stage = Batsir::Stage.new(:name => "Stage")
24
24
  chain.add_stage(stage)
@@ -0,0 +1,97 @@
1
+ require File.join( File.dirname(__FILE__), "..", "spec_helper" )
2
+
3
+ describe Batsir::Config do
4
+ context "with respect to retrieving variables" do
5
+ it "can check if a key exists" do
6
+ Batsir::Config.key?(:sidekiq_queue).should be_true
7
+ Batsir::Config.key?(:non_existent).should be_false
8
+ end
9
+
10
+ it "can use brackets" do
11
+ Batsir::Config[:sidekiq_queue].should == 'batsir'
12
+ end
13
+
14
+ it "can use fetch method" do
15
+ Batsir::Config.fetch(:sidekiq_queue, nil).should == 'batsir'
16
+ end
17
+
18
+ it "returns the default value when variable does not exist" do
19
+ Batsir::Config.fetch(:dbase, 'default').should == 'default'
20
+ end
21
+
22
+ it "can use a method with the variable's name" do
23
+ Batsir::Config.sidekiq_queue.should == 'batsir'
24
+ end
25
+
26
+ it "can use return the settings in a hash" do
27
+ Batsir::Config[:dbase] = :test
28
+ hash = Batsir::Config.to_hash
29
+ hash.keys.include?(:sidekiq_queue).should be_true
30
+ hash.keys.include?(:dbase).should be_true
31
+ hash.values.include?(:test).should be_true
32
+ hash.values.include?('batsir').should be_true
33
+ end
34
+ end
35
+
36
+ context "with respect to setting variables" do
37
+ it "can set a variable using brackets" do
38
+ Batsir::Config[:testtest] = "testtest"
39
+ Batsir::Config.testtest.should == "testtest"
40
+ end
41
+
42
+ it "can set a variable using a method with the variable's name" do
43
+ Batsir::Config.testtest = "test1"
44
+ Batsir::Config[:testtest].should == "test1"
45
+ end
46
+
47
+ context "setting multiple variables at once" do
48
+ it "can use setup method" do
49
+ Batsir::Config.setup({:test_var => "test1", :test_var2 => "test2"})
50
+ Batsir::Config.test_var.should == "test1"
51
+ Batsir::Config.test_var2.should == "test2"
52
+ end
53
+
54
+ it "merges given settings with default settings when using setup method" do
55
+ Batsir::Config.setup({:test_var => "test1", :test_var2 => "test2"})
56
+ Batsir::Config.sidekiq_queue.should == 'batsir'
57
+ end
58
+
59
+ context "with block notation" do
60
+ it "uses yielding" do
61
+ Batsir::Config.use do |config|
62
+ config[:tester1] = "test1"
63
+ config[:tester2] = "test2"
64
+ end
65
+ Batsir::Config.sidekiq_queue.should == 'batsir'
66
+ Batsir::Config.tester1.should == "test1"
67
+ Batsir::Config.tester2.should == "test2"
68
+ end
69
+
70
+ it "uses a block" do
71
+ Batsir::Config.configure do
72
+ tester3 "test3"
73
+ tester4 "test4"
74
+ end
75
+ Batsir::Config.sidekiq_queue.should == 'batsir'
76
+ Batsir::Config.tester3.should == "test3"
77
+ Batsir::Config.tester4.should == "test4"
78
+ end
79
+ end
80
+ end
81
+ end
82
+
83
+ context "with respect to deleting variables" do
84
+ it "deletes the given key" do
85
+ Batsir::Config.sidekiq_queue.should_not be_nil
86
+ Batsir::Config.delete(:sidekiq_queue)
87
+ Batsir::Config.sidekiq_queue.should be_nil
88
+ end
89
+ end
90
+ end
91
+
92
+ describe Batsir::Config, "with respect to resetting the configuration" do
93
+ it "resets properly" do
94
+ Batsir::Config.reset
95
+ Batsir::Config.to_hash.should == Batsir::Config.defaults
96
+ end
97
+ end
@@ -1,7 +1,7 @@
1
1
  require File.join( File.dirname(__FILE__), "..", "..", "spec_helper")
2
2
 
3
3
  describe Batsir::DSL::ChainMapping do
4
- it "should create a chain" do
4
+ it "creates a chain" do
5
5
  block = ::Proc.new do
6
6
  aggregator_chain do
7
7
  end
@@ -11,7 +11,7 @@ describe Batsir::DSL::ChainMapping do
11
11
  chain.should_not be_nil
12
12
  end
13
13
 
14
- it "should be possible to add a stage" do
14
+ it "can add a stage" do
15
15
  block = ::Proc.new do
16
16
  aggregator_chain do
17
17
  stage "simple_stage" do
@@ -26,7 +26,7 @@ describe Batsir::DSL::ChainMapping do
26
26
  chain.stages.first.name.should == "simple_stage"
27
27
  end
28
28
 
29
- it "should set the chain of the stage to the current chain" do
29
+ it "sets the chain of the stage to the current chain" do
30
30
  block = ::Proc.new do
31
31
  aggregator_chain do
32
32
  stage "simple_stage" do
@@ -40,7 +40,7 @@ describe Batsir::DSL::ChainMapping do
40
40
  chain.stages.first.chain.should == chain
41
41
  end
42
42
 
43
- it "should be possible to add multiple stages" do
43
+ it "can add multiple stages" do
44
44
  block = ::Proc.new do
45
45
  aggregator_chain do
46
46
  stage "first_stage" do
@@ -59,7 +59,7 @@ describe Batsir::DSL::ChainMapping do
59
59
  chain.stages.last.name.should == "second_stage"
60
60
  end
61
61
 
62
- it "should be possible to create a complete aggregator chain" do
62
+ it "can create a complete aggregator chain" do
63
63
  stage_name = "Complete Stage"
64
64
  operation1 = "Some Operation"
65
65
  operation2 = "Another Operation"
@@ -113,5 +113,4 @@ describe Batsir::DSL::ChainMapping do
113
113
  stage.notifiers[notification_class2].first.should == {}
114
114
  end
115
115
  end
116
-
117
116
  end
@@ -0,0 +1,80 @@
1
+ require File.join( File.dirname(__FILE__), "..", "..", "spec_helper")
2
+
3
+ describe Batsir::DSL::ConditionalNotifierMapping do
4
+ it "creates conditional notifier declarations" do
5
+ block = lambda do
6
+ conditional do
7
+ notify_if "message == 'sometext'", Batsir::Notifiers::Notifier
8
+ end
9
+ end
10
+
11
+ conditional = ::Blockenspiel.invoke(block, Batsir::DSL::ConditionalNotifierMapping.new)
12
+ conditional.notifier_declarations.should_not be_empty
13
+ conditional_notifier = conditional.notifier_declarations.first
14
+ conditional_notifier.notifier.should == Batsir::Notifiers::Notifier
15
+ end
16
+
17
+ it "passes options to notifiers" do
18
+ block = lambda do
19
+ conditional do
20
+ notify_if "true", Batsir::Notifiers::Notifier, :some => :options
21
+ end
22
+ end
23
+
24
+ conditional = ::Blockenspiel.invoke(block, Batsir::DSL::ConditionalNotifierMapping.new)
25
+ conditional.notifier_declarations.should_not be_empty
26
+ conditional_notifier = conditional.notifier_declarations.first
27
+ conditional_notifier.options.should have_key :some
28
+ end
29
+
30
+ it "can be used inside a stage" do
31
+ block = lambda do
32
+ stage "stage name" do
33
+ outbound do
34
+ conditional do
35
+ notify_if "true", Batsir::Notifiers::Notifier, :some => :options
36
+ end
37
+ end
38
+ end
39
+ end
40
+
41
+ stage = ::Blockenspiel.invoke(block, Batsir::DSL::StageMapping.new)
42
+ notifier = stage.conditional_notifiers.should_not be_empty
43
+ end
44
+
45
+ context "compiling" do
46
+ before :all do
47
+ Celluloid.boot
48
+
49
+ block = lambda do
50
+ stage "stage name" do
51
+ outbound do
52
+ conditional do
53
+ notify_if "true", Batsir::Notifiers::Notifier
54
+ notify_if "false", Batsir::Notifiers::Notifier
55
+ end
56
+ end
57
+ end
58
+ end
59
+
60
+ stage = ::Blockenspiel.invoke(block, Batsir::DSL::StageMapping.new)
61
+ created_class = eval( stage.compile )
62
+ @instance = created_class.new
63
+ end
64
+
65
+ it "stores the conditional notifier" do
66
+ @instance.filter_queue.notifiers.size == 1
67
+ conditional = @instance.filter_queue.notifiers.first
68
+ conditional.should be_kind_of Batsir::Notifiers::ConditionalNotifier
69
+ conditional.notifiers.size.should == 2
70
+ conditional.notifiers.first.condition.should be_a Proc
71
+ end
72
+
73
+ it "adds the default transformer" do
74
+ notifier = @instance.filter_queue.notifiers.first
75
+ notifier.transformer_queue.size.should == 1
76
+ notifier.transformer_queue.first.should be_kind_of Batsir::Transformers::Transformer
77
+ end
78
+ end
79
+ end
80
+
@@ -1,7 +1,7 @@
1
1
  require File.join( File.dirname(__FILE__), "..", "..", "spec_helper")
2
2
 
3
3
  describe Batsir::DSL::StageMapping do
4
- it "should create a simple stage with a name" do
4
+ it "creates a simple stage with a name" do
5
5
  block = ::Proc.new do
6
6
  stage "simple_stage" do
7
7
  end
@@ -12,7 +12,7 @@ describe Batsir::DSL::StageMapping do
12
12
  stage.name.should == "simple_stage"
13
13
  end
14
14
 
15
- it "should be possible to add an filter to the stage" do
15
+ it "can add a filter to the stage" do
16
16
  filter = "Operation"
17
17
 
18
18
  block = ::Proc.new do
@@ -28,7 +28,25 @@ describe Batsir::DSL::StageMapping do
28
28
  stage.filters.should include filter
29
29
  end
30
30
 
31
- it "should be possible to add multiple filters to the stage" do
31
+ it "can add a filter with options to the stage" do
32
+ filter = "Operation"
33
+ options = { :option => "options" }
34
+
35
+ block = ::Proc.new do
36
+ stage "simple_stage" do
37
+ filter filter, options
38
+ end
39
+ end
40
+
41
+ stage = ::Blockenspiel.invoke(block, Batsir::DSL::StageMapping.new)
42
+ stage.should_not be_nil
43
+ stage.filters.should_not be_nil
44
+ stage.filters.should_not be_empty
45
+ declaration = stage.filter_declarations.find{|decl| decl.filter == filter }
46
+ declaration.options.should == options
47
+ end
48
+
49
+ it "can add multiple filters to the stage" do
32
50
  filter1 = "Operation 1"
33
51
  filter2 = "Operation 2"
34
52
 
@@ -47,7 +65,7 @@ describe Batsir::DSL::StageMapping do
47
65
  stage.filters.should include filter2
48
66
  end
49
67
 
50
- it "should be possible to add an inbound section to a stage" do
68
+ it "can add an inbound section to a stage" do
51
69
  block = ::Proc.new do
52
70
  stage "simple_stage" do
53
71
  inbound do
@@ -62,7 +80,7 @@ describe Batsir::DSL::StageMapping do
62
80
  stage.acceptors.should be_empty
63
81
  end
64
82
 
65
- it "should be possible to add a transformers section to the inbound section of a stage" do
83
+ it "can add a transformers section to the inbound section of a stage" do
66
84
  block = ::Proc.new do
67
85
  stage "simple_stage" do
68
86
  inbound do
@@ -80,7 +98,7 @@ describe Batsir::DSL::StageMapping do
80
98
  stage.acceptor_transformers.should be_empty
81
99
  end
82
100
 
83
- it "should be possible to add a transformer to the transformers section of the inbound section of a stage" do
101
+ it "can add a transformer to the transformers section of the inbound section of a stage" do
84
102
  transformer = :transformer
85
103
 
86
104
  block = ::Proc.new do
@@ -102,7 +120,7 @@ describe Batsir::DSL::StageMapping do
102
120
  stage.acceptor_transformers.first.transformer.should == transformer
103
121
  end
104
122
 
105
- it "should be possible to add a transformer with options to the transformers section of the inbound section of a stage" do
123
+ it "can add a transformer with options to the transformers section of the inbound section of a stage" do
106
124
  transformer = :transformer
107
125
  options = {:foo => :bar}
108
126
 
@@ -126,7 +144,7 @@ describe Batsir::DSL::StageMapping do
126
144
  stage.acceptor_transformers.first.options.should == options
127
145
  end
128
146
 
129
- it "should be possible to add multiple transformers to the transformers section of the inbound section of a stage" do
147
+ it "can add multiple transformers to the transformers section of the inbound section of a stage" do
130
148
  transformer1 = :transformer1
131
149
  options = {:foo => :bar}
132
150
  transformer2 = :transformer2
@@ -154,7 +172,7 @@ describe Batsir::DSL::StageMapping do
154
172
  stage.acceptor_transformers.last.options.should == {}
155
173
  end
156
174
 
157
- it "should be possible to add an acceptor to a stage" do
175
+ it "can add an acceptor to a stage" do
158
176
  acceptor_class = :acceptor_class
159
177
 
160
178
  block = ::Proc.new do
@@ -173,7 +191,7 @@ describe Batsir::DSL::StageMapping do
173
191
  stage.acceptors[acceptor_class].first.should == {}
174
192
  end
175
193
 
176
- it "should be possible to add an inbound section with an acceptor with options to the stage" do
194
+ it "can add an inbound section with an acceptor with options to the stage" do
177
195
  acceptor_class = :acceptor_class
178
196
  options = {:foo => :bar}
179
197
 
@@ -193,7 +211,7 @@ describe Batsir::DSL::StageMapping do
193
211
  stage.acceptors[acceptor_class].first.should == options
194
212
  end
195
213
 
196
- it "should be possible to add multiple acceptors to a stage" do
214
+ it "can add multiple acceptors to a stage" do
197
215
  acceptor_class1 = :acceptor_class1
198
216
  options = {:foo => :bar}
199
217
  acceptor_class2 = :acceptor_class2
@@ -217,7 +235,7 @@ describe Batsir::DSL::StageMapping do
217
235
  stage.acceptors[acceptor_class2].first.should == {}
218
236
  end
219
237
 
220
- it "should be possible to add an outbound section without any notifiers" do
238
+ it "can add an outbound section without any notifiers" do
221
239
  block = ::Proc.new do
222
240
  stage "simple_stage" do
223
241
  outbound do
@@ -232,7 +250,7 @@ describe Batsir::DSL::StageMapping do
232
250
  stage.notifiers.should be_empty
233
251
  end
234
252
 
235
- it "should be possible to add a transformers section to the outbound section of a stage" do
253
+ it "can add a transformers section to the outbound section of a stage" do
236
254
  block = ::Proc.new do
237
255
  stage "simple_stage" do
238
256
  outbound do
@@ -250,7 +268,7 @@ describe Batsir::DSL::StageMapping do
250
268
  stage.notifier_transformers.should be_empty
251
269
  end
252
270
 
253
- it "should be possible to add a transformer to the transformers section of the outbound section of a stage" do
271
+ it "can add a transformer to the transformers section of the outbound section of a stage" do
254
272
  transformer = :transformer
255
273
 
256
274
  block = ::Proc.new do
@@ -272,7 +290,7 @@ describe Batsir::DSL::StageMapping do
272
290
  stage.notifier_transformers.first.transformer.should == transformer
273
291
  end
274
292
 
275
- it "should be possible to add a transformer with options to the transformers section of the outbound section of a stage" do
293
+ it "can add a transformer with options to the transformers section of the outbound section of a stage" do
276
294
  transformer = :transformer
277
295
  options = {:foo => :bar}
278
296
 
@@ -296,7 +314,7 @@ describe Batsir::DSL::StageMapping do
296
314
  stage.notifier_transformers.first.options.should == options
297
315
  end
298
316
 
299
- it "should be possible to add multiple transformers to the transformers section of the outbound section of a stage" do
317
+ it "can add multiple transformers to the transformers section of the outbound section of a stage" do
300
318
  transformer1 = :transformer1
301
319
  options = {:foo => :bar}
302
320
  transformer2 = :transformer2
@@ -324,7 +342,7 @@ describe Batsir::DSL::StageMapping do
324
342
  stage.notifier_transformers.last.options.should == {}
325
343
  end
326
344
 
327
- it "should be possible to add an outbound section to the stage" do
345
+ it "can add an outbound section to the stage" do
328
346
  notification_class = :notification_class
329
347
 
330
348
  block = ::Proc.new do
@@ -342,7 +360,7 @@ describe Batsir::DSL::StageMapping do
342
360
  stage.notifiers[notification_class].first.should == {}
343
361
  end
344
362
 
345
- it "should be possible to add an outbound section with a notifier with options to the stage" do
363
+ it "can add an outbound section with a notifier with options to the stage" do
346
364
  notification_class = :notification_class
347
365
  options = {:queue => :somequeue}
348
366
 
@@ -361,7 +379,7 @@ describe Batsir::DSL::StageMapping do
361
379
  stage.notifiers[notification_class].first.should == options
362
380
  end
363
381
 
364
- it "should be possible to add multiple notifiers to the stage" do
382
+ it "can add multiple notifiers to the stage" do
365
383
  notification_class1 = :notification_class1
366
384
  options = {:queue => :somequeue}
367
385
  notification_class2 = :notification_class2
@@ -385,7 +403,7 @@ describe Batsir::DSL::StageMapping do
385
403
  stage.notifiers[notification_class2].first.should == {}
386
404
  end
387
405
 
388
- it "should be possible to create a complete stage" do
406
+ it "can create a complete stage" do
389
407
  acceptor_class1 = :acceptor_class1
390
408
  options = {:foo => :bar}
391
409
  acceptor_class2 = :acceptor_class2
@@ -1,15 +1,14 @@
1
1
  require File.join( File.dirname(__FILE__), "..", "spec_helper" )
2
2
 
3
3
  describe Batsir::FilterQueue do
4
- it "should be possible to add a filter to a queue" do
4
+ it "can add a filter to a queue" do
5
5
  queue = Batsir::FilterQueue.new
6
6
  queue.add("Filter")
7
7
  queue.should include "Filter"
8
8
  end
9
9
 
10
- it "should not return nil as last operation when no acceptors or notifiers are added" do
10
+ it "does not return nil as last operation when no acceptors or notifiers are added" do
11
11
  queue = Batsir::FilterQueue.new
12
-
13
12
  queue.add("AnotherFilter")
14
13
  ops = []
15
14
  queue.each do |op|
@@ -18,28 +17,26 @@ describe Batsir::FilterQueue do
18
17
  ops.last.should_not be_nil
19
18
  end
20
19
 
21
- it "should be possible to add a notifier" do
20
+ it "can add a notifier" do
22
21
  queue = Batsir::FilterQueue.new
23
22
  notifier = "Notifier"
24
23
  queue.add_notifier(notifier)
25
24
  queue.should include notifier
26
25
  end
27
26
 
28
- it "should be possible to add multiple notifiers" do
27
+ it "can add multiple notifiers" do
29
28
  queue = Batsir::FilterQueue.new
30
29
  ops = []
31
30
  3.times do |index|
32
31
  ops << "Notifier #{index}"
33
32
  queue.add_notifier("Notifier #{index}")
34
33
  end
35
-
36
34
  ops.each {|op| queue.should include op}
37
35
  end
38
36
 
39
- it "should return notifiers as the last operations" do
40
- queue = Batsir::FilterQueue.new
37
+ it "returns notifiers as the last operations" do
41
38
  notifier = "Notifier"
42
-
39
+ queue = Batsir::FilterQueue.new
43
40
  queue.add("SomeFilter")
44
41
  queue.add_notifier(notifier)
45
42
  queue.add("AnotherFilter")
@@ -51,23 +48,20 @@ describe Batsir::FilterQueue do
51
48
  ops.last.should == notifier
52
49
  end
53
50
 
54
- it "should respond true to #empty? when no operations are added" do
51
+ it "responds true to #empty? when no operations are added" do
55
52
  queue = Batsir::FilterQueue.new
56
53
  queue.should be_empty
57
54
  end
58
55
 
59
- it "should not be empty when a notification operation is added" do
56
+ it "is not empty when a notification operation is added" do
60
57
  queue = Batsir::FilterQueue.new
61
58
  operation = "Notifier"
62
-
63
59
  queue.add_notifier(operation)
64
-
65
60
  queue.should_not be_empty
66
61
  end
67
62
 
68
- it "should not be empty when a regular operation is added" do
63
+ it "is not empty when a regular operation is added" do
69
64
  queue = Batsir::FilterQueue.new
70
-
71
65
  queue.add("SomeFilter")
72
66
  queue.should_not be_empty
73
67
  end
@@ -1,12 +1,11 @@
1
1
  require File.join( File.dirname(__FILE__), "..", "spec_helper" )
2
2
 
3
3
  describe Batsir::Filter do
4
- it "should be possible to create an filter" do
5
- filter = Batsir::Filter.new
6
- filter.should_not be_nil
4
+ it "has an #execute method" do
5
+ Batsir::Filter.instance_methods.map{|im| im.to_s}.should include "execute"
7
6
  end
8
7
 
9
- it "should have an #execute method" do
10
- Batsir::Filter.instance_methods.map{|im| im.to_s}.should include "execute"
8
+ it "throws an NotImplementedError when #execute method is not overridden" do
9
+ lambda{subject.execute("testing..1..2..3")}.should raise_error NotImplementedError
11
10
  end
12
11
  end
@@ -0,0 +1,10 @@
1
+ require File.join( File.dirname(__FILE__), "..", "spec_helper" )
2
+
3
+ describe Batsir::Log do
4
+ it 'provides a convenience method for logging' do
5
+ class TestClass
6
+ include Batsir::Log
7
+ end
8
+ TestClass.instance_methods.map{|im| im.to_s}.should include 'log'
9
+ end
10
+ end
@@ -0,0 +1,46 @@
1
+ require File.join( File.dirname(__FILE__), "..", "spec_helper" )
2
+
3
+ describe Batsir::Logger do
4
+ before :all do
5
+ @logger = Batsir::Logger
6
+ end
7
+
8
+ it 'returns an object of Log4r::Logger class' do
9
+ @logger.log.should be_a Log4r::Logger
10
+ end
11
+
12
+ it 'allows changing its settings' do
13
+ @logger.level.should_not == Log4r::DEBUG
14
+ @logger.level = Log4r::DEBUG
15
+ @logger.level.should == Log4r::DEBUG
16
+ end
17
+
18
+ it 'can be reset' do
19
+ current_log = @logger.level
20
+ Batsir::Logger.reset
21
+ @logger.level.should_not == current_log
22
+ end
23
+
24
+ it 'is able to use various log levels' do
25
+ @logger.level = Log4r::DEBUG
26
+ debug = @logger.debug("debug test message")
27
+ debug.should be_an Array
28
+ debug.select{|e| e.is_a?(Log4r::StdoutOutputter)}.should_not be_empty
29
+
30
+ info = @logger.info("info test message")
31
+ info.should be_an Array
32
+ info.select{|e| e.is_a?(Log4r::StdoutOutputter)}.should_not be_empty
33
+
34
+ warn = @logger.warn("warning test message")
35
+ warn.should be_an Array
36
+ warn.select{|e| e.is_a?(Log4r::StdoutOutputter)}.should_not be_empty
37
+
38
+ err = @logger.error("error test message")
39
+ err.should be_an Array
40
+ err.select{|e| e.is_a?(Log4r::StdoutOutputter)}.should_not be_empty
41
+
42
+ fatal = @logger.fatal("fatal test message")
43
+ fatal.should be_an Array
44
+ fatal.select{|e| e.is_a?(Log4r::StdoutOutputter)}.should_not be_empty
45
+ end
46
+ end