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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: db7485876728c2deada251978bbb3ccd5eebc587
4
- data.tar.gz: dbae4d22680eba2060bfd454f64541991ec07236
3
+ metadata.gz: 618121b3d95864794a80ba1afcd03e187660a3e3
4
+ data.tar.gz: 1cebc7b4f076a9ce9dc3d61077cb38df75e1fe28
5
5
  SHA512:
6
- metadata.gz: a4787aa3ad6a2006088fe3d364aef5ffee0df78a0bf11b82e0709de9debcd1784c6f4bcdcb1df8cdb699ed41debf9321fd1b7fb08cc5f8f31c246890783cc277
7
- data.tar.gz: ca764b3797ac88c79e9a3eb85b774f4e5349357a98479de4c7ebf2a532f31701d53e20d25e0db902b47d41dce2e2564ef626eece6ca4045c7bcd8c74c0723936
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
- def initialize output, additional_args = {}
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
- end
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, &block; 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
- # called by rspec when finished
29
- def close()
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
- if failed
32
- bulb_controller.failed
33
- else
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
- def failed
67
+
68
+ def failed?
43
69
  @failure_count > 0
44
70
  end
71
+
45
72
  def setup_philips_hue_controller
46
- options = { bulb_id_to_use: RSpec.configuration.rspec_hue_light_id, output: output }
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
- def output
58
- @output
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.1.3'
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.should_receive(:update).with(failed_color)
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.should_receive(:update).with(passed_color)
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
@@ -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
- c = double("controller")
29
- c.stub(:failed)
30
- c.stub(:passed)
31
- c
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 123,2,1,1 }.to_not raise_exception
42
+ expect { formatter.dump_summary "foo" }.to_not raise_exception
36
43
  end
37
- it "should not raise error if calling close() before dump_summary" do
38
- expect { formatter.close() }.to_not raise_exception
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.1.3
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: 2013-08-20 00:00:00.000000000 Z
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.0.3
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