ampel_extase 0.5.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ae725820fd3303481216d55d24f2469dbc2f71a2
4
- data.tar.gz: e707f917125e83cb174c96a19db891dde8fce21b
3
+ metadata.gz: 98397c6d3db5a5951ba8eb4b6eadb6a78babbeac
4
+ data.tar.gz: 366beb6df5bf0b866f4c92888d7587d4204320f0
5
5
  SHA512:
6
- metadata.gz: 670dc15299ed7b16b420a33678acf4bece81fff5fbf24de671d0669e43184bf476a66d49d030f59015e822f88f6c31506a4933750dc996760ce6d91c71e5347e
7
- data.tar.gz: 533e98f06fbbc95dc602c88f6607d17a47243e1e97cabcdd8c3f29a0950bb25a83bdc245578e3f92a59c6f01f6bd2afe1260e4333586fa6e22d2d68a33064a05
6
+ metadata.gz: b5db8988d151209942500312d96381605cd6d079627f4fdeef70620f9d70f02a25652c9381db8f0ab5357a739a25c8c50a89421c2119bc2966b91d1d79ea83ea
7
+ data.tar.gz: 2e8f4244d62306c792f683356773846e5aabc1e76fcf027f8e16f5006d83341f6ac935d909f76cbcb88dd6dfe754da97ecb5e1f028b4b2defdf05da920305cb5
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.0
1
+ 0.5.1
@@ -1,14 +1,14 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: ampel_extase 0.5.0 ruby lib
2
+ # stub: ampel_extase 0.5.1 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "ampel_extase"
6
- s.version = "0.5.0"
6
+ s.version = "0.5.1"
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib"]
10
10
  s.authors = ["Florian Frank"]
11
- s.date = "2015-08-27"
11
+ s.date = "2015-08-31"
12
12
  s.description = "Library to control the build traffic light. Yes, we can\u{2026}"
13
13
  s.email = "flori@ping.de"
14
14
  s.executables = ["ampel_control"]
@@ -41,6 +41,8 @@ class AmpelExtase::JenkinsStateObserver
41
41
  self
42
42
  end
43
43
 
44
+ attr_reader :state_changed_at
45
+
44
46
  def fetch_new_state
45
47
  AmpelExtase::BuildState.for [ last_result, building? ]
46
48
  end
@@ -21,7 +21,6 @@ class AmpelExtase::JenkinsWarningStateObserver
21
21
 
22
22
  def on_state_change(duration, &block)
23
23
  @observers.each do |observer|
24
- observer.expired?(duration) and next
25
24
  observer.on_state_change do |state|
26
25
  if %w[ FAILURE ABORTED ].include?(state.last_result)
27
26
  block.(state)
@@ -32,7 +31,11 @@ class AmpelExtase::JenkinsWarningStateObserver
32
31
  self
33
32
  end
34
33
 
34
+ def last_state_change
35
+ @observers.map(&:state_changed_at).max
36
+ end
37
+
35
38
  def expired?(duration)
36
- @observers.all? { |observer| observer.expired?(duration) }
39
+ Time.now - last_state_change > duration
37
40
  end
38
41
  end
@@ -1,6 +1,6 @@
1
1
  module AmpelExtase
2
2
  # AmpelExtase version
3
- VERSION = '0.5.0'
3
+ VERSION = '0.5.1'
4
4
  VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
@@ -80,7 +80,7 @@ describe AmpelExtase::JenkinsStateObserver do
80
80
  jso
81
81
  end
82
82
  expect(jso.instance_variable_get(:@build_state)).to eq bs_initial
83
- expect(jso.instance_variable_get(:@state_changed_at)).to eq past
83
+ expect(jso.state_changed_at).to eq past
84
84
  allow(client).to receive(:fetch_build).with(:last_completed_build).
85
85
  and_return('result' => 'SUCCESS')
86
86
  allow(client).to receive(:fetch_build).with(:last_build).
@@ -97,7 +97,7 @@ describe AmpelExtase::JenkinsStateObserver do
97
97
  }.to yield_with_args(bs_success)
98
98
  end
99
99
  expect(jso.instance_variable_get(:@build_state)).to eq bs_success
100
- expect(jso.instance_variable_get(:@state_changed_at)).to eq now
100
+ expect(jso.state_changed_at).to eq now
101
101
  allow(client).to receive(:fetch_build).with(:last_completed_build).
102
102
  and_return('result' => 'FAILURE')
103
103
  allow(client).to receive(:fetch_build).with(:last_build).
@@ -5,8 +5,18 @@ describe AmpelExtase::JenkinsWarningStateObserver do
5
5
  described_class.new [ observer ]
6
6
  end
7
7
 
8
+ let :client do
9
+ double('AmpelExtase::JenkinsClient', url: 'http://foo/bar')
10
+ end
11
+
8
12
  let :observer do
9
- double('AmpelExtase::JenkinsStateObserver')
13
+ AmpelExtase::JenkinsStateObserver.new client
14
+ end
15
+
16
+ before do
17
+ allow(client).to receive(:fetch).and_return true
18
+ allow_any_instance_of(AmpelExtase::JenkinsStateObserver).to receive(:puts)
19
+ allow_any_instance_of(AmpelExtase::JenkinsClient).to receive(:puts)
10
20
  end
11
21
 
12
22
  describe '.for_urls' do
@@ -37,23 +47,34 @@ describe AmpelExtase::JenkinsWarningStateObserver do
37
47
  AmpelExtase::BuildState.for [ 'FAILURE', true ]
38
48
  end
39
49
 
40
- it 'skips observers that are already expired b4 duration' do
41
- expect(observer).to receive(:expired?).with(666).and_return true
42
- expect(observer).not_to receive(:on_state_change)
50
+ it 'delegates on_state_change to observers' do
51
+ expect(observer).to receive(:on_state_change)
43
52
  jenkins_warning_state_observer.on_state_change(666)
44
53
  end
45
54
 
55
+ it 'executes state change action on FAILURE/ABORTED result' do
56
+ allow(observer).to receive(:fetch_new_state).and_return bs_failure
57
+ executed = false
58
+ jenkins_warning_state_observer.on_state_change(666) do
59
+ executed = true
60
+ end
61
+ expect(executed).to eq true
62
+ end
63
+
46
64
  it 'skips states where the last result is not FAILURE/ABORTED' do
47
- expect(observer).to receive(:expired?).with(666).and_return false
48
- allow(observer).to receive(:on_state_change)
49
- jenkins_warning_state_observer.on_state_change(666)
65
+ allow(observer).to receive(:fetch_new_state).and_return bs_success
66
+ executed = false
67
+ jenkins_warning_state_observer.on_state_change(666) do
68
+ executed = true
69
+ end
70
+ expect(executed).to eq false
50
71
  end
51
72
  end
52
73
 
53
74
  describe '#expired?' do
54
75
  it 'checks if all of its observers are expired' do
55
- expect(observer).to receive(:expired?).with(666)
56
- jenkins_warning_state_observer.expired?(666)
76
+ expect(observer).to receive(:state_changed_at).and_return Time.now - 666
77
+ expect(jenkins_warning_state_observer).to be_expired(60)
57
78
  end
58
79
  end
59
80
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ampel_extase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-27 00:00:00.000000000 Z
11
+ date: 2015-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gem_hadar