split 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,111 @@
1
+ require 'spec_helper'
2
+
3
+ describe Split::RedisInterface do
4
+ let(:list_name) { 'list_name' }
5
+ let(:set_name) { 'set_name' }
6
+ let(:interface) { described_class.new }
7
+
8
+ describe '#persist_list' do
9
+ subject(:persist_list) do
10
+ interface.persist_list(list_name, %w(a b c d))
11
+ end
12
+
13
+ specify do
14
+ expect(persist_list).to eq %w(a b c d)
15
+ expect(Split.redis.lindex(list_name, 0)).to eq 'a'
16
+ expect(Split.redis.lindex(list_name, 1)).to eq 'b'
17
+ expect(Split.redis.lindex(list_name, 2)).to eq 'c'
18
+ expect(Split.redis.lindex(list_name, 3)).to eq 'd'
19
+ expect(Split.redis.llen(list_name)).to eq 4
20
+ end
21
+
22
+ context 'list is overwritten but not deleted' do
23
+ specify do
24
+ expect(persist_list).to eq %w(a b c d)
25
+ interface.persist_list(list_name, ['z'])
26
+ expect(Split.redis.lindex(list_name, 0)).to eq 'z'
27
+ expect(Split.redis.llen(list_name)).to eq 1
28
+ end
29
+ end
30
+ end
31
+
32
+ describe '#add_to_list' do
33
+ subject(:add_to_list) do
34
+ interface.add_to_list(list_name, 'y')
35
+ interface.add_to_list(list_name, 'z')
36
+ end
37
+
38
+ specify do
39
+ add_to_list
40
+ expect(Split.redis.lindex(list_name, 0)).to eq 'y'
41
+ expect(Split.redis.lindex(list_name, 1)).to eq 'z'
42
+ expect(Split.redis.llen(list_name)).to eq 2
43
+ end
44
+ end
45
+
46
+ describe '#set_list_index' do
47
+ subject(:set_list_index) do
48
+ interface.add_to_list(list_name, 'y')
49
+ interface.add_to_list(list_name, 'z')
50
+ interface.set_list_index(list_name, 0, 'a')
51
+ end
52
+
53
+ specify do
54
+ set_list_index
55
+ expect(Split.redis.lindex(list_name, 0)).to eq 'a'
56
+ expect(Split.redis.lindex(list_name, 1)).to eq 'z'
57
+ expect(Split.redis.llen(list_name)).to eq 2
58
+ end
59
+ end
60
+
61
+ describe '#list_length' do
62
+ subject(:list_length) do
63
+ interface.add_to_list(list_name, 'y')
64
+ interface.add_to_list(list_name, 'z')
65
+ interface.list_length(list_name)
66
+ end
67
+
68
+ specify do
69
+ expect(list_length).to eq 2
70
+ end
71
+ end
72
+
73
+ describe '#remove_last_item_from_list' do
74
+ subject(:remove_last_item_from_list) do
75
+ interface.add_to_list(list_name, 'y')
76
+ interface.add_to_list(list_name, 'z')
77
+ interface.remove_last_item_from_list(list_name)
78
+ end
79
+
80
+ specify do
81
+ remove_last_item_from_list
82
+ expect(Split.redis.lindex(list_name, 0)).to eq 'y'
83
+ expect(Split.redis.llen(list_name)).to eq 1
84
+ end
85
+ end
86
+
87
+ describe '#make_list_length' do
88
+ subject(:make_list_length) do
89
+ interface.add_to_list(list_name, 'y')
90
+ interface.add_to_list(list_name, 'z')
91
+ interface.make_list_length(list_name, 1)
92
+ end
93
+
94
+ specify do
95
+ make_list_length
96
+ expect(Split.redis.lindex(list_name, 0)).to eq 'y'
97
+ expect(Split.redis.llen(list_name)).to eq 1
98
+ end
99
+ end
100
+
101
+ describe '#add_to_set' do
102
+ subject(:add_to_set) do
103
+ interface.add_to_set(set_name, 'something')
104
+ end
105
+
106
+ specify do
107
+ add_to_set
108
+ expect(Split.redis.sismember(set_name, 'something')).to be true
109
+ end
110
+ end
111
+ end
@@ -4,33 +4,34 @@ ENV['RACK_ENV'] = "test"
4
4
  require 'rubygems'
5
5
  require 'bundler/setup'
6
6
 
7
- require 'coveralls'
8
- Coveralls.wear!
7
+ require 'simplecov'
8
+ SimpleCov.start
9
9
 
10
10
  require 'split'
11
11
  require 'ostruct'
12
12
  require 'yaml'
13
- require 'complex' if RUBY_VERSION.match(/1\.8/)
14
13
 
15
14
  Dir['./spec/support/*.rb'].each { |f| require f }
16
15
 
17
16
  require "fakeredis"
18
17
 
19
- fakeredis = Redis.new
18
+ G_fakeredis = Redis.new
20
19
 
21
- RSpec.configure do |config|
22
- config.order = 'random'
23
- config.before(:each) do
20
+ module GlobalSharedContext
21
+ extend RSpec::SharedContext
22
+ let(:mock_user){ Split::User.new(double(session: {})) }
23
+ before(:each) do
24
24
  Split.configuration = Split::Configuration.new
25
- Split.redis = fakeredis
25
+ Split.redis = G_fakeredis
26
26
  Split.redis.flushall
27
27
  @ab_user = mock_user
28
28
  params = nil
29
29
  end
30
30
  end
31
31
 
32
- def mock_user
33
- Split::User.new(double(session: {}))
32
+ RSpec.configure do |config|
33
+ config.order = 'random'
34
+ config.include GlobalSharedContext
34
35
  end
35
36
 
36
37
  def session
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+ require 'spec_helper'
3
+
4
+ RSpec.describe Split do
5
+
6
+ around(:each) do |ex|
7
+ old_env, old_redis = [ENV.delete('REDIS_URL'), Split.redis]
8
+ ex.run
9
+ ENV['REDIS_URL'] = old_env
10
+ Split.redis = old_redis
11
+ end
12
+
13
+ describe '#redis=' do
14
+ it 'accepts a url string' do
15
+ Split.redis = 'redis://localhost:6379'
16
+ expect(Split.redis).to be_a(Redis)
17
+
18
+ client = Split.redis.client
19
+ expect(client.host).to eq("localhost")
20
+ expect(client.port).to eq(6379)
21
+ end
22
+
23
+ it 'accepts an options hash' do
24
+ Split.redis = {host: 'localhost', port: 6379, db: 12}
25
+ expect(Split.redis).to be_a(Redis)
26
+
27
+ client = Split.redis.client
28
+ expect(client.host).to eq("localhost")
29
+ expect(client.port).to eq(6379)
30
+ expect(client.db).to eq(12)
31
+ end
32
+
33
+ it 'accepts a valid Redis instance' do
34
+ other_redis = Redis.new(url: "redis://localhost:6379")
35
+ Split.redis = other_redis
36
+ expect(Split.redis).to eq(other_redis)
37
+ end
38
+
39
+ it 'raises an ArgumentError when server cannot be determined' do
40
+ expect { Split.redis = Object.new }.to raise_error(ArgumentError)
41
+ end
42
+ end
43
+ end
@@ -21,15 +21,14 @@ Gem::Specification.new do |s|
21
21
  s.require_paths = ["lib"]
22
22
 
23
23
  s.add_dependency 'redis', '>= 2.1'
24
- s.add_dependency 'redis-namespace', '>= 1.1.0'
25
24
  s.add_dependency 'sinatra', '>= 1.2.6'
26
25
  s.add_dependency 'simple-random', '>= 0.9.3'
27
26
 
28
27
  s.add_development_dependency 'bundler', '~> 1.10'
29
- s.add_development_dependency 'coveralls', '~> 0.8'
28
+ s.add_development_dependency 'simplecov', '~> 0.12'
30
29
  s.add_development_dependency 'rack-test', '~> 0.6'
31
30
  s.add_development_dependency 'rake', '~> 11.1'
32
31
  s.add_development_dependency 'rspec', '~> 3.4'
33
32
  s.add_development_dependency 'pry', '~> 0.10'
34
- s.add_development_dependency 'fakeredis', '~> 0.5.0'
33
+ s.add_development_dependency 'fakeredis', '~> 0.6.0'
35
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: split
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Nesbitt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-08 00:00:00.000000000 Z
11
+ date: 2016-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.1'
27
- - !ruby/object:Gem::Dependency
28
- name: redis-namespace
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: 1.1.0
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: 1.1.0
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: sinatra
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -81,19 +67,19 @@ dependencies:
81
67
  - !ruby/object:Gem::Version
82
68
  version: '1.10'
83
69
  - !ruby/object:Gem::Dependency
84
- name: coveralls
70
+ name: simplecov
85
71
  requirement: !ruby/object:Gem::Requirement
86
72
  requirements:
87
73
  - - "~>"
88
74
  - !ruby/object:Gem::Version
89
- version: '0.8'
75
+ version: '0.12'
90
76
  type: :development
91
77
  prerelease: false
92
78
  version_requirements: !ruby/object:Gem::Requirement
93
79
  requirements:
94
80
  - - "~>"
95
81
  - !ruby/object:Gem::Version
96
- version: '0.8'
82
+ version: '0.12'
97
83
  - !ruby/object:Gem::Dependency
98
84
  name: rack-test
99
85
  requirement: !ruby/object:Gem::Requirement
@@ -156,14 +142,14 @@ dependencies:
156
142
  requirements:
157
143
  - - "~>"
158
144
  - !ruby/object:Gem::Version
159
- version: 0.5.0
145
+ version: 0.6.0
160
146
  type: :development
161
147
  prerelease: false
162
148
  version_requirements: !ruby/object:Gem::Requirement
163
149
  requirements:
164
150
  - - "~>"
165
151
  - !ruby/object:Gem::Version
166
- version: 0.5.0
152
+ version: 0.6.0
167
153
  description:
168
154
  email:
169
155
  - andrewnez@gmail.com
@@ -171,7 +157,12 @@ executables: []
171
157
  extensions: []
172
158
  extra_rdoc_files: []
173
159
  files:
160
+ - ".codeclimate.yml"
161
+ - ".csslintrc"
162
+ - ".eslintignore"
163
+ - ".eslintrc"
174
164
  - ".gitignore"
165
+ - ".rubocop.yml"
175
166
  - ".travis.yml"
176
167
  - Appraisals
177
168
  - CHANGELOG.md
@@ -183,6 +174,7 @@ files:
183
174
  - Rakefile
184
175
  - gemfiles/4.1.gemfile
185
176
  - gemfiles/4.2.gemfile
177
+ - gemfiles/5.0.gemfile
186
178
  - lib/split.rb
187
179
  - lib/split/algorithms.rb
188
180
  - lib/split/algorithms/weighted_sample.rb
@@ -207,7 +199,6 @@ files:
207
199
  - lib/split/experiment.rb
208
200
  - lib/split/experiment_catalog.rb
209
201
  - lib/split/extensions.rb
210
- - lib/split/extensions/array.rb
211
202
  - lib/split/extensions/string.rb
212
203
  - lib/split/goals_collection.rb
213
204
  - lib/split/helper.rb
@@ -217,6 +208,7 @@ files:
217
208
  - lib/split/persistence/dual_adapter.rb
218
209
  - lib/split/persistence/redis_adapter.rb
219
210
  - lib/split/persistence/session_adapter.rb
211
+ - lib/split/redis_interface.rb
220
212
  - lib/split/trial.rb
221
213
  - lib/split/user.rb
222
214
  - lib/split/version.rb
@@ -234,10 +226,13 @@ files:
234
226
  - spec/helper_spec.rb
235
227
  - spec/metric_spec.rb
236
228
  - spec/persistence/cookie_adapter_spec.rb
229
+ - spec/persistence/dual_adapter_spec.rb
237
230
  - spec/persistence/redis_adapter_spec.rb
238
231
  - spec/persistence/session_adapter_spec.rb
239
232
  - spec/persistence_spec.rb
233
+ - spec/redis_interface_spec.rb
240
234
  - spec/spec_helper.rb
235
+ - spec/split_spec.rb
241
236
  - spec/support/cookies_mock.rb
242
237
  - spec/trial_spec.rb
243
238
  - spec/user_spec.rb
@@ -280,11 +275,13 @@ test_files:
280
275
  - spec/helper_spec.rb
281
276
  - spec/metric_spec.rb
282
277
  - spec/persistence/cookie_adapter_spec.rb
278
+ - spec/persistence/dual_adapter_spec.rb
283
279
  - spec/persistence/redis_adapter_spec.rb
284
280
  - spec/persistence/session_adapter_spec.rb
285
281
  - spec/persistence_spec.rb
282
+ - spec/redis_interface_spec.rb
286
283
  - spec/spec_helper.rb
284
+ - spec/split_spec.rb
287
285
  - spec/support/cookies_mock.rb
288
286
  - spec/trial_spec.rb
289
287
  - spec/user_spec.rb
290
- has_rdoc:
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
- class Array
3
- # maintain backwards compatibility with 1.8.7
4
- alias_method :sample, :choice unless method_defined?(:sample)
5
- end