greenjaguar 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e4fc61d4fffe390ea3af3fabff9edd69042b4586
4
- data.tar.gz: 64b48478ccdfa7af0887c669d969aa11865b135c
3
+ metadata.gz: 84523e4db04a5527e3dab130b50a0b4a68bf6ab1
4
+ data.tar.gz: 515888c081b94b8733ad865b21cfafd62b32789e
5
5
  SHA512:
6
- metadata.gz: e5fc9b39e21fbe19bc83d2bf767005614298df222cd990c8853bbcc987b37fa3b7bcd13ae1ca50c8fc23767a1e328c3700bfd85730709b69f2235fde25caaf92
7
- data.tar.gz: 1d30022a6c2d4506cdf8c200aec18af14b3dfd598c84886e85804a6d776db767b00b8d38750a5b265cece72269af86d40d58ee005f09bc1f684c59eb128ca112
6
+ metadata.gz: 6c60c04211a67629397bbbe3666b834ce481296b48e13d44541dc1263898052ec57c0f8e5f19bd372212e1a8a78b410548f3da4ba30693dfb8dd4ded179b8c35
7
+ data.tar.gz: 40f915a3bcff528b9233c485eeb14d7a61ef5730aa68bd1fc9b4b14c9455badf2b3216bec423282a00dee0c0d71d8224fdb860ca915ef7f5924b721e8018aadb
@@ -1,6 +1,6 @@
1
1
  module Greenjaguar
2
2
  class PolicyBuilder
3
- attr_accessor :count, :wait_strategy, :timeout, :logger, :strategy, :exceptions
3
+ attr_accessor :count, :wait_strategy, :timeout, :logger, :exceptions
4
4
 
5
5
  def initialize(&block)
6
6
  @count = 1
@@ -41,7 +41,7 @@ module Greenjaguar
41
41
  end
42
42
 
43
43
  def measure_time_in(time_unit)
44
- @strategy.time_unit = time_unit
44
+ strategy.time_unit = time_unit
45
45
  self
46
46
  end
47
47
 
@@ -67,12 +67,12 @@ module Greenjaguar
67
67
  strategy.wait
68
68
  end
69
69
 
70
- private
71
-
72
70
  def strategy
73
71
  @strategy ||= init_wait_strategy(:default)
74
72
  end
75
73
 
74
+ private
75
+
76
76
  def init_wait_strategy(wait_strategy, *args)
77
77
  case wait_strategy
78
78
  when :fibonacci
@@ -1,3 +1,3 @@
1
1
  module Greenjaguar
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -15,7 +15,7 @@ module Specs
15
15
  WebMock.reset!
16
16
  end
17
17
 
18
- it '#run should call the passed code block 4 times' do
18
+ it 'should call the passed code block 4 times' do
19
19
  policy = @object_under_test.build_policy do
20
20
  times 3
21
21
  end
@@ -28,7 +28,7 @@ module Specs
28
28
  assert_requested :get, "http://www.example.com", :times => 4
29
29
  end
30
30
 
31
- it '#run should call the passed code block only 1 time if successful response is received' do
31
+ it 'should call the passed code block only 1 time if successful response is received' do
32
32
  @stub = stub_request(:get, "http://www.example.com")
33
33
 
34
34
  policy = @object_under_test.build_policy do
@@ -41,7 +41,7 @@ module Specs
41
41
  assert_requested :get, "http://www.example.com", :times => 1
42
42
  end
43
43
 
44
- it '#run should raise the error once retrying is completed' do
44
+ it 'should raise the error once retrying is completed' do
45
45
  policy = @object_under_test.build_policy do
46
46
  times 3
47
47
  end
@@ -53,7 +53,7 @@ module Specs
53
53
  end.to raise_error
54
54
  end
55
55
 
56
- it '#run should call the passed code block 4 times according to fibonacci sequence' do
56
+ it 'should call the passed code block 4 times according to fibonacci sequence' do
57
57
  policy = @object_under_test.build_policy do
58
58
  times 3
59
59
  with_strategy :fibonacci
@@ -68,7 +68,7 @@ module Specs
68
68
  assert_requested :get, "http://www.example.com", :times => 4
69
69
  end
70
70
 
71
- it '#run should call the passed code block 4 times according to fixed interval strategy' do
71
+ it 'should call the passed code block 4 times according to fixed interval strategy' do
72
72
  policy = @object_under_test.build_policy do
73
73
  times 3
74
74
  with_strategy :fixed_interval, 2
@@ -83,7 +83,7 @@ module Specs
83
83
  assert_requested :get, "http://www.example.com", :times => 4
84
84
  end
85
85
 
86
- it '#run should call the passed code block 4 times according to exponential backoff sequence' do
86
+ it 'should call the passed code block 4 times according to exponential backoff sequence' do
87
87
  policy = @object_under_test.build_policy do
88
88
  times 5
89
89
  with_strategy :exponential_backoff
@@ -98,7 +98,7 @@ module Specs
98
98
  assert_requested :get, "http://www.example.com", :times => 6
99
99
  end
100
100
 
101
- it '#run does not call the passed code block if exception is not part of allowed exception(s)' do
101
+ it 'does not call the passed code block if exception is not part of allowed exception(s)' do
102
102
  @stub = stub_request(:get, "www.example.com").to_raise(RegexpError)
103
103
  policy = @object_under_test.build_policy do
104
104
  times 5
@@ -114,7 +114,7 @@ module Specs
114
114
  assert_requested :get, "http://www.example.com", :times => 1
115
115
  end
116
116
 
117
- it '#run should call the passed code block if exception is part of allowed exception(s)' do
117
+ it 'should call the passed code block if exception is part of allowed exception(s)' do
118
118
  @stub = stub_request(:get, "http://www.example.com").to_raise(ZeroDivisionError)
119
119
 
120
120
  policy = @object_under_test.build_policy do
@@ -132,7 +132,7 @@ module Specs
132
132
  assert_requested :get, "http://www.example.com", :times => 11
133
133
  end
134
134
 
135
- it '#run should not raise the error if set to fail silently' do
135
+ it 'should not raise the error if set to fail silently' do
136
136
  policy = @object_under_test.build_policy do
137
137
  times 3
138
138
  fail_silently
@@ -143,5 +143,15 @@ module Specs
143
143
  end
144
144
  end
145
145
 
146
+ it 'should use default strategy when none is specified' do
147
+ policy = @object_under_test.build_policy do
148
+ times 3
149
+ measure_time_in :ms
150
+ fail_silently
151
+ end
152
+
153
+ expect(policy.strategy.class).to eql(Greenjaguar::Strategies::DefaultWaitStrategy)
154
+ end
155
+
146
156
  end
147
157
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: greenjaguar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aniruddha Deshpande