stoplight 3.0.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +176 -198
  3. data/lib/stoplight/builder.rb +68 -0
  4. data/lib/stoplight/circuit_breaker.rb +92 -0
  5. data/lib/stoplight/configurable.rb +95 -0
  6. data/lib/stoplight/configuration.rb +126 -0
  7. data/lib/stoplight/data_store/base.rb +9 -0
  8. data/lib/stoplight/data_store/memory.rb +46 -5
  9. data/lib/stoplight/data_store/redis.rb +75 -6
  10. data/lib/stoplight/default.rb +2 -0
  11. data/lib/stoplight/error.rb +1 -0
  12. data/lib/stoplight/light/deprecated.rb +44 -0
  13. data/lib/stoplight/light/lockable.rb +45 -0
  14. data/lib/stoplight/light/runnable.rb +34 -16
  15. data/lib/stoplight/light.rb +69 -63
  16. data/lib/stoplight/rspec/generic_notifier.rb +42 -0
  17. data/lib/stoplight/rspec.rb +3 -0
  18. data/lib/stoplight/version.rb +1 -1
  19. data/lib/stoplight.rb +33 -10
  20. data/spec/spec_helper.rb +7 -0
  21. data/spec/stoplight/builder_spec.rb +165 -0
  22. data/spec/stoplight/circuit_breaker_spec.rb +35 -0
  23. data/spec/stoplight/configurable_spec.rb +25 -0
  24. data/spec/stoplight/data_store/base_spec.rb +7 -0
  25. data/spec/stoplight/data_store/memory_spec.rb +12 -123
  26. data/spec/stoplight/data_store/redis_spec.rb +28 -129
  27. data/spec/stoplight/error_spec.rb +10 -0
  28. data/spec/stoplight/light/lockable_spec.rb +93 -0
  29. data/spec/stoplight/light/runnable_spec.rb +12 -233
  30. data/spec/stoplight/light_spec.rb +4 -28
  31. data/spec/stoplight/notifier/generic_spec.rb +35 -35
  32. data/spec/stoplight/notifier/io_spec.rb +1 -0
  33. data/spec/stoplight/notifier/logger_spec.rb +3 -0
  34. data/spec/stoplight_spec.rb +17 -6
  35. data/spec/support/configurable.rb +69 -0
  36. data/spec/support/data_store/base/clear_failures.rb +18 -0
  37. data/spec/support/data_store/base/clear_state.rb +20 -0
  38. data/spec/support/data_store/base/get_all.rb +44 -0
  39. data/spec/support/data_store/base/get_failures.rb +30 -0
  40. data/spec/support/data_store/base/get_state.rb +7 -0
  41. data/spec/support/data_store/base/names.rb +29 -0
  42. data/spec/support/data_store/base/record_failures.rb +70 -0
  43. data/spec/support/data_store/base/set_state.rb +15 -0
  44. data/spec/support/data_store/base/with_notification_lock.rb +27 -0
  45. data/spec/support/data_store/base.rb +21 -0
  46. data/spec/support/database_cleaner.rb +26 -0
  47. data/spec/support/exception_helpers.rb +9 -0
  48. data/spec/support/light/runnable/color.rb +79 -0
  49. data/spec/support/light/runnable/run.rb +247 -0
  50. data/spec/support/light/runnable.rb +4 -0
  51. metadata +56 -225
  52. data/lib/stoplight/notifier/bugsnag.rb +0 -37
  53. data/lib/stoplight/notifier/hip_chat.rb +0 -43
  54. data/lib/stoplight/notifier/honeybadger.rb +0 -44
  55. data/lib/stoplight/notifier/pagerduty.rb +0 -21
  56. data/lib/stoplight/notifier/raven.rb +0 -40
  57. data/lib/stoplight/notifier/rollbar.rb +0 -39
  58. data/lib/stoplight/notifier/slack.rb +0 -21
  59. data/spec/stoplight/notifier/bugsnag_spec.rb +0 -90
  60. data/spec/stoplight/notifier/hip_chat_spec.rb +0 -91
  61. data/spec/stoplight/notifier/honeybadger_spec.rb +0 -88
  62. data/spec/stoplight/notifier/pagerduty_spec.rb +0 -40
  63. data/spec/stoplight/notifier/raven_spec.rb +0 -90
  64. data/spec/stoplight/notifier/rollbar_spec.rb +0 -90
  65. data/spec/stoplight/notifier/slack_spec.rb +0 -46
@@ -1,43 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Stoplight
4
- module Notifier
5
- # @see Base
6
- class HipChat < Base
7
- DEFAULT_OPTIONS = {
8
- color: 'purple',
9
- message_format: 'text',
10
- notify: true
11
- }.freeze
12
-
13
- # @return [Proc]
14
- attr_reader :formatter
15
- # @return [::HipChat::Client]
16
- attr_reader :hip_chat
17
- # @return [Hash{Symbol => Object}]
18
- attr_reader :options
19
- # @return [String]
20
- attr_reader :room
21
-
22
- # @param hip_chat [::HipChat::Client]
23
- # @param room [String]
24
- # @param formatter [Proc, nil]
25
- # @param options [Hash{Symbol => Object}]
26
- # @option options [String] :color
27
- # @option options [String] :message_format
28
- # @option options [Boolean] :notify
29
- def initialize(hip_chat, room, formatter = nil, options = {})
30
- @hip_chat = hip_chat
31
- @room = room
32
- @formatter = formatter || Default::FORMATTER
33
- @options = DEFAULT_OPTIONS.merge(options)
34
- end
35
-
36
- def notify(light, from_color, to_color, error)
37
- message = formatter.call(light, from_color, to_color, error)
38
- hip_chat[room].send('Stoplight', message, options)
39
- message
40
- end
41
- end
42
- end
43
- end
@@ -1,44 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Stoplight
4
- module Notifier
5
- # @see Base
6
- class Honeybadger < Base
7
- DEFAULT_OPTIONS = {
8
- parameters: {},
9
- session: {},
10
- context: {}
11
- }.freeze
12
-
13
- # @return [String]
14
- attr_reader :api_key
15
- # @return [Proc]
16
- attr_reader :formatter
17
- # @return [Hash{Symbol => Object}]
18
- attr_reader :options
19
-
20
- # @param api_key [String]
21
- # @param formatter [Proc, nil]
22
- # @param options [Hash{Symbol => Object}]
23
- # @option options [Hash] :parameters
24
- # @option options [Hash] :session
25
- # @option options [Hash] :context
26
- def initialize(api_key, formatter = nil, options = {})
27
- @api_key = api_key
28
- @formatter = formatter || Default::FORMATTER
29
- @options = DEFAULT_OPTIONS.merge(options)
30
- end
31
-
32
- def notify(light, from_color, to_color, error)
33
- message = formatter.call(light, from_color, to_color, error)
34
- h = options.merge(
35
- api_key: api_key,
36
- error_message: message,
37
- backtrace: error&.backtrace
38
- )
39
- ::Honeybadger.notify(h)
40
- message
41
- end
42
- end
43
- end
44
- end
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Stoplight
4
- module Notifier
5
- # @see Base
6
- class Pagerduty < Base
7
- include Generic
8
-
9
- # @return [::Pagerduty]
10
- def pagerduty
11
- @object
12
- end
13
-
14
- private
15
-
16
- def put(message)
17
- pagerduty.trigger(message)
18
- end
19
- end
20
- end
21
- end
@@ -1,40 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Stoplight
4
- module Notifier
5
- # @see Base
6
- class Raven < Base
7
- DEFAULT_OPTIONS = {
8
- extra: {}
9
- }.freeze
10
-
11
- # @return [::Raven::Configuration]
12
- attr_reader :configuration
13
- # @return [Proc]
14
- attr_reader :formatter
15
- # @return [Hash{Symbol => Object}]
16
- attr_reader :options
17
-
18
- # @param api_key [String]
19
- # @param formatter [Proc, nil]
20
- # @param options [Hash{Symbol => Object}]
21
- # @option options [Hash] :extra
22
- def initialize(configuration, formatter = nil, options = {})
23
- @configuration = configuration
24
- @formatter = formatter || Default::FORMATTER
25
- @options = DEFAULT_OPTIONS.merge(options)
26
- end
27
-
28
- def notify(light, from_color, to_color, error)
29
- message = formatter.call(light, from_color, to_color, error)
30
-
31
- h = options.merge(
32
- configuration: configuration,
33
- backtrace: error&.backtrace
34
- )
35
- ::Raven.capture_message(message, h)
36
- message
37
- end
38
- end
39
- end
40
- end
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Stoplight
4
- module Notifier
5
- # @see Base
6
- class Rollbar < Base
7
- DEFAULT_OPTIONS = {
8
- severity: 'info'
9
- }.freeze
10
-
11
- StoplightStatusChange = Class.new(Error::Base)
12
-
13
- # @return [Proc]
14
- attr_reader :formatter
15
- # @return [::Rollbar]
16
- attr_reader :rollbar
17
- # @return [Hash{Symbol => Object}]
18
- attr_reader :options
19
-
20
- # @param rollbar [::Rollbar]
21
- # @param formatter [Proc, nil]
22
- # @param options [Hash{Symbol => Object}]
23
- # @option options [String] :severity
24
- def initialize(rollbar, formatter = nil, options = {})
25
- @rollbar = rollbar
26
- @formatter = formatter || Default::FORMATTER
27
- @options = DEFAULT_OPTIONS.merge(options)
28
- end
29
-
30
- def notify(light, from_color, to_color, error)
31
- formatter.call(light, from_color, to_color, error).tap do |message|
32
- severity = options.fetch(:severity)
33
- exception = StoplightStatusChange.new(message)
34
- rollbar.__send__(severity, exception)
35
- end
36
- end
37
- end
38
- end
39
- end
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Stoplight
4
- module Notifier
5
- # @see Base
6
- class Slack < Base
7
- include Generic
8
-
9
- # @return [::Slack::Notifier]
10
- def slack
11
- @object
12
- end
13
-
14
- private
15
-
16
- def put(message)
17
- slack.ping(message)
18
- end
19
- end
20
- end
21
- end
@@ -1,90 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- # require 'bugsnag'
6
- module Bugsnag
7
- end
8
-
9
- RSpec.describe Stoplight::Notifier::Bugsnag do
10
- it 'is a class' do
11
- expect(described_class).to be_a(Class)
12
- end
13
-
14
- it 'is a subclass of Base' do
15
- expect(described_class).to be < Stoplight::Notifier::Base
16
- end
17
-
18
- describe '#formatter' do
19
- it 'is initially the default' do
20
- expect(described_class.new(nil, nil).formatter)
21
- .to eql(Stoplight::Default::FORMATTER)
22
- end
23
-
24
- it 'reads the formatter' do
25
- formatter = proc {}
26
- expect(described_class.new(nil, formatter).formatter)
27
- .to eql(formatter)
28
- end
29
- end
30
-
31
- describe '#options' do
32
- it 'is initially the default' do
33
- expect(described_class.new(nil, nil).options)
34
- .to eql(Stoplight::Notifier::Bugsnag::DEFAULT_OPTIONS)
35
- end
36
-
37
- it 'reads the options' do
38
- options = { key: :value }
39
- expect(described_class.new(nil, nil, options).options)
40
- .to eql(Stoplight::Notifier::Bugsnag::DEFAULT_OPTIONS.merge(options))
41
- end
42
- end
43
-
44
- describe '#bugsnag' do
45
- it 'reads the Bugsnag client' do
46
- client = Bugsnag
47
- expect(described_class.new(client, nil).bugsnag)
48
- .to eql(client)
49
- end
50
- end
51
-
52
- describe '#notify' do
53
- let(:light) { Stoplight::Light.new(name, &code) }
54
- let(:name) { ('a'..'z').to_a.shuffle.join }
55
- let(:code) { -> {} }
56
- let(:from_color) { Stoplight::Color::GREEN }
57
- let(:to_color) { Stoplight::Color::RED }
58
- let(:notifier) { described_class.new(bugsnag) }
59
- let(:bugsnag) { Bugsnag }
60
-
61
- subject(:result) do
62
- notifier.notify(light, from_color, to_color, error)
63
- end
64
-
65
- before do
66
- status_change = described_class::StoplightStatusChange.new(message)
67
- expect(bugsnag).to receive(:notify).with(status_change, severity: 'info')
68
- end
69
-
70
- context 'when no error given' do
71
- let(:error) { nil }
72
-
73
- it 'logs message' do
74
- expect(result).to eq(message)
75
- end
76
- end
77
-
78
- context 'when message with an error given' do
79
- let(:error) { ZeroDivisionError.new('divided by 0') }
80
-
81
- it 'logs message' do
82
- expect(result).to eq(message)
83
- end
84
- end
85
-
86
- def message
87
- notifier.formatter.call(light, from_color, to_color, error)
88
- end
89
- end
90
- end
@@ -1,91 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- # require 'hipchat'
6
- module HipChat
7
- class Client
8
- def initialize(*); end
9
- end
10
- end
11
-
12
- RSpec.describe Stoplight::Notifier::HipChat do
13
- it 'is a class' do
14
- expect(described_class).to be_a(Class)
15
- end
16
-
17
- it 'is a subclass of Base' do
18
- expect(described_class).to be < Stoplight::Notifier::Base
19
- end
20
-
21
- describe '#formatter' do
22
- it 'is initially the default' do
23
- expect(described_class.new(nil, nil).formatter)
24
- .to eql(Stoplight::Default::FORMATTER)
25
- end
26
-
27
- it 'reads the formatter' do
28
- formatter = proc {}
29
- expect(described_class.new(nil, nil, formatter).formatter)
30
- .to eql(formatter)
31
- end
32
- end
33
-
34
- describe '#hip_chat' do
35
- it 'reads the HipChat client' do
36
- hip_chat = HipChat::Client.new('API token')
37
- expect(described_class.new(hip_chat, nil).hip_chat)
38
- .to eql(hip_chat)
39
- end
40
- end
41
-
42
- describe '#options' do
43
- it 'is initially the default' do
44
- expect(described_class.new(nil, nil).options)
45
- .to eql(Stoplight::Notifier::HipChat::DEFAULT_OPTIONS)
46
- end
47
-
48
- it 'reads the options' do
49
- options = { key: :value }
50
- expect(described_class.new(nil, nil, nil, options).options)
51
- .to eql(Stoplight::Notifier::HipChat::DEFAULT_OPTIONS.merge(options))
52
- end
53
- end
54
-
55
- describe '#room' do
56
- it 'reads the room' do
57
- room = 'Notifications'
58
- expect(described_class.new(nil, room).room).to eql(room)
59
- end
60
- end
61
-
62
- describe '#notify' do
63
- let(:light) { Stoplight::Light.new(name, &code) }
64
- let(:name) { ('a'..'z').to_a.shuffle.join }
65
- let(:code) { -> {} }
66
- let(:from_color) { Stoplight::Color::GREEN }
67
- let(:to_color) { Stoplight::Color::RED }
68
- let(:notifier) { described_class.new(hip_chat, room) }
69
- let(:hip_chat) { double(HipChat::Client) }
70
- let(:room) { ('a'..'z').to_a.shuffle.join }
71
-
72
- before do
73
- tmp = double
74
- expect(hip_chat).to receive(:[]).with(room).and_return(tmp)
75
- expect(tmp).to receive(:send)
76
- .with('Stoplight', kind_of(String), kind_of(Hash)).and_return(true)
77
- end
78
-
79
- it 'returns the message' do
80
- error = nil
81
- expect(notifier.notify(light, from_color, to_color, error))
82
- .to eql(notifier.formatter.call(light, from_color, to_color, error))
83
- end
84
-
85
- it 'returns the message with an error' do
86
- error = ZeroDivisionError.new('divided by 0')
87
- expect(notifier.notify(light, from_color, to_color, error))
88
- .to eql(notifier.formatter.call(light, from_color, to_color, error))
89
- end
90
- end
91
- end
@@ -1,88 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- # require 'honeybadger'
6
- module Honeybadger
7
- end
8
-
9
- RSpec.describe Stoplight::Notifier::Honeybadger do
10
- it 'is a class' do
11
- expect(described_class).to be_a(Class)
12
- end
13
-
14
- it 'is a subclass of Base' do
15
- expect(described_class).to be < Stoplight::Notifier::Base
16
- end
17
-
18
- describe '#formatter' do
19
- it 'is initially the default' do
20
- expect(described_class.new(nil).formatter).to eql(
21
- Stoplight::Default::FORMATTER
22
- )
23
- end
24
-
25
- it 'reads the formatter' do
26
- formatter = proc {}
27
- expect(described_class.new(nil, formatter).formatter).to eql(formatter)
28
- end
29
- end
30
-
31
- describe '#options' do
32
- it 'is initially the default' do
33
- expect(described_class.new(nil).options).to eql(
34
- Stoplight::Notifier::Honeybadger::DEFAULT_OPTIONS
35
- )
36
- end
37
-
38
- it 'reads the options' do
39
- options = { key: :value }
40
- expect(described_class.new(nil, nil, options).options).to eql(
41
- Stoplight::Notifier::Honeybadger::DEFAULT_OPTIONS.merge(options)
42
- )
43
- end
44
- end
45
-
46
- describe '#notify' do
47
- let(:light) { Stoplight::Light.new(name, &code) }
48
- let(:name) { ('a'..'z').to_a.shuffle.join }
49
- let(:code) { -> {} }
50
- let(:from_color) { Stoplight::Color::GREEN }
51
- let(:to_color) { Stoplight::Color::RED }
52
- let(:notifier) { described_class.new(api_key) }
53
- let(:api_key) { ('a'..'z').to_a.shuffle.join }
54
-
55
- before do
56
- allow(Honeybadger).to receive(:notify)
57
- end
58
-
59
- it 'returns the message' do
60
- error = nil
61
- message = notifier.formatter.call(light, from_color, to_color, error)
62
- expect(notifier.notify(light, from_color, to_color, error)).to eql(
63
- message
64
- )
65
- expect(Honeybadger).to have_received(:notify).with(
66
- hash_including(
67
- api_key: api_key,
68
- error_message: message
69
- )
70
- )
71
- end
72
-
73
- it 'returns the message with an error' do
74
- error = ZeroDivisionError.new('divided by 0')
75
- message = notifier.formatter.call(light, from_color, to_color, error)
76
- expect(notifier.notify(light, from_color, to_color, error)).to eql(
77
- message
78
- )
79
- expect(Honeybadger).to have_received(:notify).with(
80
- hash_including(
81
- api_key: api_key,
82
- error_message: message,
83
- backtrace: error.backtrace
84
- )
85
- )
86
- end
87
- end
88
- end
@@ -1,40 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
- require 'pagerduty'
5
-
6
- RSpec.describe Stoplight::Notifier::Pagerduty do
7
- it_behaves_like 'a generic notifier'
8
-
9
- it 'is a class' do
10
- expect(described_class).to be_a(Class)
11
- end
12
-
13
- it 'is a subclass of Base' do
14
- expect(described_class).to be < Stoplight::Notifier::Base
15
- end
16
-
17
- describe '#pagerduty' do
18
- it 'reads Pagerduty client' do
19
- pagerduty = Pagerduty.new('WEBHOOK_URL')
20
- expect(described_class.new(pagerduty).pagerduty).to eql(pagerduty)
21
- end
22
- end
23
-
24
- describe '#notify' do
25
- let(:light) { Stoplight::Light.new(name, &code) }
26
- let(:name) { ('a'..'z').to_a.shuffle.join }
27
- let(:code) { -> {} }
28
- let(:from_color) { Stoplight::Color::GREEN }
29
- let(:to_color) { Stoplight::Color::RED }
30
- let(:notifier) { described_class.new(pagerduty) }
31
- let(:pagerduty) { double(Pagerduty).as_null_object }
32
-
33
- it 'pings Pagerduty' do
34
- error = nil
35
- message = notifier.formatter.call(light, from_color, to_color, error)
36
- expect(pagerduty).to receive(:trigger).with(message)
37
- notifier.notify(light, from_color, to_color, error)
38
- end
39
- end
40
- end
@@ -1,90 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- # require 'sentry-raven'
6
- module Raven
7
- class Configuration
8
- end
9
- end
10
-
11
- RSpec.describe Stoplight::Notifier::Raven do
12
- it 'is a class' do
13
- expect(described_class).to be_a(Class)
14
- end
15
-
16
- it 'is a subclass of Base' do
17
- expect(described_class).to be < Stoplight::Notifier::Base
18
- end
19
-
20
- describe '#formatter' do
21
- it 'is initially the default' do
22
- expect(described_class.new(nil).formatter).to eql(
23
- Stoplight::Default::FORMATTER
24
- )
25
- end
26
-
27
- it 'reads the formatter' do
28
- formatter = proc {}
29
- expect(described_class.new(nil, formatter).formatter).to eql(formatter)
30
- end
31
- end
32
-
33
- describe '#options' do
34
- it 'is initially the default' do
35
- expect(described_class.new(nil).options).to eql(
36
- Stoplight::Notifier::Raven::DEFAULT_OPTIONS
37
- )
38
- end
39
-
40
- it 'reads the options' do
41
- options = { key: :value }
42
- expect(described_class.new(nil, nil, options).options).to eql(
43
- Stoplight::Notifier::Raven::DEFAULT_OPTIONS.merge(options)
44
- )
45
- end
46
- end
47
-
48
- describe '#notify' do
49
- let(:light) { Stoplight::Light.new(name, &code) }
50
- let(:name) { ('a'..'z').to_a.shuffle.join }
51
- let(:code) { -> {} }
52
- let(:from_color) { Stoplight::Color::GREEN }
53
- let(:to_color) { Stoplight::Color::RED }
54
- let(:notifier) { described_class.new(configuration) }
55
- let(:configuration) { instance_double(::Raven::Configuration) }
56
-
57
- before do
58
- allow(::Raven).to receive(:capture_message)
59
- end
60
-
61
- it 'returns the message' do
62
- error = nil
63
- message = notifier.formatter.call(light, from_color, to_color, error)
64
- expect(notifier.notify(light, from_color, to_color, error)).to eql(
65
- message
66
- )
67
- expect(::Raven).to have_received(:capture_message).with(
68
- message,
69
- hash_including(
70
- configuration: configuration
71
- )
72
- )
73
- end
74
-
75
- it 'returns the message with an error' do
76
- error = ZeroDivisionError.new('divided by 0')
77
- message = notifier.formatter.call(light, from_color, to_color, error)
78
- expect(notifier.notify(light, from_color, to_color, error)).to eql(
79
- message
80
- )
81
- expect(::Raven).to have_received(:capture_message).with(
82
- message,
83
- hash_including(
84
- configuration: configuration,
85
- backtrace: error.backtrace
86
- )
87
- )
88
- end
89
- end
90
- end
@@ -1,90 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- # require 'rollbar'
6
- module Rollbar
7
- end
8
-
9
- RSpec.describe Stoplight::Notifier::Rollbar do
10
- it 'is a class' do
11
- expect(described_class).to be_a(Class)
12
- end
13
-
14
- it 'is a subclass of Base' do
15
- expect(described_class).to be < Stoplight::Notifier::Base
16
- end
17
-
18
- describe '#formatter' do
19
- it 'is initially the default' do
20
- expect(described_class.new(nil, nil).formatter)
21
- .to eql(Stoplight::Default::FORMATTER)
22
- end
23
-
24
- it 'reads the formatter' do
25
- formatter = proc {}
26
- expect(described_class.new(nil, formatter).formatter)
27
- .to eql(formatter)
28
- end
29
- end
30
-
31
- describe '#options' do
32
- it 'is initially the default' do
33
- expect(described_class.new(nil, nil).options)
34
- .to eql(Stoplight::Notifier::Rollbar::DEFAULT_OPTIONS)
35
- end
36
-
37
- it 'reads the options' do
38
- options = { key: :value }
39
- expect(described_class.new(nil, nil, options).options)
40
- .to eql(Stoplight::Notifier::Rollbar::DEFAULT_OPTIONS.merge(options))
41
- end
42
- end
43
-
44
- describe '#rollbar' do
45
- it 'reads the Rollbar client' do
46
- client = Rollbar
47
- expect(described_class.new(client, nil).rollbar)
48
- .to eql(client)
49
- end
50
- end
51
-
52
- describe '#notify' do
53
- let(:light) { Stoplight::Light.new(name, &code) }
54
- let(:name) { ('a'..'z').to_a.shuffle.join }
55
- let(:code) { -> {} }
56
- let(:from_color) { Stoplight::Color::GREEN }
57
- let(:to_color) { Stoplight::Color::RED }
58
- let(:notifier) { described_class.new(rollbar) }
59
- let(:rollbar) { Rollbar }
60
-
61
- subject(:result) do
62
- notifier.notify(light, from_color, to_color, error)
63
- end
64
-
65
- before do
66
- status_change = described_class::StoplightStatusChange.new(message)
67
- expect(rollbar).to receive(:info).with(status_change)
68
- end
69
-
70
- context 'when no error given' do
71
- let(:error) { nil }
72
-
73
- it 'logs message' do
74
- expect(result).to eq(message)
75
- end
76
- end
77
-
78
- context 'when message with an error given' do
79
- let(:error) { ZeroDivisionError.new('divided by 0') }
80
-
81
- it 'logs message' do
82
- expect(result).to eq(message)
83
- end
84
- end
85
-
86
- def message
87
- notifier.formatter.call(light, from_color, to_color, error)
88
- end
89
- end
90
- end