batsir 0.3.7.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGES.md +9 -0
  3. data/README.md +1 -1
  4. data/lib/batsir/compiler/stage_worker_compiler.rb +42 -27
  5. data/lib/batsir/dsl/conditional_notifier_declaration.rb +7 -7
  6. data/lib/batsir/version.rb +3 -3
  7. metadata +81 -151
  8. data/.document +0 -5
  9. data/.rspec +0 -3
  10. data/.travis.yml +0 -18
  11. data/Gemfile +0 -19
  12. data/Rakefile +0 -62
  13. data/batsir.gemspec +0 -132
  14. data/batsir.png +0 -0
  15. data/spec/batsir/acceptors/acceptor_spec.rb +0 -65
  16. data/spec/batsir/acceptors/amqp_acceptor_spec.rb +0 -158
  17. data/spec/batsir/acceptors/shared_examples.rb +0 -102
  18. data/spec/batsir/amqp_spec.rb +0 -58
  19. data/spec/batsir/chain_spec.rb +0 -31
  20. data/spec/batsir/config_spec.rb +0 -97
  21. data/spec/batsir/dsl/chain_mapping_spec.rb +0 -116
  22. data/spec/batsir/dsl/conditional_notifier_mapping_spec.rb +0 -80
  23. data/spec/batsir/dsl/stage_mapping_spec.rb +0 -453
  24. data/spec/batsir/filter_queue_spec.rb +0 -68
  25. data/spec/batsir/filter_spec.rb +0 -11
  26. data/spec/batsir/log_spec.rb +0 -10
  27. data/spec/batsir/logger_spec.rb +0 -46
  28. data/spec/batsir/notifiers/amqp_notifier_spec.rb +0 -138
  29. data/spec/batsir/notifiers/conditional_notifier_spec.rb +0 -62
  30. data/spec/batsir/notifiers/notifier_spec.rb +0 -11
  31. data/spec/batsir/notifiers/shared_examples.rb +0 -100
  32. data/spec/batsir/registry_spec.rb +0 -48
  33. data/spec/batsir/stage_spec.rb +0 -684
  34. data/spec/batsir/stage_worker_spec.rb +0 -128
  35. data/spec/batsir/strategies/retry_strategy_spec.rb +0 -58
  36. data/spec/batsir/strategies/strategy_spec.rb +0 -28
  37. data/spec/batsir/support/bunny_mocks.rb +0 -135
  38. data/spec/batsir/support/mock_filters.rb +0 -43
  39. data/spec/batsir/transformers/field_transformer_spec.rb +0 -73
  40. data/spec/batsir/transformers/json_input_transformer_spec.rb +0 -27
  41. data/spec/batsir/transformers/json_output_transformer_spec.rb +0 -18
  42. data/spec/batsir/transformers/transformer_spec.rb +0 -36
  43. data/spec/spec_helper.rb +0 -26
data/batsir.gemspec DELETED
@@ -1,132 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = "batsir"
8
- s.version = "0.3.7.1"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["J.W. Koelewijn", "Bram de Vries"]
12
- s.date = "2013-10-24"
13
- s.description = "Batsir uses so called stages to define operation queues. These operation queues\n consist of several operations that will be executed one after the other. Each stage\n is defined by its name and the queue on which it will listen. Once a message is received\n on the queue, it is dispatched to a worker in a seperate thread that will pass the message\n to each operation in the operation queue.\n Operation queues can have 4 different operations, 1 common operation type, and 3 special\n purpose operations: retrieval operations (which are always executed before all other operations),\n persistence operations (which are always executed after the common operations, but before the\n notification operations) and notification operations (which will always be executed last)\n This makes it possible to create chains of stages to perform tasks that depend on each\n other, but otherwise have a low coupling"
14
- s.email = "jwkoelewijn@gmail.com"
15
- s.extra_rdoc_files = [
16
- "CHANGES.md",
17
- "LICENSE.txt",
18
- "README.md"
19
- ]
20
- s.files = [
21
- ".document",
22
- ".rspec",
23
- ".travis.yml",
24
- "CHANGES.md",
25
- "Gemfile",
26
- "LICENSE.txt",
27
- "README.md",
28
- "Rakefile",
29
- "batsir.gemspec",
30
- "batsir.png",
31
- "lib/batsir.rb",
32
- "lib/batsir/acceptors/acceptor.rb",
33
- "lib/batsir/acceptors/amqp_acceptor.rb",
34
- "lib/batsir/amqp.rb",
35
- "lib/batsir/amqp_consumer.rb",
36
- "lib/batsir/chain.rb",
37
- "lib/batsir/compiler/stage_worker_compiler.rb",
38
- "lib/batsir/config.rb",
39
- "lib/batsir/dsl/conditional_notifier_declaration.rb",
40
- "lib/batsir/dsl/dsl_mappings.rb",
41
- "lib/batsir/errors.rb",
42
- "lib/batsir/filter.rb",
43
- "lib/batsir/filter_queue.rb",
44
- "lib/batsir/log.rb",
45
- "lib/batsir/logger.rb",
46
- "lib/batsir/logo.rb",
47
- "lib/batsir/notifiers/amqp_notifier.rb",
48
- "lib/batsir/notifiers/conditional_notifier.rb",
49
- "lib/batsir/notifiers/notifier.rb",
50
- "lib/batsir/registry.rb",
51
- "lib/batsir/stage.rb",
52
- "lib/batsir/stage_worker.rb",
53
- "lib/batsir/strategies/retry_strategy.rb",
54
- "lib/batsir/strategies/strategy.rb",
55
- "lib/batsir/transformers/field_transformer.rb",
56
- "lib/batsir/transformers/json_input_transformer.rb",
57
- "lib/batsir/transformers/json_output_transformer.rb",
58
- "lib/batsir/transformers/transformer.rb",
59
- "lib/batsir/version.rb",
60
- "spec/batsir/acceptors/acceptor_spec.rb",
61
- "spec/batsir/acceptors/amqp_acceptor_spec.rb",
62
- "spec/batsir/acceptors/shared_examples.rb",
63
- "spec/batsir/amqp_spec.rb",
64
- "spec/batsir/chain_spec.rb",
65
- "spec/batsir/config_spec.rb",
66
- "spec/batsir/dsl/chain_mapping_spec.rb",
67
- "spec/batsir/dsl/conditional_notifier_mapping_spec.rb",
68
- "spec/batsir/dsl/stage_mapping_spec.rb",
69
- "spec/batsir/filter_queue_spec.rb",
70
- "spec/batsir/filter_spec.rb",
71
- "spec/batsir/log_spec.rb",
72
- "spec/batsir/logger_spec.rb",
73
- "spec/batsir/notifiers/amqp_notifier_spec.rb",
74
- "spec/batsir/notifiers/conditional_notifier_spec.rb",
75
- "spec/batsir/notifiers/notifier_spec.rb",
76
- "spec/batsir/notifiers/shared_examples.rb",
77
- "spec/batsir/registry_spec.rb",
78
- "spec/batsir/stage_spec.rb",
79
- "spec/batsir/stage_worker_spec.rb",
80
- "spec/batsir/strategies/retry_strategy_spec.rb",
81
- "spec/batsir/strategies/strategy_spec.rb",
82
- "spec/batsir/support/bunny_mocks.rb",
83
- "spec/batsir/support/mock_filters.rb",
84
- "spec/batsir/transformers/field_transformer_spec.rb",
85
- "spec/batsir/transformers/json_input_transformer_spec.rb",
86
- "spec/batsir/transformers/json_output_transformer_spec.rb",
87
- "spec/batsir/transformers/transformer_spec.rb",
88
- "spec/spec_helper.rb"
89
- ]
90
- s.homepage = "http://github.com/jwkoelewijn/batsir"
91
- s.licenses = ["MIT"]
92
- s.require_paths = ["lib"]
93
- s.rubygems_version = "1.8.25"
94
- s.summary = "Batsir is an execution platform for stage based operation queue execution"
95
-
96
- if s.respond_to? :specification_version then
97
- s.specification_version = 3
98
-
99
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
100
- s.add_runtime_dependency(%q<bundler>, ["> 1.0.0"])
101
- s.add_runtime_dependency(%q<jeweler>, [">= 0"])
102
- s.add_runtime_dependency(%q<rdoc>, [">= 0"])
103
- s.add_runtime_dependency(%q<blockenspiel>, [">= 0.4.3"])
104
- s.add_runtime_dependency(%q<celluloid>, ["~> 0.14.1"])
105
- s.add_runtime_dependency(%q<sidekiq>, [">= 2.5.4"])
106
- s.add_runtime_dependency(%q<bunny>, ["~> 0.10.7"])
107
- s.add_runtime_dependency(%q<json>, [">= 0"])
108
- s.add_runtime_dependency(%q<log4r>, [">= 0"])
109
- else
110
- s.add_dependency(%q<bundler>, ["> 1.0.0"])
111
- s.add_dependency(%q<jeweler>, [">= 0"])
112
- s.add_dependency(%q<rdoc>, [">= 0"])
113
- s.add_dependency(%q<blockenspiel>, [">= 0.4.3"])
114
- s.add_dependency(%q<celluloid>, ["~> 0.14.1"])
115
- s.add_dependency(%q<sidekiq>, [">= 2.5.4"])
116
- s.add_dependency(%q<bunny>, ["~> 0.10.7"])
117
- s.add_dependency(%q<json>, [">= 0"])
118
- s.add_dependency(%q<log4r>, [">= 0"])
119
- end
120
- else
121
- s.add_dependency(%q<bundler>, ["> 1.0.0"])
122
- s.add_dependency(%q<jeweler>, [">= 0"])
123
- s.add_dependency(%q<rdoc>, [">= 0"])
124
- s.add_dependency(%q<blockenspiel>, [">= 0.4.3"])
125
- s.add_dependency(%q<celluloid>, ["~> 0.14.1"])
126
- s.add_dependency(%q<sidekiq>, [">= 2.5.4"])
127
- s.add_dependency(%q<bunny>, ["~> 0.10.7"])
128
- s.add_dependency(%q<json>, [">= 0"])
129
- s.add_dependency(%q<log4r>, [">= 0"])
130
- end
131
- end
132
-
data/batsir.png DELETED
Binary file
@@ -1,65 +0,0 @@
1
- require File.join( File.dirname(__FILE__), "..", "..", "spec_helper" )
2
- require File.join( File.dirname(__FILE__), 'shared_examples')
3
-
4
-
5
- describe Batsir::Acceptors::Acceptor do
6
- it_behaves_like "an acceptor", Batsir::Acceptors::Acceptor
7
-
8
- let( :acceptor_class ) {
9
- Batsir::Acceptors::Acceptor
10
- }
11
-
12
- it "is a Celluloid actor" do
13
- acceptor_class.ancestors.should include Celluloid
14
- end
15
-
16
- it "calls the #perform_async on the worker class when #start_filter_chain is called" do
17
- class MockWorker
18
- def self.stage_name
19
- "mock_stage"
20
- end
21
-
22
- def self.initialize_filter_queue
23
- end
24
-
25
- def self.perform_async(*args)
26
- end
27
-
28
- include Batsir::StageWorker
29
- end
30
-
31
- acceptor = acceptor_class.new
32
- stage_name = "some stage"
33
-
34
- acceptor.stage_name = stage_name
35
-
36
- Batsir::Registry.register(stage_name, MockWorker)
37
- MockWorker.should_receive(:perform_async)
38
- acceptor.start_filter_chain({})
39
- end
40
-
41
- it "calls #transform on the acceptor transformers" do
42
- class MockTransformer < Batsir::Transformers::Transformer
43
- def transform(message)
44
- @@transformed ||= 0
45
- @@transformed += 1
46
- end
47
-
48
- def self.transformed
49
- @@transformed ||= 0
50
- @@transformed
51
- end
52
- end
53
-
54
- acceptor = acceptor_class.new
55
- stage_name = "some stage"
56
- acceptor.stage_name = stage_name
57
- acceptor.add_transformer MockTransformer.new
58
-
59
- MockTransformer.transformed.should == 0
60
-
61
- acceptor.start_filter_chain({})
62
-
63
- MockTransformer.transformed.should == 1
64
- end
65
- end
@@ -1,158 +0,0 @@
1
- require File.join( File.dirname(__FILE__), "..", "..", "spec_helper" )
2
- require File.join( File.dirname(__FILE__), 'shared_examples')
3
-
4
- describe Batsir::Acceptors::AMQPAcceptor do
5
- it_behaves_like "an acceptor", Batsir::Acceptors::AMQPAcceptor
6
-
7
- let(:acceptor_class){
8
- Batsir::Acceptors::AMQPAcceptor
9
- }
10
-
11
- context "instantiating" do
12
- it "sets a bunny pool" do
13
- acceptor = acceptor_class.new
14
- acceptor.bunny_pool.should be_kind_of ConnectionPool
15
- end
16
-
17
- it "uses the same ConnectionPool instance for each acceptor" do
18
- acceptor1 = acceptor_class.new
19
- acceptor2 = acceptor_class.new
20
- acceptor1.should_not eql acceptor2
21
- acceptor1.bunny_pool.should eql acceptor2.bunny_pool
22
- end
23
- end
24
-
25
- context "setting options" do
26
- it "can set the queue on which to listen" do
27
- acceptor = acceptor_class.new(:queue => :queue)
28
- acceptor.queue.should == :queue
29
- end
30
-
31
- it "can set the host of the amqp broker" do
32
- acceptor = acceptor_class.new(:host => 'localhost')
33
- acceptor.host.should == 'localhost'
34
- end
35
-
36
- it "can set the port of the amqp broker" do
37
- acceptor = acceptor_class.new(:port => 1234)
38
- acceptor.port.should == 1234
39
- end
40
-
41
- it "can set the username with which to connect to the broker" do
42
- acceptor = acceptor_class.new(:username => 'some_user')
43
- acceptor.username.should == 'some_user'
44
- end
45
-
46
- it "can set the password with which to connect to the broker" do
47
- acceptor = acceptor_class.new(:password => 'password')
48
- acceptor.password.should == 'password'
49
- end
50
-
51
- it "can set the vhost to use on the broker" do
52
- acceptor = acceptor_class.new(:vhost => '/vhost')
53
- acceptor.vhost.should == '/vhost'
54
- end
55
-
56
- it "can set the exchange to use on the broker" do
57
- acceptor = acceptor_class.new(:exchange => 'amq.direct')
58
- acceptor.exchange.should == 'amq.direct'
59
- end
60
-
61
- it "can set the queue to be durable" do
62
- acceptor = acceptor_class.new(:durable => true)
63
- acceptor.durable.should == true
64
- end
65
-
66
- it "defaults to amqp://guest:guest@localhost:5672/ with direct exchange on vhost ''" do
67
- acceptor = acceptor_class.new(:queue => :somequeue)
68
- acceptor.queue.should == :somequeue
69
- acceptor.host.should == 'localhost'
70
- acceptor.port.should == 5672
71
- acceptor.username.should == 'guest'
72
- acceptor.password.should == 'guest'
73
- acceptor.vhost.should == '/'
74
- acceptor.exchange.should == 'amq.direct'
75
- end
76
- end
77
-
78
- context "starting the acceptor" do
79
- def new_acceptor(options = {})
80
- acceptor_class.new({:queue => 'test_queue'}.merge options)
81
- end
82
-
83
- it "starts listening on the configured queue" do
84
- acceptor = new_acceptor()
85
- acceptor.bunny_pool do |bunny|
86
- acceptor.consumer.queue.name.should == 'test_queue'
87
- end
88
- end
89
-
90
- it "connects to the configured host" do
91
- acceptor = new_acceptor(:host => 'localhost')
92
- acceptor.start
93
- acceptor.consumer.queue.channel.connection.host.should == 'localhost'
94
- end
95
-
96
- it "connects to the configured port" do
97
- acceptor = new_acceptor(:port => 5672)
98
- acceptor.start
99
- acceptor.consumer.queue.channel.connection.port.should == 5672
100
- end
101
-
102
- it "connects with the configured username" do
103
- acceptor = new_acceptor(:username => 'guest', :password => 'guest')
104
- acceptor.start
105
- acceptor.consumer.queue.channel.connection.user.should == 'guest'
106
- acceptor.consumer.queue.channel.connection.pass.should == 'guest'
107
- end
108
-
109
- it "connects to the configured vhost" do
110
- acceptor = new_acceptor(:vhost => '/')
111
- acceptor.start
112
- acceptor.consumer.queue.channel.connection.vhost.should == '/'
113
- end
114
-
115
- it "declares the configured exchange" do
116
- acceptor = new_acceptor(:exchange => 'some_exchange')
117
- acceptor.start
118
- acceptor.consumer.queue.instance_variable_get(:@bindings).first[:exchange].should == 'some_exchange'
119
- end
120
-
121
- it "binds the configured exchange to the queue" do
122
- acceptor = new_acceptor(:exchange => 'some_exchange', :queue => :queue)
123
- acceptor.start
124
- binding = acceptor.consumer.queue.instance_variable_get(:@bindings).first
125
- binding[:exchange].should == 'some_exchange'
126
- binding[:routing_key].should == :queue
127
- end
128
-
129
- it "calls the #start_filter_chain method when a message is received" do
130
- acceptor = new_acceptor(:queue => :some_queue)
131
-
132
- # Because acceptor is a Celluloid Actor, it is not possible to define a method
133
- # on the instance directly, because you actually hold a reference to a
134
- # ActorProxy.
135
- # Fortunately, ActorProxy defines the #_send_ method, which we can use to
136
- # define a singleton_method on the actual proxied instance.
137
- # We cannot just redefine the class method here, because it will break other
138
- # tests.
139
-
140
- start_filter_chain_mock_method = lambda do |message|
141
- @method_called ||= 0
142
- @method_called += 1
143
- end
144
-
145
- method_called_mock_method = lambda do
146
- @method_called ||= 0
147
- end
148
-
149
- acceptor._send_(:define_singleton_method, :start_filter_chain, start_filter_chain_mock_method)
150
- acceptor._send_(:define_singleton_method, :method_called, method_called_mock_method)
151
-
152
- acceptor.start
153
- acceptor.consumer.call({})
154
-
155
- acceptor.method_called.should == 1
156
- end
157
- end
158
- end
@@ -1,102 +0,0 @@
1
- shared_examples_for "an acceptor" do |acceptor_class|
2
- before :each do
3
- subject{acceptor_class.new}
4
- end
5
-
6
- context 'properties' do
7
- it "is a Batsir::Acceptors::Acceptor" do
8
- subject.should be_kind_of Batsir::Acceptors::Acceptor
9
- end
10
-
11
- it "has a #start method" do
12
- subject.class.instance_methods.map{|im| im.to_s}.should include "start"
13
- end
14
-
15
- it "has a #start_filter_chain method" do
16
- subject.class.instance_methods.map{|im| im.to_s}.should include "start_filter_chain"
17
- end
18
-
19
- it "has a transformer_queue" do
20
- subject.transformer_queue.should_not be_nil
21
- end
22
- end
23
-
24
- context 'instances' do
25
- it "can initialize an Acceptor with on options hash" do
26
- acceptor = acceptor_class.new({})
27
- acceptor.should_not be_nil
28
- end
29
-
30
- it "initially has an empty transformer_queue" do
31
- subject.transformer_queue.should_not be_nil
32
- subject.transformer_queue.should be_empty
33
- end
34
-
35
- it "can set the stage name for the acceptor" do
36
- acceptor = acceptor_class.new
37
- stage_name = "some stage"
38
- acceptor.stage_name = stage_name
39
- acceptor.stage_name.should == stage_name
40
- end
41
-
42
- it "looks up a worker class when the #start_filter_chain method is called" do
43
- acceptor = acceptor_class.new
44
- stage_name = "some stage"
45
- acceptor.stage_name = stage_name
46
- Batsir::Registry.should_receive(:get).with(stage_name)
47
- acceptor.start_filter_chain({})
48
- end
49
- end
50
-
51
- context 'transformers' do
52
- it "can add a transformer to the transformer_queue" do
53
- transformer = :transformer
54
-
55
- acceptor = acceptor_class.new
56
- acceptor.add_transformer transformer
57
-
58
- acceptor.transformer_queue.should_not be_empty
59
- acceptor.transformer_queue.size.should == 1
60
- acceptor.transformer_queue.first.should == :transformer
61
- end
62
-
63
- it "can add a transformer multiple times" do
64
- transformer = :transformer
65
-
66
- acceptor = acceptor_class.new
67
- acceptor.add_transformer transformer
68
- acceptor.add_transformer transformer
69
-
70
- acceptor.transformer_queue.should_not be_empty
71
- acceptor.transformer_queue.size.should == 2
72
- end
73
-
74
- it "handles errors thrown by transformers" do
75
- class ErrorAcceptor < Batsir::Acceptors::Acceptor
76
- attr_accessor :message
77
- def process_message_error(message, error)
78
- message = "error"
79
- @message = message
80
- end
81
- end
82
-
83
- class MockTransformer < Batsir::Transformers::Transformer
84
- def transform(message)
85
- raise Batsir::Errors::TransformError.new
86
- end
87
- end
88
-
89
- acceptor = ErrorAcceptor.new
90
- stage_name = "some stage"
91
- acceptor.stage_name = stage_name
92
- acceptor.add_transformer MockTransformer.new
93
-
94
- acceptor.message.should be_nil
95
-
96
- acceptor.start_filter_chain({})
97
-
98
- acceptor.message.should == "error"
99
- end
100
- end
101
-
102
- end
@@ -1,58 +0,0 @@
1
- require File.join( File.dirname(__FILE__), "..", "spec_helper" )
2
-
3
- describe Batsir::AMQP do
4
- before :all do
5
- class AMQPTest
6
- include Batsir::AMQP
7
- end
8
- @test = AMQPTest.new
9
- end
10
-
11
- context 'with respect to default variables' do
12
- it 'has a host' do
13
- @test.host.should == 'localhost'
14
- end
15
-
16
- it 'has a port' do
17
- @test.port.should == 5672
18
- end
19
-
20
- it 'has a username' do
21
- @test.username.should == 'guest'
22
- end
23
-
24
- it 'has a password' do
25
- @test.password.should == 'guest'
26
- end
27
-
28
- it 'has a vhost' do
29
- @test.vhost.should == '/'
30
- end
31
-
32
- it 'has a exchange' do
33
- @test.exchange.should == 'amq.direct'
34
- end
35
-
36
- it 'is durable' do
37
- @test.durable.should == true
38
- end
39
-
40
- it 'is undead' do
41
- @test.heartbeat.should == 0
42
- end
43
- end
44
-
45
- context 'with respect to setting variables' do
46
- it 'can change host' do
47
- localhost = '127.0.0.1'
48
- @test.host = localhost
49
- @test.host.should == localhost
50
- end
51
-
52
- it 'can change heartbeat' do
53
- hb = 512
54
- @test.heartbeat = hb
55
- @test.heartbeat.should == hb
56
- end
57
- end
58
- end
@@ -1,31 +0,0 @@
1
- require File.join( File.dirname(__FILE__), "..", "spec_helper" )
2
-
3
- describe Batsir::Chain do
4
- it "has a list of stages" do
5
- chain = Batsir::Chain.new
6
- chain.stages.should_not be_nil
7
- end
8
-
9
- it "initially has an empty list of stages" do
10
- chain = Batsir::Chain.new
11
- chain.stages.should be_empty
12
- end
13
-
14
- it "can add a stage" do
15
- chain = Batsir::Chain.new
16
- stage = Batsir::Stage.new(:name => "Stage")
17
- chain.add_stage(stage)
18
- chain.stages.should include stage
19
- end
20
-
21
- it "can compile a chain" do
22
- chain = Batsir::Chain.new
23
- stage = Batsir::Stage.new(:name => "Stage")
24
- chain.add_stage(stage)
25
- compiled_code = chain.compile
26
- compiled_code.should_not be_nil
27
-
28
- klazz = eval(compiled_code)
29
- klazz.name.to_s.should == "StageWorker"
30
- end
31
- end
@@ -1,97 +0,0 @@
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