rspec-hue 0.1.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/philips_hue_controller.rb +17 -6
- data/lib/rspec_hue.rb +57 -32
- data/rspec-hue.gemspec +1 -1
- data/spec/philips_hue_controller_spec.rb +3 -3
- data/spec/rspec_hue_spec.rb +16 -8
- data/spec/spec_helper.rb +0 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 618121b3d95864794a80ba1afcd03e187660a3e3
|
4
|
+
data.tar.gz: 1cebc7b4f076a9ce9dc3d61077cb38df75e1fe28
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9085c5d629e4ca2932d779ef5bbbf574199154597798bd79be875670e4e97bd77c91d121a3049602bcad61bcc56658dc1453d8658866dc2b89f667472678b1be
|
7
|
+
data.tar.gz: 49e51ac9ae2dc45aca445dc6caa67a2076593c2c7c23c444708e087ed9c503ce4533306100d5536de27d87834540294e9147e2cb010b4d9e67fbfcb2656ad9c5
|
@@ -2,6 +2,7 @@ require 'huey'
|
|
2
2
|
require 'null_bulb'
|
3
3
|
|
4
4
|
class PhilipsHueController
|
5
|
+
|
5
6
|
def initialize options = {}
|
6
7
|
@configuration = default_options.merge options
|
7
8
|
if configuration.has_key? :bulb_id_to_use
|
@@ -10,18 +11,23 @@ class PhilipsHueController
|
|
10
11
|
@bulb = passed_bulb_or_null_bulb
|
11
12
|
end
|
12
13
|
end
|
14
|
+
|
13
15
|
def failed
|
14
|
-
bulb.update(configuration[:failed_color])
|
16
|
+
bulb.update(configuration[:failed_color])
|
15
17
|
end
|
18
|
+
|
16
19
|
def passed
|
17
|
-
bulb.update(configuration[:passed_color])
|
20
|
+
bulb.update(configuration[:passed_color])
|
18
21
|
end
|
22
|
+
|
19
23
|
private
|
24
|
+
|
20
25
|
def configuration
|
21
26
|
@configuration
|
22
27
|
end
|
28
|
+
|
23
29
|
def default_options
|
24
|
-
{
|
30
|
+
{
|
25
31
|
hue_ip: nil,
|
26
32
|
ssdp_ip: '239.255.255.250',
|
27
33
|
ssdp_port: 1900,
|
@@ -33,25 +39,30 @@ class PhilipsHueController
|
|
33
39
|
passed_color: { bri: 57, ct: 500, xy: [ 0.408, 0.517 ] }
|
34
40
|
}
|
35
41
|
end
|
42
|
+
|
36
43
|
def output
|
37
44
|
configuration[:output]
|
38
45
|
end
|
46
|
+
|
39
47
|
def bulb
|
40
48
|
@bulb
|
41
49
|
end
|
50
|
+
|
42
51
|
def passed_bulb_or_null_bulb
|
43
52
|
configuration.fetch(:bulb, NullBulb.new )
|
44
53
|
end
|
54
|
+
|
45
55
|
def init_bulb
|
46
56
|
@bulb = Huey::Bulb.find(configuration[:bulb_id_to_use]) if configuration.has_key? :bulb_id_to_use
|
47
57
|
@bulb = passed_bulb_or_null_bulb if @bulb.nil? #Huey return nil if not found
|
48
58
|
@bulb.on = true
|
49
59
|
@bulb.transitiontime = configuration[:bulb_transition_time]
|
50
60
|
end
|
61
|
+
|
51
62
|
def init_philips_hue
|
52
63
|
# Must do this, othwerwise Huey starts pushing out debug messages
|
53
64
|
Huey::Config.logger = ::Logger.new(nil)
|
54
|
-
begin
|
65
|
+
begin
|
55
66
|
Huey.configure do |config|
|
56
67
|
if configuration[:hue_ip].nil?
|
57
68
|
config.ssdp = true
|
@@ -79,7 +90,7 @@ class PhilipsHueController
|
|
79
90
|
rescue Huey::Errors::PressLinkButton
|
80
91
|
if STDIN.tty?
|
81
92
|
output.puts "RspecHue: Not authorized, press linkbutton on Philips Hue, then press enter here to continue, or q and enter to skip."
|
82
|
-
input = gets.strip
|
93
|
+
input = gets.strip
|
83
94
|
unless input.downcase == "q"
|
84
95
|
init_philips_hue
|
85
96
|
else
|
@@ -91,4 +102,4 @@ class PhilipsHueController
|
|
91
102
|
end
|
92
103
|
end
|
93
104
|
end
|
94
|
-
end
|
105
|
+
end
|
data/lib/rspec_hue.rb
CHANGED
@@ -1,49 +1,79 @@
|
|
1
1
|
require 'rspec'
|
2
2
|
require 'philips_hue_controller'
|
3
3
|
|
4
|
-
class RspecHue
|
5
|
-
|
4
|
+
class RspecHue
|
5
|
+
|
6
|
+
# ::RSpec::Core::Formatters.register self,
|
7
|
+
# :example_passed,
|
8
|
+
# :example_pending,
|
9
|
+
# :example_failed,
|
10
|
+
# :example_group_started,
|
11
|
+
# :example_group_finished,
|
12
|
+
# :dump_summary,
|
13
|
+
# :seed
|
14
|
+
|
15
|
+
::RSpec::Core::Formatters.register self,
|
16
|
+
:example_failed,
|
17
|
+
:dump_summary
|
18
|
+
|
19
|
+
attr_reader :output, :failure_count, :bulb_controller
|
20
|
+
|
21
|
+
class << self
|
22
|
+
def configure_rspec_for_settings
|
23
|
+
RSpec.configure do |c|
|
24
|
+
c.add_setting :rspec_hue_light_id
|
25
|
+
c.add_setting :rspec_hue_ip
|
26
|
+
c.add_setting :rspec_hue_failed_color
|
27
|
+
c.add_setting :rspec_hue_passed_color
|
28
|
+
c.add_setting :rspec_hue_api_user
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def initialize(output, additional_args = {})
|
6
34
|
@output = output || StringIO.new
|
7
35
|
@additional_args = additional_args
|
8
36
|
@failure_count = 0
|
9
|
-
|
10
|
-
#called by rspec
|
11
|
-
def dump_summary duration, example_count, failure_count, pending_count
|
37
|
+
|
12
38
|
@bulb_controller = @additional_args.fetch(:controller) { setup_philips_hue_controller }
|
13
|
-
@failure_count = failure_count
|
14
|
-
end
|
15
|
-
# Catch everything else rspec throws at us, and swallow it.
|
16
|
-
def method_missing m, *args, █ end
|
17
|
-
|
18
|
-
def self.configure_rspec_for_settings
|
19
|
-
RSpec.configure do |c|
|
20
|
-
c.add_setting :rspec_hue_light_id
|
21
|
-
c.add_setting :rspec_hue_ip
|
22
|
-
c.add_setting :rspec_hue_failed_color
|
23
|
-
c.add_setting :rspec_hue_passed_color
|
24
|
-
c.add_setting :rspec_hue_api_user
|
25
|
-
end
|
26
39
|
end
|
27
40
|
|
28
|
-
|
29
|
-
|
41
|
+
def example_passed(notification)
|
42
|
+
end
|
43
|
+
|
44
|
+
def example_pending(notification)
|
45
|
+
end
|
46
|
+
|
47
|
+
def example_failed(notification)
|
48
|
+
@failure_count += 1
|
49
|
+
end
|
50
|
+
|
51
|
+
def dump_summary(summary)
|
30
52
|
init_bulb_controller
|
31
|
-
|
32
|
-
|
33
|
-
|
53
|
+
|
54
|
+
if failed?
|
55
|
+
bulb_controller.failed
|
56
|
+
else
|
34
57
|
bulb_controller.passed
|
35
58
|
end
|
36
59
|
end
|
37
60
|
|
61
|
+
|
38
62
|
private
|
63
|
+
|
39
64
|
def init_bulb_controller
|
40
65
|
@bulb_controller = @additional_args.fetch(:controller) { setup_philips_hue_controller }
|
41
66
|
end
|
42
|
-
|
67
|
+
|
68
|
+
def failed?
|
43
69
|
@failure_count > 0
|
44
70
|
end
|
71
|
+
|
45
72
|
def setup_philips_hue_controller
|
46
|
-
options = {
|
73
|
+
options = {
|
74
|
+
bulb_id_to_use: ENV["RSPEC_HUE_LIGHT_ID"] || RSpec.configuration.rspec_hue_light_id,
|
75
|
+
output: output
|
76
|
+
}
|
47
77
|
failed_color = RSpec.configuration.rspec_hue_failed_color
|
48
78
|
passed_color = RSpec.configuration.rspec_hue_passed_color
|
49
79
|
hue_ip = RSpec.configuration.rspec_hue_ip
|
@@ -54,12 +84,7 @@ class RspecHue
|
|
54
84
|
options[:api_user] = api_user unless api_user.nil?
|
55
85
|
PhilipsHueController.new options
|
56
86
|
end
|
57
|
-
|
58
|
-
|
59
|
-
end
|
60
|
-
def bulb_controller
|
61
|
-
@bulb_controller
|
62
|
-
end
|
63
|
-
end
|
87
|
+
end
|
88
|
+
|
64
89
|
# Must call to add setting-possibilty to RSpec
|
65
90
|
RspecHue.configure_rspec_for_settings
|
data/rspec-hue.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "rspec-hue"
|
7
|
-
spec.version = '0.
|
7
|
+
spec.version = '1.0.0'
|
8
8
|
spec.authors = ["larskrantz"]
|
9
9
|
spec.email = ["lars.krantz@alaz.se"]
|
10
10
|
spec.description = %q{Light up Philips Hue when testing}
|
@@ -8,13 +8,13 @@ describe PhilipsHueController do
|
|
8
8
|
|
9
9
|
context "when telling controller to light bulb for failing test" do
|
10
10
|
it "the bulb should receive update with failcolor" do
|
11
|
-
bulb.
|
11
|
+
expect(bulb).to receive(:update).with(failed_color)
|
12
12
|
controller.failed
|
13
13
|
end
|
14
14
|
end
|
15
15
|
context "when telling controller to light bulb for passing test" do
|
16
16
|
it "the bulb should receive update with passcolor" do
|
17
|
-
bulb.
|
17
|
+
expect(bulb).to receive(:update).with(passed_color)
|
18
18
|
controller.passed
|
19
19
|
end
|
20
20
|
end
|
@@ -39,4 +39,4 @@ describe PhilipsHueController do
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
42
|
-
end
|
42
|
+
end
|
data/spec/rspec_hue_spec.rb
CHANGED
@@ -7,35 +7,43 @@ describe RspecHue do
|
|
7
7
|
config.send (setting.to_s + "=").to_sym, RSpec.configuration.send(setting)
|
8
8
|
end
|
9
9
|
end
|
10
|
+
|
10
11
|
it "should be able to set :rspec_hue_light_id" do
|
11
12
|
expect { set_rspec_setting :rspec_hue_light_id }.to_not raise_exception
|
12
13
|
end
|
14
|
+
|
13
15
|
it "should be able to set :rspec_hue_ip" do
|
14
16
|
expect { set_rspec_setting :rspec_hue_ip }.to_not raise_exception
|
15
17
|
end
|
18
|
+
|
16
19
|
it "should be able to set :rspec_hue_failed_color" do
|
17
20
|
expect { set_rspec_setting :rspec_hue_failed_color }.to_not raise_exception
|
18
21
|
end
|
22
|
+
|
19
23
|
it "should be able to set :rspec_hue_passed_color" do
|
20
24
|
expect { set_rspec_setting :rspec_hue_passed_color }.to_not raise_exception
|
21
25
|
end
|
26
|
+
|
22
27
|
it "should be able to set :rspec_hue_api_user" do
|
23
28
|
expect { set_rspec_setting :rspec_hue_api_user }.to_not raise_exception
|
24
29
|
end
|
25
30
|
end
|
31
|
+
|
26
32
|
context "when corresponding to the formatter interface" do
|
27
33
|
let(:controller) do
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
34
|
+
double("controller").tap do |c|
|
35
|
+
allow(c).to receive(:failed)
|
36
|
+
allow(c).to receive(:passed)
|
37
|
+
end
|
32
38
|
end
|
33
39
|
let(:formatter) { RspecHue.new StringIO.new, controller: controller }
|
40
|
+
|
34
41
|
it "should respond dump_summary" do
|
35
|
-
expect { formatter.dump_summary
|
42
|
+
expect { formatter.dump_summary "foo" }.to_not raise_exception
|
36
43
|
end
|
37
|
-
|
38
|
-
|
44
|
+
|
45
|
+
it "should increment #failed_count by 1" do
|
46
|
+
expect { formatter.example_failed(nil) }.to change { formatter.failure_count }.by(1)
|
39
47
|
end
|
40
48
|
end
|
41
|
-
end
|
49
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -6,7 +6,6 @@ require 'rspec_hue'
|
|
6
6
|
#
|
7
7
|
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
8
8
|
RSpec.configure do |config|
|
9
|
-
config.treat_symbols_as_metadata_keys_with_true_values = true
|
10
9
|
config.run_all_when_everything_filtered = true
|
11
10
|
config.filter_run :focus
|
12
11
|
config.filter_run_excluding :integration
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-hue
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- larskrantz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -124,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
124
|
version: '0'
|
125
125
|
requirements: []
|
126
126
|
rubyforge_project:
|
127
|
-
rubygems_version: 2.
|
127
|
+
rubygems_version: 2.4.5
|
128
128
|
signing_key:
|
129
129
|
specification_version: 4
|
130
130
|
summary: Let your Philips Hue indicate if tests are passing or not
|