lifx_dash 0.2.0 → 0.2.1

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: cfe674982a9903633e0576f45dfd2f9e598cd9cb
4
- data.tar.gz: 533b6ad256a945e13505484568345faa7d60d0d2
3
+ metadata.gz: cde4d1d84b135cf5d326504c0851f8703fb5f7d7
4
+ data.tar.gz: ced93f39fdbcc107870e8969dcab429006090874
5
5
  SHA512:
6
- metadata.gz: 9c443ecea091c19c9f41a48cd3c7ac29f5f371982a8bdd18cbca99f8be00201822f7b0c5164911b9a1998d848f3474894c08c8828339472bfcf5234b8ed9ce6b
7
- data.tar.gz: 388b2c610cbc1d6f1b27f3fcb1a98506482b18933fdf79ffd9760980a64298aa1a84bd6b21453f7b676fbd6fd5ab856afbbbb5d800e4f8ba6e1e91bfa88d4302
6
+ metadata.gz: 185f41631bc572c42f5bc173cd8ebc5ab569bf5214be48a439d8178c46fc0a2be790bd2e9962396c5d4decbea072861e8b21a9445650f8b8821a3c690f3be699
7
+ data.tar.gz: 37d3db26fe370bd8fd8b20945b85bc99abe815f134bf63418900dade12f720d92225db1541b10c1e2b3a6dc35973711126325455ddd27f5d5fb4ebc71a31be71
@@ -0,0 +1,17 @@
1
+ Feature: Show help information
2
+ In order to show command line help
3
+
4
+ Scenario: Show general command line help
5
+ When I get help for "lifx_dash"
6
+ Then the output should contain " lifx_dash - Toggle LIFX lights with an Amazon Dash button"
7
+ Then the output should match / config - (.*)/
8
+ Then the output should match / help - (.*)/
9
+ Then the output should match / monitor - (.*)/
10
+ Then the output should match / snoop - (.*)/
11
+ And the exit status should be 0
12
+
13
+ Scenario: Show config help
14
+ When I run `lifx_dash help config`
15
+ Then the output should contain " config - Set (and persist) default options for commands"
16
+ Then the output should contain " -s, --[no-]show - Show the config file"
17
+ And the exit status should be 0
@@ -0,0 +1,4 @@
1
+ When /^I get help for "([^"]*)"$/ do |app_name|
2
+ @app_name = app_name
3
+ step %(I run `#{app_name} help`)
4
+ end
@@ -0,0 +1 @@
1
+ require 'aruba/cucumber'
@@ -1,3 +1,3 @@
1
1
  module LifxDash
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -49,8 +49,8 @@ Gem::Specification.new do |spec|
49
49
  spec.requirements << 'root access'
50
50
 
51
51
  # external gems
52
- spec.add_runtime_dependency "gli", "2.14.0"
53
- spec.add_runtime_dependency "packetfu", "1.1.11"
52
+ spec.add_runtime_dependency "gli", "2.16.0"
53
+ spec.add_runtime_dependency "packetfu", "1.1.13"
54
54
 
55
55
  # dev gems
56
56
  spec.add_development_dependency "bundler"
@@ -0,0 +1,73 @@
1
+ require File.expand_path(File.dirname(__FILE__)+'/../test_helper')
2
+
3
+ class TestLifxHTTPApi < MiniTest::Unit::TestCase
4
+
5
+ def setup
6
+ @logger = MiniTest::Mock.new
7
+ @api_client = LifxDash::LifxHTTPApi.new('my-token', @logger)
8
+ end
9
+
10
+ def test_toggles_lights_logging_successful
11
+ selector = "d073d500ec8e"
12
+ body = { results: [{ id: "d073d500ec8e", label: "Golden Boy", status: "ok" } ]}.to_json
13
+ stub_request(:post, lifx_url(selector)).to_return(body: body, status: 207)
14
+
15
+ @logger.expect(:info, nil, ["Toggling lights! (via #{LifxDash::LifxHTTPApi::BASE_URI})"])
16
+ @logger.expect(:info, nil, ["Lights toggled successfully!"])
17
+ @logger.expect(:info, nil, ["API reply (207): #{body}"])
18
+ @api_client.toggle(selector)
19
+
20
+ assert @logger.verify
21
+ end
22
+
23
+ def test_toggles_lights_logging_warnings
24
+ selector = "all"
25
+ http_responses = {
26
+ 401 => { error: "Invalid token" }, # invalid token in header
27
+ 500 => nil, # server issue
28
+ 207 => "{}" # server OK, but results not present
29
+ }
30
+
31
+ http_responses.each do |code, api_response_body|
32
+ stub_request(:post, lifx_url(selector)).
33
+ to_return(body: api_response_body.to_json, status: code)
34
+
35
+ @logger.expect(:info, nil, ["Toggling lights! (via #{LifxDash::LifxHTTPApi::BASE_URI})"])
36
+ @logger.expect(:warn, nil, ["Warning: Possible issue with LIFX lights or HTTP API response"])
37
+ @logger.expect(:warn, nil, ["API reply (#{code}): #{api_response_body.to_json}"])
38
+ @api_client.toggle(selector)
39
+
40
+ assert @logger.verify
41
+ end
42
+ end
43
+
44
+ def test_raises_error_on_toggle_when_http_errors
45
+ assert_raises(Errno::ECONNRESET) do
46
+ @logger.expect(:info, nil, ["Toggling lights! (via #{LifxDash::LifxHTTPApi::BASE_URI})"])
47
+ @logger.expect(:error, nil, ["Error: POST request to #{LifxDash::LifxHTTPApi::BASE_URI} failed: Connection reset by peer"])
48
+
49
+ net_error = -> (uri) { raise Errno::ECONNRESET.new }
50
+ Net::HTTP::Post.stub :new, net_error do
51
+ @api_client.toggle('all')
52
+ end
53
+
54
+ assert @logger.verify
55
+ end
56
+ end
57
+
58
+ def test_raises_error_on_toggle_with_bad_selector
59
+ assert_raises(URI::InvalidURIError) do
60
+ bad_selector = "im a bad bulb selector"
61
+ @logger.expect(:error, nil, ["Error: POST request to #{LifxDash::LifxHTTPApi::BASE_URI} failed: bad URI(is not URI?): #{lifx_url(bad_selector)}"])
62
+ @api_client.toggle(bad_selector)
63
+
64
+ assert @logger.verify
65
+ end
66
+ end
67
+
68
+ private
69
+
70
+ def lifx_url(selector)
71
+ "https://#{LifxDash::LifxHTTPApi::BASE_URI}/lights/#{selector}/toggle"
72
+ end
73
+ end
@@ -0,0 +1,15 @@
1
+ if ENV['COVERAGE']
2
+ if ENV['TRAVIS']
3
+ require 'coveralls'
4
+ Coveralls.wear!
5
+ else
6
+ require 'simplecov'
7
+ end
8
+ end
9
+
10
+ require 'lifx_dash'
11
+ require 'minitest/autorun'
12
+ require 'webmock/minitest'
13
+
14
+ # set a quiet logger to /dev/null
15
+ LOGGER = Logger.new("/dev/null")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lifx_dash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Hutchinson
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 2.14.0
19
+ version: 2.16.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 2.14.0
26
+ version: 2.16.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: packetfu
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 1.1.11
33
+ version: 1.1.13
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 1.1.11
40
+ version: 1.1.13
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -193,6 +193,9 @@ files:
193
193
  - bin/console
194
194
  - bin/lifx_dash
195
195
  - bin/setup
196
+ - features/lifx_dash.feature
197
+ - features/step_definitions/lifx_dash_steps.rb
198
+ - features/support/env.rb
196
199
  - lib/lifx_dash.rb
197
200
  - lib/lifx_dash/capturer.rb
198
201
  - lib/lifx_dash/configuration.rb
@@ -205,6 +208,8 @@ files:
205
208
  - man/lifx_dash.1
206
209
  - man/lifx_dash.1.html
207
210
  - man/lifx_dash.1.ronn
211
+ - test/lifx_dash/lifx_http_api_test.rb
212
+ - test/test_helper.rb
208
213
  homepage: http://github.com/matthutchinson/lifx_dash
209
214
  licenses:
210
215
  - MIT
@@ -239,4 +244,9 @@ rubygems_version: 2.6.11
239
244
  signing_key:
240
245
  specification_version: 4
241
246
  summary: Toggle LIFX lights with an Amazon Dash button
242
- test_files: []
247
+ test_files:
248
+ - features/lifx_dash.feature
249
+ - features/step_definitions/lifx_dash_steps.rb
250
+ - features/support/env.rb
251
+ - test/lifx_dash/lifx_http_api_test.rb
252
+ - test/test_helper.rb