ldclient-rb 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ require "spec_helper"
2
+
3
+ describe LaunchDarkly::LDNewRelic do
4
+ subject { LaunchDarkly::LDNewRelic }
5
+ end
@@ -0,0 +1,9 @@
1
+ require "codeclimate-test-reporter"
2
+ CodeClimate::TestReporter.start
3
+
4
+ require "ldclient-rb"
5
+
6
+ RSpec.configure do |config|
7
+ config.before(:each) do
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ require "spec_helper"
2
+
3
+ describe LaunchDarkly::ThreadSafeMemoryStore do
4
+ subject { LaunchDarkly::ThreadSafeMemoryStore }
5
+ let(:store) { subject.new }
6
+ it "can read and write" do
7
+ store.write("key", "value")
8
+ expect(store.read("key")).to eq "value"
9
+ end
10
+ end
@@ -0,0 +1,118 @@
1
+ require "spec_helper"
2
+
3
+ describe LaunchDarkly::InMemoryFeatureStore do
4
+ subject { LaunchDarkly::InMemoryFeatureStore }
5
+ let(:store) { subject.new }
6
+ let(:key) { :asdf }
7
+ let(:feature) { { value: "qwer", version: 0 } }
8
+
9
+ describe '#all' do
10
+ it "will get all keys" do
11
+ store.upsert(key, feature)
12
+ data = store.all
13
+ expect(data).to eq(key => feature)
14
+ end
15
+ it "will not get deleted keys" do
16
+ store.upsert(key, feature)
17
+ store.delete(key, 1)
18
+ data = store.all
19
+ expect(data).to eq({})
20
+ end
21
+ end
22
+
23
+ describe '#initialized?' do
24
+ it "will return whether the store has been initialized" do
25
+ expect(store.initialized?).to eq false
26
+ store.init(key => feature)
27
+ expect(store.initialized?).to eq true
28
+ end
29
+ end
30
+ end
31
+
32
+ describe LaunchDarkly::StreamProcessor do
33
+ subject { LaunchDarkly::StreamProcessor }
34
+ let(:config) { LaunchDarkly::Config.new }
35
+ let(:processor) { subject.new("api_key", config) }
36
+ describe '#start' do
37
+ it "will check if the reactor has started" do
38
+ expect(processor).to receive(:start_reactor).and_return false
39
+ expect(EM).to_not receive(:defer)
40
+ processor.start
41
+ end
42
+ it "will check if the stream processor has already started" do
43
+ expect(processor).to receive(:start_reactor).and_return true
44
+ processor.instance_variable_get(:@started).make_true
45
+ expect(EM).to_not receive(:defer)
46
+ processor.start
47
+ end
48
+ it "will boot the stream processor" do
49
+ expect(processor).to receive(:start_reactor).and_return true
50
+ expect(EM).to receive(:defer)
51
+ processor.start
52
+ end
53
+ end
54
+
55
+ describe '#boot_event_manager' do
56
+ let(:message) { "asdf" }
57
+ before do
58
+ processor.instance_variable_get(:@config).instance_variable_set(:@stream_uri, "http://example.com/streaming")
59
+ expect_any_instance_of(EM::EventSource).to receive(:start)
60
+ source = processor.send(:boot_event_manager)
61
+ @req = source.instance_variable_get "@req"
62
+ # It seems testing EventManager is hard/impossible
63
+ end
64
+ it "will start" do
65
+ end
66
+ xit "will process put messages" do
67
+ expect(processor).to receive(:process_message).with(message, LaunchDarkly::PUT)
68
+ @req.stream_data("data: #{message}\nevent:#{LaunchDarkly::PUT}\n")
69
+ end
70
+ xit "will process patch messages" do
71
+ expect(processor).to receive(:process_message).with(message, LaunchDarkly::PATCH)
72
+ end
73
+ xit "will process delete messages" do
74
+ expect(processor).to receive(:process_message).with(message, LaunchDarkly::DELETE)
75
+ end
76
+ xit "will process errors" do
77
+ expect(processor).to receive(:set_disconnected)
78
+ end
79
+ end
80
+
81
+ describe '#process_message' do
82
+ let(:put_message) { '{"key": {"value": "asdf"}}' }
83
+ let(:patch_message) { '{"path": "akey", "data": {"value": "asdf", "version": 1}}' }
84
+ let(:delete_message) { '{"path": "akey", "version": 2}' }
85
+ it "will accept PUT methods" do
86
+ processor.send(:process_message, put_message, LaunchDarkly::PUT)
87
+ expect(processor.instance_variable_get(:@store).get("key")).to eq(value: "asdf")
88
+ end
89
+ it "will accept PATCH methods" do
90
+ processor.send(:process_message, patch_message, LaunchDarkly::PATCH)
91
+ expect(processor.instance_variable_get(:@store).get("key")).to eq(value: "asdf", version: 1)
92
+ end
93
+ it "will accept DELETE methods" do
94
+ processor.send(:process_message, patch_message, LaunchDarkly::PATCH)
95
+ processor.send(:process_message, delete_message, LaunchDarkly::DELETE)
96
+ expect(processor.instance_variable_get(:@store).get("key")).to eq(nil)
97
+ end
98
+ it "will log an error if the method is not recognized" do
99
+ expect(processor.instance_variable_get(:@config).logger).to receive :error
100
+ processor.send(:process_message, put_message, "get")
101
+ end
102
+ end
103
+
104
+ describe '#should_fallback_update' do
105
+ it "will return true if the stream is disconnected for more than 120 seconds" do
106
+ processor.send(:set_disconnected)
107
+ future_time = Time.now + 200
108
+ expect(Time).to receive(:now).and_return(future_time)
109
+ value = processor.send(:should_fallback_update)
110
+ expect(value).to eq true
111
+ end
112
+ it "will return false otherwise" do
113
+ processor.send(:set_connected)
114
+ value = processor.send(:should_fallback_update)
115
+ expect(value).to eq false
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,7 @@
1
+ require "spec_helper"
2
+
3
+ describe LaunchDarkly do
4
+ it "has a version" do
5
+ expect(LaunchDarkly::VERSION).to be
6
+ end
7
+ end
metadata CHANGED
@@ -1,153 +1,181 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ldclient-rb
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
  - LaunchDarkly
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-25 00:00:00.000000000 Z
11
+ date: 2016-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.7'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.7'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
33
  version: '10.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '3.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '3.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: codeclimate-test-reporter
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
41
69
  - !ruby/object:Gem::Dependency
42
70
  name: json
43
71
  requirement: !ruby/object:Gem::Requirement
44
72
  requirements:
45
- - - "~>"
73
+ - - ~>
46
74
  - !ruby/object:Gem::Version
47
75
  version: '1.8'
48
76
  type: :runtime
49
77
  prerelease: false
50
78
  version_requirements: !ruby/object:Gem::Requirement
51
79
  requirements:
52
- - - "~>"
80
+ - - ~>
53
81
  - !ruby/object:Gem::Version
54
82
  version: '1.8'
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: faraday
57
85
  requirement: !ruby/object:Gem::Requirement
58
86
  requirements:
59
- - - "~>"
87
+ - - ~>
60
88
  - !ruby/object:Gem::Version
61
89
  version: '0.9'
62
90
  type: :runtime
63
91
  prerelease: false
64
92
  version_requirements: !ruby/object:Gem::Requirement
65
93
  requirements:
66
- - - "~>"
94
+ - - ~>
67
95
  - !ruby/object:Gem::Version
68
96
  version: '0.9'
69
97
  - !ruby/object:Gem::Dependency
70
98
  name: faraday-http-cache
71
99
  requirement: !ruby/object:Gem::Requirement
72
100
  requirements:
73
- - - "~>"
101
+ - - ~>
74
102
  - !ruby/object:Gem::Version
75
103
  version: '0.4'
76
104
  type: :runtime
77
105
  prerelease: false
78
106
  version_requirements: !ruby/object:Gem::Requirement
79
107
  requirements:
80
- - - "~>"
108
+ - - ~>
81
109
  - !ruby/object:Gem::Version
82
110
  version: '0.4'
83
111
  - !ruby/object:Gem::Dependency
84
112
  name: thread_safe
85
113
  requirement: !ruby/object:Gem::Requirement
86
114
  requirements:
87
- - - "~>"
115
+ - - ~>
88
116
  - !ruby/object:Gem::Version
89
117
  version: '0.3'
90
118
  type: :runtime
91
119
  prerelease: false
92
120
  version_requirements: !ruby/object:Gem::Requirement
93
121
  requirements:
94
- - - "~>"
122
+ - - ~>
95
123
  - !ruby/object:Gem::Version
96
124
  version: '0.3'
97
125
  - !ruby/object:Gem::Dependency
98
126
  name: net-http-persistent
99
127
  requirement: !ruby/object:Gem::Requirement
100
128
  requirements:
101
- - - "~>"
129
+ - - ~>
102
130
  - !ruby/object:Gem::Version
103
131
  version: '2.9'
104
132
  type: :runtime
105
133
  prerelease: false
106
134
  version_requirements: !ruby/object:Gem::Requirement
107
135
  requirements:
108
- - - "~>"
136
+ - - ~>
109
137
  - !ruby/object:Gem::Version
110
138
  version: '2.9'
111
139
  - !ruby/object:Gem::Dependency
112
140
  name: concurrent-ruby
113
141
  requirement: !ruby/object:Gem::Requirement
114
142
  requirements:
115
- - - "~>"
143
+ - - ~>
116
144
  - !ruby/object:Gem::Version
117
- version: '0.9'
145
+ version: 1.0.0
118
146
  type: :runtime
119
147
  prerelease: false
120
148
  version_requirements: !ruby/object:Gem::Requirement
121
149
  requirements:
122
- - - "~>"
150
+ - - ~>
123
151
  - !ruby/object:Gem::Version
124
- version: '0.9'
152
+ version: 1.0.0
125
153
  - !ruby/object:Gem::Dependency
126
154
  name: hashdiff
127
155
  requirement: !ruby/object:Gem::Requirement
128
156
  requirements:
129
- - - "~>"
157
+ - - ~>
130
158
  - !ruby/object:Gem::Version
131
159
  version: '0.2'
132
160
  type: :runtime
133
161
  prerelease: false
134
162
  version_requirements: !ruby/object:Gem::Requirement
135
163
  requirements:
136
- - - "~>"
164
+ - - ~>
137
165
  - !ruby/object:Gem::Version
138
166
  version: '0.2'
139
167
  - !ruby/object:Gem::Dependency
140
168
  name: ld-em-eventsource
141
169
  requirement: !ruby/object:Gem::Requirement
142
170
  requirements:
143
- - - "~>"
171
+ - - ~>
144
172
  - !ruby/object:Gem::Version
145
173
  version: '0.2'
146
174
  type: :runtime
147
175
  prerelease: false
148
176
  version_requirements: !ruby/object:Gem::Requirement
149
177
  requirements:
150
- - - "~>"
178
+ - - ~>
151
179
  - !ruby/object:Gem::Version
152
180
  version: '0.2'
153
181
  description: Official LaunchDarkly SDK for Ruby
@@ -157,11 +185,17 @@ executables: []
157
185
  extensions: []
158
186
  extra_rdoc_files: []
159
187
  files:
160
- - ".gitignore"
188
+ - .gitignore
189
+ - .hound.yml
190
+ - .rspec
191
+ - .rubocop.yml
192
+ - .simplecov
193
+ - CONTRIBUTING.md
161
194
  - Gemfile
162
195
  - LICENSE.txt
163
196
  - README.md
164
197
  - Rakefile
198
+ - circle.yml
165
199
  - ldclient-rb.gemspec
166
200
  - lib/ldclient-rb.rb
167
201
  - lib/ldclient-rb/config.rb
@@ -170,7 +204,16 @@ files:
170
204
  - lib/ldclient-rb/store.rb
171
205
  - lib/ldclient-rb/stream.rb
172
206
  - lib/ldclient-rb/version.rb
173
- homepage: https://rubygems.org/gems/ldclient-rb
207
+ - spec/config_spec.rb
208
+ - spec/fixtures/feature.json
209
+ - spec/fixtures/user.json
210
+ - spec/ldclient_spec.rb
211
+ - spec/newrelic_spec.rb
212
+ - spec/spec_helper.rb
213
+ - spec/store_spec.rb
214
+ - spec/stream_spec.rb
215
+ - spec/version_spec.rb
216
+ homepage: https://github.com/launchdarkly/ruby-client
174
217
  licenses:
175
218
  - Apache 2.0
176
219
  metadata: {}
@@ -180,19 +223,27 @@ require_paths:
180
223
  - lib
181
224
  required_ruby_version: !ruby/object:Gem::Requirement
182
225
  requirements:
183
- - - ">="
226
+ - - '>='
184
227
  - !ruby/object:Gem::Version
185
228
  version: '0'
186
229
  required_rubygems_version: !ruby/object:Gem::Requirement
187
230
  requirements:
188
- - - ">="
231
+ - - '>='
189
232
  - !ruby/object:Gem::Version
190
233
  version: '0'
191
234
  requirements: []
192
235
  rubyforge_project:
193
- rubygems_version: 2.2.2
236
+ rubygems_version: 2.5.0
194
237
  signing_key:
195
238
  specification_version: 4
196
239
  summary: LaunchDarkly SDK for Ruby
197
- test_files: []
198
- has_rdoc:
240
+ test_files:
241
+ - spec/config_spec.rb
242
+ - spec/fixtures/feature.json
243
+ - spec/fixtures/user.json
244
+ - spec/ldclient_spec.rb
245
+ - spec/newrelic_spec.rb
246
+ - spec/spec_helper.rb
247
+ - spec/store_spec.rb
248
+ - spec/stream_spec.rb
249
+ - spec/version_spec.rb