rspec-hue_formatter 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.rubocop.yml +23 -0
- data/.travis.yml +9 -0
- data/Gemfile +13 -0
- data/LICENSE.txt +21 -0
- data/README.md +38 -0
- data/Rakefile +11 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/rspec/hue_formatter.rb +141 -0
- data/lib/rspec/hue_formatter/version.rb +14 -0
- data/rspec-hue_formatter.gemspec +26 -0
- metadata +99 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ace37d10f2e3071cf1d9603c4b032d11d9782f6b
|
4
|
+
data.tar.gz: 39bee34c651613706d2e34aa7dd80e59f21ebc3a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7c3d6b4d959782f650fd66978675483439df8e1d01b49f99ac5795d841493987f4b746ef16f8eba1d5a8152f2b2447222cdbbdbdc58155accd55e28c4aac41be
|
7
|
+
data.tar.gz: 25ceea6f59538769dd5dc4980ad40b2e2867242c5b413fcd64f2e44cd46b8a2c45a9804d00a4822e9cfa9f7efde595cdaf4ba4d14467e06d88be79a8dd59f138
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Metrics/ClassLength:
|
2
|
+
Max: 150
|
3
|
+
|
4
|
+
Metrics/LineLength:
|
5
|
+
Max: 100
|
6
|
+
|
7
|
+
Style/AlignHash:
|
8
|
+
EnforcedHashRocketStyle: table
|
9
|
+
EnforcedColonStyle: separator
|
10
|
+
|
11
|
+
Style/Documentation:
|
12
|
+
Enabled: false
|
13
|
+
|
14
|
+
Style/EmptyElse:
|
15
|
+
Enabled: false
|
16
|
+
|
17
|
+
Style/GuardClause:
|
18
|
+
Enabled: false
|
19
|
+
|
20
|
+
Style/RegexpLiteral:
|
21
|
+
Exclude:
|
22
|
+
- '*.gemspec'
|
23
|
+
- 'Guardfile'
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Yuji Nakayama
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
[![Gem Version](http://img.shields.io/gem/v/rspec-hue_formatter.svg?style=flat)](http://badge.fury.io/rb/rspec-hue_formatter)
|
2
|
+
[![Dependency Status](http://img.shields.io/gemnasium/yujinakayama/rspec-hue_formatter.svg?style=flat)](https://gemnasium.com/yujinakayama/rspec-hue_formatter)
|
3
|
+
[![Build Status](https://travis-ci.org/yujinakayama/rspec-hue_formatter.svg?branch=master&style=flat)](https://travis-ci.org/yujinakayama/rspec-hue_formatter)
|
4
|
+
[![Coverage Status](http://img.shields.io/coveralls/yujinakayama/rspec-hue_formatter/master.svg?style=flat)](https://coveralls.io/r/yujinakayama/rspec-hue_formatter)
|
5
|
+
[![Code Climate](https://img.shields.io/codeclimate/github/yujinakayama/rspec-hue_formatter.svg?style=flat)](https://codeclimate.com/github/yujinakayama/rspec-hue_formatter)
|
6
|
+
|
7
|
+
# RSpec::HueFormatter
|
8
|
+
|
9
|
+
Bring RSpec integration into your room with [Philips Hue](http://www2.meethue.com/).
|
10
|
+
|
11
|
+
<iframe src="https://player.vimeo.com/video/124436622" width="500" height="281" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
|
12
|
+
|
13
|
+
## Requirements
|
14
|
+
|
15
|
+
* Philips Hue :)
|
16
|
+
* RSpec 3
|
17
|
+
|
18
|
+
## Installation
|
19
|
+
|
20
|
+
Add `rspec-hue_formatter` dependency to your Gemfile:
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
gem 'rspec-hue_formatter'
|
24
|
+
```
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
Run `rspec` with `--format RSpec::HueFormatter` as follows:
|
29
|
+
|
30
|
+
```bash
|
31
|
+
$ bundle exec rspec --format RSpec::HueFormatter
|
32
|
+
```
|
33
|
+
|
34
|
+
## License
|
35
|
+
|
36
|
+
Copyright (c) 2015 Yuji Nakayama
|
37
|
+
|
38
|
+
See the [LICENSE.txt](LICENSE.txt) for details.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'rspec/hue_formatter'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
require 'hue'
|
2
|
+
|
3
|
+
module RSpec
|
4
|
+
class HueFormatter
|
5
|
+
Core::Formatters.register(
|
6
|
+
self,
|
7
|
+
:start,
|
8
|
+
:example_started, :example_passed, :example_pending, :example_failed,
|
9
|
+
:dump_summary, :close
|
10
|
+
)
|
11
|
+
|
12
|
+
GREEN = 29_000
|
13
|
+
YELLOW = 12_750
|
14
|
+
RED = 0
|
15
|
+
|
16
|
+
IMMEDIATE_TRANSITION = 0
|
17
|
+
SLOW_TRANSITION = 10
|
18
|
+
|
19
|
+
LIGHT_SETTERS_BY_READER = {
|
20
|
+
on?: :on,
|
21
|
+
hue: :hue,
|
22
|
+
saturation: :saturation,
|
23
|
+
brightness: :brightness
|
24
|
+
}
|
25
|
+
|
26
|
+
attr_reader :example_index
|
27
|
+
|
28
|
+
def initialize(_output)
|
29
|
+
@example_index = -1
|
30
|
+
end
|
31
|
+
|
32
|
+
def start(_notification)
|
33
|
+
save_light_states
|
34
|
+
turn_off_lights
|
35
|
+
sleep 2
|
36
|
+
end
|
37
|
+
|
38
|
+
def example_started(_notification)
|
39
|
+
@example_index += 1
|
40
|
+
end
|
41
|
+
|
42
|
+
def example_passed(_notification)
|
43
|
+
flash_current_light(GREEN)
|
44
|
+
end
|
45
|
+
|
46
|
+
def example_pending(_notification)
|
47
|
+
flash_current_light(YELLOW)
|
48
|
+
end
|
49
|
+
|
50
|
+
def example_failed(_notification)
|
51
|
+
flash_current_light(RED)
|
52
|
+
end
|
53
|
+
|
54
|
+
def dump_summary(notification)
|
55
|
+
turn_off_lights(IMMEDIATE_TRANSITION)
|
56
|
+
|
57
|
+
sleep 2
|
58
|
+
|
59
|
+
hue = case
|
60
|
+
when notification.failure_count.nonzero? then RED
|
61
|
+
when notification.pending_count.nonzero? then YELLOW
|
62
|
+
else GREEN
|
63
|
+
end
|
64
|
+
|
65
|
+
glow_all_lights(hue, 2)
|
66
|
+
end
|
67
|
+
|
68
|
+
def close(_notification)
|
69
|
+
restore_light_states
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
def save_light_states
|
75
|
+
@states = lights.map do |light|
|
76
|
+
LIGHT_SETTERS_BY_READER.each_with_object({}) do |(attr, key), state|
|
77
|
+
state[key] = light.send(attr)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def restore_light_states
|
83
|
+
lights.zip(@states).each do |light, state|
|
84
|
+
light.set_state(state, SLOW_TRANSITION)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def turn_off_lights(transition_time = SLOW_TRANSITION)
|
89
|
+
set_all_light_states({ on: false }, transition_time)
|
90
|
+
end
|
91
|
+
|
92
|
+
def glow_all_lights(hue, number_of_times)
|
93
|
+
number_of_times.times do
|
94
|
+
set_all_light_states(bright_state(hue), SLOW_TRANSITION)
|
95
|
+
sleep 1
|
96
|
+
set_all_light_states({ brightness: Hue::Light::BRIGHTNESS_RANGE.begin }, SLOW_TRANSITION)
|
97
|
+
sleep 1
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def set_all_light_states(state, transition_time)
|
102
|
+
lights.each do |light|
|
103
|
+
light.set_state(state, transition_time)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def flash_current_light(hue)
|
108
|
+
previous_light.set_state({ on: false }, IMMEDIATE_TRANSITION)
|
109
|
+
current_light.set_state(bright_state(hue), IMMEDIATE_TRANSITION)
|
110
|
+
end
|
111
|
+
|
112
|
+
def bright_state(hue)
|
113
|
+
{
|
114
|
+
on: true,
|
115
|
+
hue: hue,
|
116
|
+
saturation: Hue::Light::SATURATION_RANGE.end,
|
117
|
+
brightness: Hue::Light::BRIGHTNESS_RANGE.end
|
118
|
+
}
|
119
|
+
end
|
120
|
+
|
121
|
+
def current_light
|
122
|
+
light_for_index(example_index)
|
123
|
+
end
|
124
|
+
|
125
|
+
def previous_light
|
126
|
+
light_for_index(example_index - 1)
|
127
|
+
end
|
128
|
+
|
129
|
+
def light_for_index(index)
|
130
|
+
light_index = index % lights.count
|
131
|
+
lights[light_index]
|
132
|
+
end
|
133
|
+
|
134
|
+
def lights
|
135
|
+
@lights ||= begin
|
136
|
+
hue = Hue::Client.new
|
137
|
+
hue.lights.sort_by(&:name)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rspec/hue_formatter/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'rspec-hue_formatter'
|
8
|
+
spec.version = Rspec::HueFormatter::Version.to_s
|
9
|
+
spec.authors = ['Yuji Nakayama']
|
10
|
+
spec.email = ['nkymyj@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = 'Bring RSpec integration into your room with Philips Hue.'
|
13
|
+
spec.description = spec.summary
|
14
|
+
spec.homepage = 'https://github.com/yujinakayama/rspec-hue_formatter'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = 'exe'
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_runtime_dependency 'rspec-core', '~> 3.0'
|
23
|
+
spec.add_runtime_dependency 'hue', '~> 0.1'
|
24
|
+
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspec-hue_formatter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yuji Nakayama
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec-core
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: hue
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
55
|
+
description: Bring RSpec integration into your room with Philips Hue.
|
56
|
+
email:
|
57
|
+
- nkymyj@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".rubocop.yml"
|
65
|
+
- ".travis.yml"
|
66
|
+
- Gemfile
|
67
|
+
- LICENSE.txt
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- bin/console
|
71
|
+
- bin/setup
|
72
|
+
- lib/rspec/hue_formatter.rb
|
73
|
+
- lib/rspec/hue_formatter/version.rb
|
74
|
+
- rspec-hue_formatter.gemspec
|
75
|
+
homepage: https://github.com/yujinakayama/rspec-hue_formatter
|
76
|
+
licenses:
|
77
|
+
- MIT
|
78
|
+
metadata: {}
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubyforge_project:
|
95
|
+
rubygems_version: 2.4.6
|
96
|
+
signing_key:
|
97
|
+
specification_version: 4
|
98
|
+
summary: Bring RSpec integration into your room with Philips Hue.
|
99
|
+
test_files: []
|