stoplight 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,9 +3,10 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe Stoplight::Notifier::HipChat do
6
- subject(:notifier) { described_class.new(client, room, options) }
6
+ subject(:notifier) { described_class.new(client, room, format, options) }
7
7
  let(:client) { double }
8
8
  let(:room) { SecureRandom.hex }
9
+ let(:format) { nil }
9
10
  let(:options) { {} }
10
11
 
11
12
  describe '#notify' do
@@ -15,7 +16,19 @@ describe Stoplight::Notifier::HipChat do
15
16
  it 'sends the message to HipChat' do
16
17
  expect(client).to receive(:[]).with(room).and_return(client)
17
18
  expect(client).to receive(:send)
19
+ .with('Stoplight', "@all #{message}", anything)
18
20
  result
19
21
  end
22
+
23
+ context 'with a format' do
24
+ let(:format) { '> %s <' }
25
+
26
+ it 'formats the message' do
27
+ expect(client).to receive(:[]).with(room).and_return(client)
28
+ expect(client).to receive(:send)
29
+ .with('Stoplight', "> #{message} <", anything)
30
+ result
31
+ end
32
+ end
20
33
  end
21
34
  end
@@ -3,16 +3,28 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe Stoplight::Notifier::StandardError do
6
- subject(:notifier) { described_class.new }
6
+ subject(:notifier) { described_class.new(format) }
7
+ let(:format) { nil }
7
8
 
8
- describe '#notify' do
9
- let(:message) { SecureRandom.hex }
9
+ before { @stderr, $stderr = $stderr, StringIO.new }
10
+ after { $stderr = @stderr }
10
11
 
12
+ describe '#notify' do
11
13
  subject(:result) { notifier.notify(message) }
14
+ let(:message) { SecureRandom.hex }
12
15
 
13
16
  it 'emits the message as a warning' do
14
- expect(notifier).to receive(:warn).with(message)
15
17
  result
18
+ expect($stderr.string).to eql("#{message}\n")
19
+ end
20
+
21
+ context 'with a format' do
22
+ let(:format) { '> %s <' }
23
+
24
+ it 'formats the message' do
25
+ result
26
+ expect($stderr.string).to eql("> #{message} <\n")
27
+ end
16
28
  end
17
29
  end
18
30
  end
@@ -5,12 +5,6 @@ require 'spec_helper'
5
5
  describe Stoplight do
6
6
  let(:name) { SecureRandom.hex }
7
7
 
8
- it 'forwards all data store methods' do
9
- (Stoplight::DataStore::Base.new.methods - Object.methods).each do |method|
10
- expect(Stoplight).to respond_to(method)
11
- end
12
- end
13
-
14
8
  describe '::VERSION' do
15
9
  subject(:result) { described_class.const_get(:VERSION) }
16
10
 
@@ -75,84 +69,4 @@ describe Stoplight do
75
69
  end
76
70
  end
77
71
  end
78
-
79
- describe '.green?' do
80
- subject(:result) { described_class.green?(name) }
81
-
82
- it 'is true' do
83
- expect(result).to be true
84
- end
85
-
86
- context 'locked green' do
87
- before do
88
- described_class.set_state(
89
- name, Stoplight::DataStore::STATE_LOCKED_GREEN)
90
- end
91
-
92
- it 'is true' do
93
- expect(result).to be true
94
- end
95
- end
96
-
97
- context 'locked red' do
98
- before do
99
- described_class.set_state(
100
- name, Stoplight::DataStore::STATE_LOCKED_RED)
101
- end
102
-
103
- it 'is false' do
104
- expect(result).to be false
105
- end
106
- end
107
-
108
- context 'with failures' do
109
- before do
110
- described_class.threshold(name).times do
111
- described_class.record_failure(name, nil)
112
- end
113
- end
114
-
115
- it 'is false' do
116
- expect(result).to be false
117
- end
118
- end
119
- end
120
-
121
- describe '.red?' do
122
- subject(:result) { described_class.red?(name) }
123
-
124
- context 'green' do
125
- before { allow(described_class).to receive(:green?).and_return(true) }
126
-
127
- it 'is false' do
128
- expect(result).to be false
129
- end
130
- end
131
-
132
- context 'not green' do
133
- before { allow(described_class).to receive(:green?).and_return(false) }
134
-
135
- it 'is true' do
136
- expect(result).to be true
137
- end
138
- end
139
- end
140
-
141
- describe '.threshold' do
142
- subject(:result) { described_class.threshold(name) }
143
-
144
- it 'uses the default threshold' do
145
- expect(result).to eql(Stoplight::DEFAULT_THRESHOLD)
146
- end
147
-
148
- context 'with a custom threshold' do
149
- let(:threshold) { rand(10) }
150
-
151
- before { described_class.set_threshold(name, threshold) }
152
-
153
- it 'uses the threshold' do
154
- expect(result).to eql(threshold)
155
- end
156
- end
157
- end
158
72
  end
@@ -1,178 +1,44 @@
1
1
  # coding: utf-8
2
+ # rubocop:disable Metrics/LineLength
2
3
 
3
4
  shared_examples_for 'a data store' do
5
+ let(:name) { SecureRandom.hex }
6
+ let(:failure) { Stoplight::Failure.new(error, time) }
4
7
  let(:error) { error_class.new }
5
8
  let(:error_class) { Class.new(StandardError) }
6
- let(:name) { SecureRandom.hex }
9
+ let(:time) { Time.now }
7
10
  let(:state) { Stoplight::DataStore::STATES.to_a.sample }
8
- let(:threshold) { rand(10) }
9
-
10
- it 'is a DataStore::Base' do
11
- expect(data_store).to be_a(Stoplight::DataStore::Base)
12
- end
13
-
14
- describe '#names' do
15
- subject(:result) { data_store.names }
16
-
17
- it 'returns an array' do
18
- expect(result).to be_an(Array)
19
- end
20
-
21
- context 'with a name' do
22
- before do
23
- @data_store = Stoplight.data_store
24
- Stoplight.data_store = data_store
25
- Stoplight::Light.new(name) {}.run
26
- end
27
- after { Stoplight.data_store = @data_store }
28
-
29
- it 'includes the name' do
30
- expect(result).to include(name)
31
- end
32
- end
33
- end
34
-
35
- context 'attempts' do
36
- describe '#attempts' do
37
- subject(:result) { data_store.attempts(name) }
38
-
39
- it 'returns an integer' do
40
- expect(result).to be_an(Integer)
41
- end
42
-
43
- context 'with an attempt' do
44
- it 'includes the attempt' do
45
- attempts = data_store.attempts(name)
46
- data_store.record_attempt(name)
47
- expect(result).to be > attempts
48
- end
49
- end
50
- end
51
-
52
- describe '#clear_attempts' do
53
- subject(:result) { data_store.clear_attempts(name) }
54
-
55
- context 'with an attempt' do
56
- before { data_store.record_attempt(name) }
57
-
58
- it 'clears the attempts' do
59
- result
60
- expect(data_store.attempts(name)).to eql(0)
61
- end
62
- end
63
- end
64
-
65
- describe '#record_attempt' do
66
- subject(:result) { data_store.record_attempt(name) }
67
-
68
- it 'records the attempt' do
69
- attempts = data_store.attempts(name)
70
- result
71
- expect(data_store.attempts(name)).to eql(attempts + 1)
72
- end
73
- end
74
- end
75
-
76
- context 'failures' do
77
- describe '#clear_failures' do
78
- subject(:result) { data_store.clear_failures(name) }
79
-
80
- context 'with a failure' do
81
- before { data_store.record_failure(name, error) }
82
-
83
- it 'clears the failures' do
84
- result
85
- expect(data_store.failures(name)).to be_empty
86
- end
87
- end
88
- end
89
-
90
- describe '#failures' do
91
- subject(:result) { data_store.failures(name) }
92
-
93
- it 'returns an array' do
94
- expect(result).to be_an(Array)
95
- end
96
-
97
- context 'with a failure' do
98
- it 'includes the failure' do
99
- failures = data_store.failures(name)
100
- data_store.record_failure(name, error)
101
- expect(result.size).to be > failures.size
102
- end
103
- end
104
- end
105
-
106
- describe '#record_failure' do
107
- subject(:result) { data_store.record_failure(name, error) }
108
-
109
- it 'records the failure' do
110
- failures = data_store.failures(name)
111
- result
112
- expect(data_store.failures(name).size).to eql(failures.size + 1)
113
- end
114
- end
115
- end
116
-
117
- context 'state' do
118
- describe '#set_state' do
119
- subject(:result) { data_store.set_state(name, state) }
120
-
121
- it 'returns the state' do
122
- expect(result).to eql(state)
123
- end
124
-
125
- it 'sets the state' do
126
- result
127
- expect(data_store.state(name)).to eql(state)
128
- end
129
- end
130
-
131
- describe '#state' do
132
- subject(:result) { data_store.state(name) }
133
-
134
- it 'returns the default state' do
135
- expect(result).to eql(Stoplight::DataStore::STATE_UNLOCKED)
136
- end
137
-
138
- context 'with a state' do
139
- before { data_store.set_state(name, state) }
140
-
141
- it 'returns the state' do
142
- expect(result).to eql(state)
143
- end
144
- end
145
- end
146
- end
147
-
148
- context 'threshold' do
149
- describe '#set_threshold' do
150
- subject(:result) { data_store.set_threshold(name, threshold) }
151
-
152
- it 'returns the threshold' do
153
- expect(result).to eql(threshold)
154
- end
155
-
156
- it 'sets the threshold' do
157
- result
158
- expect(data_store.threshold(name)).to eql(threshold)
159
- end
160
- end
161
-
162
- describe '#threshold' do
163
- subject(:result) { data_store.threshold(name) }
164
-
165
- it 'returns nil' do
166
- expect(result).to eql(nil)
167
- end
168
-
169
- context 'with a threshold' do
170
- before { data_store.set_threshold(name, threshold) }
171
-
172
- it 'returns the threshold' do
173
- expect(result).to eql(threshold)
174
- end
175
- end
176
- end
11
+ let(:threshold) { rand(100) }
12
+ let(:timeout) { rand(100) }
13
+
14
+ it { expect(data_store.names).to eql([]) }
15
+ it { expect(data_store.clear_stale).to eql(nil) }
16
+ it { expect(data_store.clear(name)).to eql(nil) }
17
+ it { expect(data_store.sync(name)).to eql(nil) }
18
+ it { expect(data_store.get_color(name)).to eql(Stoplight::DataStore::COLOR_GREEN) }
19
+ it { expect(data_store.green?(name)).to eql(true) }
20
+ it { expect(data_store.yellow?(name)).to eql(false) }
21
+ it { expect(data_store.red?(name)).to eql(false) }
22
+ it { expect(data_store.get_attempts(name)).to eql(Stoplight::DataStore::DEFAULT_ATTEMPTS) }
23
+ it { expect(data_store.record_attempt(name)).to eql(1) }
24
+ it { expect(data_store.clear_attempts(name)).to eql(nil) }
25
+ it { expect(data_store.get_failures(name)).to eql(Stoplight::DataStore::DEFAULT_FAILURES) }
26
+ it { expect(data_store.record_failure(name, failure)).to eql(failure) }
27
+ it { expect(data_store.clear_failures(name)).to eql(nil) }
28
+ it { expect(data_store.get_state(name)).to eql(Stoplight::DataStore::DEFAULT_STATE) }
29
+ it { expect(data_store.set_state(name, state)).to eql(state) }
30
+ it { expect(data_store.clear_state(name)).to eql(nil) }
31
+ it { expect(data_store.get_threshold(name)).to eql(Stoplight::DataStore::DEFAULT_THRESHOLD) }
32
+ it { expect(data_store.set_threshold(name, threshold)).to eql(threshold) }
33
+ it { expect(data_store.clear_threshold(name)).to eql(nil) }
34
+ it { expect(data_store.get_timeout(name)).to eql(Stoplight::DataStore::DEFAULT_TIMEOUT) }
35
+ it { expect(data_store.set_timeout(name, timeout)).to eql(timeout) }
36
+ it { expect(data_store.clear_timeout(name)).to eql(nil) }
37
+
38
+ it 'clears stale lights' do
39
+ data_store.sync(name)
40
+ expect(data_store.names).to include(name)
41
+ data_store.clear_stale
42
+ expect(data_store.names).to_not include(name)
177
43
  end
178
44
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stoplight
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cameron Desautels
@@ -9,8 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-08-20 00:00:00.000000000 Z
12
+ date: 2014-09-11 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: benchmark-ips
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: 2.0.0
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: 2.0.0
14
28
  - !ruby/object:Gem::Dependency
15
29
  name: coveralls
16
30
  requirement: !ruby/object:Gem::Requirement
@@ -59,28 +73,28 @@ dependencies:
59
73
  requirements:
60
74
  - - ~>
61
75
  - !ruby/object:Gem::Version
62
- version: 3.0.0
76
+ version: 3.1.0
63
77
  type: :development
64
78
  prerelease: false
65
79
  version_requirements: !ruby/object:Gem::Requirement
66
80
  requirements:
67
81
  - - ~>
68
82
  - !ruby/object:Gem::Version
69
- version: 3.0.0
83
+ version: 3.1.0
70
84
  - !ruby/object:Gem::Dependency
71
85
  name: rubocop
72
86
  requirement: !ruby/object:Gem::Requirement
73
87
  requirements:
74
88
  - - ~>
75
89
  - !ruby/object:Gem::Version
76
- version: 0.25.0
90
+ version: 0.26.0
77
91
  type: :development
78
92
  prerelease: false
79
93
  version_requirements: !ruby/object:Gem::Requirement
80
94
  requirements:
81
95
  - - ~>
82
96
  - !ruby/object:Gem::Version
83
- version: 0.25.0
97
+ version: 0.26.0
84
98
  - !ruby/object:Gem::Dependency
85
99
  name: yard
86
100
  requirement: !ruby/object:Gem::Requirement
@@ -103,23 +117,27 @@ executables: []
103
117
  extensions: []
104
118
  extra_rdoc_files: []
105
119
  files:
120
+ - CHANGELOG.md
121
+ - LICENSE.md
122
+ - README.md
123
+ - lib/stoplight.rb
124
+ - lib/stoplight/data_store.rb
106
125
  - lib/stoplight/data_store/base.rb
107
126
  - lib/stoplight/data_store/memory.rb
108
127
  - lib/stoplight/data_store/redis.rb
109
- - lib/stoplight/data_store.rb
110
128
  - lib/stoplight/error.rb
111
129
  - lib/stoplight/failure.rb
112
130
  - lib/stoplight/light.rb
113
131
  - lib/stoplight/mixin.rb
132
+ - lib/stoplight/notifier.rb
114
133
  - lib/stoplight/notifier/base.rb
115
134
  - lib/stoplight/notifier/hip_chat.rb
116
135
  - lib/stoplight/notifier/standard_error.rb
117
- - lib/stoplight/notifier.rb
118
- - lib/stoplight.rb
119
136
  - spec/spec_helper.rb
120
137
  - spec/stoplight/data_store/base_spec.rb
121
138
  - spec/stoplight/data_store/memory_spec.rb
122
139
  - spec/stoplight/data_store/redis_spec.rb
140
+ - spec/stoplight/data_store_spec.rb
123
141
  - spec/stoplight/failure_spec.rb
124
142
  - spec/stoplight/light_spec.rb
125
143
  - spec/stoplight/mixin_spec.rb
@@ -129,9 +147,6 @@ files:
129
147
  - spec/stoplight/notifier_spec.rb
130
148
  - spec/stoplight_spec.rb
131
149
  - spec/support/data_store.rb
132
- - CHANGELOG.md
133
- - LICENSE.md
134
- - README.md
135
150
  homepage: https://github.com/orgsync/stoplight
136
151
  licenses:
137
152
  - MIT
@@ -152,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
152
167
  version: '0'
153
168
  requirements: []
154
169
  rubyforge_project:
155
- rubygems_version: 2.0.14
170
+ rubygems_version: 2.4.1
156
171
  signing_key:
157
172
  specification_version: 4
158
173
  summary: Traffic control for code.
@@ -161,6 +176,7 @@ test_files:
161
176
  - spec/stoplight/data_store/base_spec.rb
162
177
  - spec/stoplight/data_store/memory_spec.rb
163
178
  - spec/stoplight/data_store/redis_spec.rb
179
+ - spec/stoplight/data_store_spec.rb
164
180
  - spec/stoplight/failure_spec.rb
165
181
  - spec/stoplight/light_spec.rb
166
182
  - spec/stoplight/mixin_spec.rb