berater 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -17,19 +17,13 @@ describe Berater::Unlimiter do
17
17
  end
18
18
 
19
19
  describe '#limit' do
20
- let(:limiter) { described_class.new }
20
+ subject { described_class.new }
21
21
 
22
- it 'works' do
23
- expect {|b| limiter.limit(&b) }.to yield_control
24
- end
25
-
26
- it 'works without a block' do
27
- expect(limiter.limit).to be_a Berater::Lock
28
- end
22
+ it_behaves_like 'it is not overloaded'
29
23
 
30
24
  it 'is never overloaded' do
31
25
  10.times do
32
- expect { limiter.limit }.not_to be_overloaded
26
+ expect { subject.limit }.not_to be_overloaded
33
27
  end
34
28
  end
35
29
  end
@@ -0,0 +1,78 @@
1
+ describe Berater::Utils do
2
+ using Berater::Utils
3
+
4
+ describe '.to_usec' do
5
+ def f(val)
6
+ (val * 10**6).to_i
7
+ end
8
+
9
+ it 'works with integers' do
10
+ expect(0.to_usec).to be f(0)
11
+ expect(3.to_usec).to be f(3)
12
+ end
13
+
14
+ it 'works with floats' do
15
+ expect(0.1.to_usec).to be f(0.1)
16
+ expect(3.0.to_usec).to be f(3)
17
+ end
18
+
19
+ it 'has great precision' do
20
+ expect(0.123456.to_usec).to be 123456
21
+ expect(123456.654321.to_usec).to be 123456654321
22
+ end
23
+
24
+ it 'works with symbols that are keywords' do
25
+ expect(:sec.to_usec).to be f(1)
26
+ expect(:second.to_usec).to be f(1)
27
+ expect(:seconds.to_usec).to be f(1)
28
+
29
+ expect(:min.to_usec).to be f(60)
30
+ expect(:minute.to_usec).to be f(60)
31
+ expect(:minutes.to_usec).to be f(60)
32
+
33
+ expect(:hour.to_usec).to be f(60 * 60)
34
+ expect(:hours.to_usec).to be f(60 * 60)
35
+ end
36
+
37
+ it 'works with strings that are keywords' do
38
+ expect('sec'.to_usec).to be f(1)
39
+ expect('second'.to_usec).to be f(1)
40
+ expect('seconds'.to_usec).to be f(1)
41
+
42
+ expect('min'.to_usec).to be f(60)
43
+ expect('minute'.to_usec).to be f(60)
44
+ expect('minutes'.to_usec).to be f(60)
45
+
46
+ expect('hour'.to_usec).to be f(60 * 60)
47
+ expect('hours'.to_usec).to be f(60 * 60)
48
+ end
49
+
50
+ it 'works with strings that are numeric' do
51
+ expect('0'.to_usec).to be f(0)
52
+ expect('3'.to_usec).to be f(3)
53
+
54
+ expect('0.1'.to_usec).to be f(0.1)
55
+ expect('3.0'.to_usec).to be f(3)
56
+ end
57
+
58
+ context 'with erroneous values' do
59
+ def e(val)
60
+ expect { val.to_usec }.to raise_error(ArgumentError)
61
+ end
62
+
63
+ it 'rejects negative numbers' do
64
+ e(-1)
65
+ e(-1.2)
66
+ e('-1')
67
+ end
68
+
69
+ it 'rejects bogus symbols and strings' do
70
+ e('abc')
71
+ e('1a')
72
+ e(:abc)
73
+ e(Float::INFINITY)
74
+ end
75
+ end
76
+ end
77
+
78
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: berater
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Pepper
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-22 00:00:00.000000000 Z
11
+ date: 2021-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: benchmark
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: byebug
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -108,7 +122,7 @@ dependencies:
108
122
  - - ">="
109
123
  - !ruby/object:Gem::Version
110
124
  version: '0'
111
- description: rate limiter
125
+ description: work...within limits
112
126
  email:
113
127
  executables: []
114
128
  extensions: []
@@ -120,19 +134,27 @@ files:
120
134
  - lib/berater/inhibitor.rb
121
135
  - lib/berater/limiter.rb
122
136
  - lib/berater/lock.rb
137
+ - lib/berater/lua_script.rb
123
138
  - lib/berater/rate_limiter.rb
124
139
  - lib/berater/rspec.rb
125
140
  - lib/berater/rspec/matchers.rb
126
141
  - lib/berater/test_mode.rb
127
142
  - lib/berater/unlimiter.rb
143
+ - lib/berater/utils.rb
128
144
  - lib/berater/version.rb
129
145
  - spec/berater_spec.rb
130
146
  - spec/concurrency_limiter_spec.rb
147
+ - spec/dsl_refinement_spec.rb
148
+ - spec/dsl_spec.rb
131
149
  - spec/inhibitor_spec.rb
150
+ - spec/limiter_spec.rb
151
+ - spec/lua_script_spec.rb
132
152
  - spec/matchers_spec.rb
133
153
  - spec/rate_limiter_spec.rb
154
+ - spec/riddle_spec.rb
134
155
  - spec/test_mode_spec.rb
135
156
  - spec/unlimiter_spec.rb
157
+ - spec/utils_spec.rb
136
158
  homepage: https://github.com/dpep/berater_rb
137
159
  licenses:
138
160
  - MIT
@@ -159,8 +181,14 @@ summary: Berater
159
181
  test_files:
160
182
  - spec/rate_limiter_spec.rb
161
183
  - spec/matchers_spec.rb
184
+ - spec/dsl_refinement_spec.rb
162
185
  - spec/test_mode_spec.rb
186
+ - spec/dsl_spec.rb
187
+ - spec/lua_script_spec.rb
163
188
  - spec/concurrency_limiter_spec.rb
189
+ - spec/riddle_spec.rb
190
+ - spec/utils_spec.rb
164
191
  - spec/berater_spec.rb
192
+ - spec/limiter_spec.rb
165
193
  - spec/inhibitor_spec.rb
166
194
  - spec/unlimiter_spec.rb