ChuckTestar 0.0.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.
- data/README.md +33 -0
- data/assets/chuck-nope.png +0 -0
- data/assets/chuck-normal.png +0 -0
- data/chuck_testar.gemspec +24 -0
- data/lib/chuck_testar.rb +128 -0
- data/lib/notifications/growl.rb +11 -0
- data/spec/chuck_testar_spec.rb +60 -0
- data/spec/spec_helper.rb +24 -0
- metadata +77 -0
data/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# Chuck testr RSpec formatter
|
2
|
+
|
3
|
+
The gem is a game changer... Nope! It's just **Chuck Testar - Chuck's Testa RSpec formatter**
|
4
|
+
|
5
|
+
## Requirements
|
6
|
+
|
7
|
+
It requires only `rspec` gem, obviously.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
If you are using bundler, add this to your `Gemfile`:
|
12
|
+
|
13
|
+
gem 'ChuckTestar'
|
14
|
+
|
15
|
+
Or install the gem manually with `gem install ChuckTestar`.
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
To start using the formatter you can either specify it in the rspec's command line options or add it to `.rspec` file:
|
20
|
+
|
21
|
+
- With `.rspec` file
|
22
|
+
|
23
|
+
Add this line to your `.rspec` file:
|
24
|
+
|
25
|
+
--format ChuckTestar
|
26
|
+
|
27
|
+
- With command line options
|
28
|
+
|
29
|
+
rspec spec/* --format ChuckTestar
|
30
|
+
|
31
|
+
## License
|
32
|
+
ChuckTestar is released under the MIT license
|
33
|
+
|
Binary file
|
Binary file
|
@@ -0,0 +1,24 @@
|
|
1
|
+
lib = File.expand_path('../lib/', __FILE__)
|
2
|
+
$:.unshift lib unless $:.include?(lib)
|
3
|
+
|
4
|
+
require 'bundler'
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "ChuckTestar"
|
8
|
+
s.version = '0.0.1'
|
9
|
+
s.platform = Gem::Platform::RUBY
|
10
|
+
s.authors = ["Mariusz Lusiak"]
|
11
|
+
s.email = ["mariusz@applicake.com"]
|
12
|
+
s.homepage = "http://applicake.com"
|
13
|
+
s.summary = %q{Chuck Testar Formatter for RSpec}
|
14
|
+
s.description = %q{}
|
15
|
+
|
16
|
+
s.required_rubygems_version = ">= 1.3.6"
|
17
|
+
|
18
|
+
s.add_runtime_dependency 'rspec'
|
19
|
+
s.add_runtime_dependency 'growl_notify' if RbConfig::CONFIG['host_os'] =~ /darwin/
|
20
|
+
|
21
|
+
s.files = %w( README.md chuck_testar.gemspec ) + Dir["lib/**/*.rb"] + Dir["assets/*.png"]
|
22
|
+
s.test_files = Dir["spec/**/*.rb"]
|
23
|
+
s.require_paths = ["lib"]
|
24
|
+
end
|
data/lib/chuck_testar.rb
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
require 'rspec/core/formatters/base_text_formatter'
|
2
|
+
require 'notifications/growl' if RbConfig::CONFIG['host_os'] =~ /darwin/
|
3
|
+
|
4
|
+
module ChuckTesta
|
5
|
+
class GnomeNotify
|
6
|
+
attr_accessor :title, :description, :icon
|
7
|
+
|
8
|
+
def initialize params={}
|
9
|
+
params.each { |k,v| send("#{k}=", v) }
|
10
|
+
end
|
11
|
+
|
12
|
+
def build_params
|
13
|
+
"-i #{icon} \"#{title}\" \"#{description}\""
|
14
|
+
end
|
15
|
+
|
16
|
+
def notify!
|
17
|
+
installed? ? `notify-send #{build_params}` : print_hint
|
18
|
+
end
|
19
|
+
|
20
|
+
def installed?
|
21
|
+
`which notify-send`.empty? ? false : true
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
def print_hint
|
26
|
+
`echo hint: sudo apt-get install libnotify-bin to see Chuck on your Desktop!`
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
module Portable
|
31
|
+
def self.platform
|
32
|
+
if RbConfig::CONFIG['host_os'] =~ /mswin|windows|cygwin/i
|
33
|
+
'windows'
|
34
|
+
elsif RbConfig::CONFIG['host_os'] =~ /darwin/
|
35
|
+
'osx'
|
36
|
+
else
|
37
|
+
'linux'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.linux?
|
42
|
+
ChuckTesta::Portable::platform == 'linux'
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.osx?
|
46
|
+
ChuckTesta::Portable::platform == 'osx'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
class ChuckTestar < RSpec::Core::Formatters::BaseTextFormatter
|
54
|
+
|
55
|
+
def icon(name)
|
56
|
+
File.join(File.dirname(__FILE__), '../assets', name)
|
57
|
+
end
|
58
|
+
|
59
|
+
def notify(text, icon_filename)
|
60
|
+
notification = {
|
61
|
+
:title => 'RSpec',
|
62
|
+
:description => text,
|
63
|
+
:icon => icon(icon_filename)
|
64
|
+
}
|
65
|
+
|
66
|
+
unless ChuckTesta::Portable::linux?
|
67
|
+
GrowlNotify.normal(notification)
|
68
|
+
else
|
69
|
+
notifier = ChuckTesta::GnomeNotify.new(notification)
|
70
|
+
notifier.notify!
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def say(text)
|
75
|
+
if ChuckTesta::Portable.platform == 'linux'
|
76
|
+
`echo "#{text}" | espeak 2>/dev/null`
|
77
|
+
elsif ChuckTesta::Portable.platform == 'osx'
|
78
|
+
`say "#{text}"`
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def notify_with_voice!(text, icon_filename)
|
83
|
+
notify(text, icon_filename)
|
84
|
+
say(text)
|
85
|
+
end
|
86
|
+
|
87
|
+
def delay(seconds)
|
88
|
+
sleep(seconds)
|
89
|
+
end
|
90
|
+
|
91
|
+
def start(example_count)
|
92
|
+
super(example_count)
|
93
|
+
output.print green('Y')
|
94
|
+
end
|
95
|
+
|
96
|
+
def stop
|
97
|
+
output.print green('p')
|
98
|
+
output.print green("\n\nYour tests pass!\n")
|
99
|
+
notify_with_voice!('Your tests pass', 'chuck-normal.png')
|
100
|
+
delay(2)
|
101
|
+
if @failed_examples.length > 0
|
102
|
+
output.print magenta("\n\nNope! It's just Chuck Testa!")
|
103
|
+
notify_with_voice!("Nope! It\'s just Chuck Testa!", 'chuck-nope.png')
|
104
|
+
delay(1)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def example_passed(example)
|
109
|
+
super(example)
|
110
|
+
output.print green('e')
|
111
|
+
end
|
112
|
+
|
113
|
+
def example_pending(example)
|
114
|
+
super(example)
|
115
|
+
output.print green('e')
|
116
|
+
end
|
117
|
+
|
118
|
+
def example_failed(example)
|
119
|
+
super(example)
|
120
|
+
output.print green('e')
|
121
|
+
end
|
122
|
+
|
123
|
+
def start_dump
|
124
|
+
super()
|
125
|
+
output.puts
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
@@ -0,0 +1,11 @@
|
|
1
|
+
begin
|
2
|
+
require "growl_notify"
|
3
|
+
|
4
|
+
GrowlNotify.config do |config|
|
5
|
+
config.notifications = ["Chuck Testar"]
|
6
|
+
config.default_notifications = ["Chuck Testar"]
|
7
|
+
config.application_name = "Chuck Testar RSpec formatter" # this shoes up in the growl applications list in systems settings
|
8
|
+
end
|
9
|
+
rescue LoadError
|
10
|
+
puts "Please install growl_notify gem to enable growl notifications"
|
11
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ChuckTestar do
|
4
|
+
let(:output) { StringIO.new }
|
5
|
+
let(:formatter) { ChuckTestar.new(output) }
|
6
|
+
|
7
|
+
before do
|
8
|
+
formatter.stub(:delay => true)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "output" do
|
12
|
+
let(:example) {
|
13
|
+
double("example 1",
|
14
|
+
:execution_result => {:status => 'failed', :exception => Exception.new }
|
15
|
+
)
|
16
|
+
}
|
17
|
+
|
18
|
+
it "displays 'Y' at the start of the suite" do
|
19
|
+
formatter.start(1)
|
20
|
+
output.string.should =~ /Y/
|
21
|
+
end
|
22
|
+
|
23
|
+
it "displays 'e' when examples pass" do
|
24
|
+
formatter.example_passed(example)
|
25
|
+
output.string.should =~ /e/
|
26
|
+
end
|
27
|
+
|
28
|
+
it "displays 'e' when examples fails" do
|
29
|
+
formatter.example_failed(example)
|
30
|
+
output.string.should =~ /e/
|
31
|
+
end
|
32
|
+
|
33
|
+
it "displays 'p' at the end of tests suite" do
|
34
|
+
formatter.stub(:notify_with_voice! => true)
|
35
|
+
formatter.stop
|
36
|
+
output.string.should =~ /p/
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "notifications" do
|
41
|
+
before do
|
42
|
+
formatter.stub(:say => true)
|
43
|
+
end
|
44
|
+
|
45
|
+
if ChuckTesta::Portable::osx?
|
46
|
+
it "display growl success notification when spec pass" do
|
47
|
+
formatter.example_passed(example)
|
48
|
+
GrowlNotify.should_receive(:normal).with(:title => 'RSpec', :description => 'Your tests pass', :icon => formatter.icon('chuck-normal.png'))
|
49
|
+
formatter.stop
|
50
|
+
end
|
51
|
+
|
52
|
+
it "display growl success and fail notifications when spec fail" do
|
53
|
+
formatter.example_failed(example)
|
54
|
+
GrowlNotify.should_receive(:normal).with(:title => 'RSpec', :description => 'Your tests pass', :icon => formatter.icon('chuck-normal.png'))
|
55
|
+
GrowlNotify.should_receive(:normal).with(:title => 'RSpec', :description => "Nope! It's just Chuck Testa!", :icon => formatter.icon('chuck-nope.png'))
|
56
|
+
formatter.stop
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#require 'simplecov'
|
2
|
+
#SimpleCov.start
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'spork'
|
6
|
+
|
7
|
+
Spork.prefork do
|
8
|
+
$:.unshift File.expand_path('../../lib', __FILE__)
|
9
|
+
|
10
|
+
require 'rubygems'
|
11
|
+
require 'bundler'
|
12
|
+
Bundler.setup
|
13
|
+
require 'rspec'
|
14
|
+
Dir[File.join(File.expand_path('../', __FILE__), "support/**/*.rb")].each do |file|
|
15
|
+
require file
|
16
|
+
end
|
17
|
+
|
18
|
+
require 'chuck_testar'
|
19
|
+
end
|
20
|
+
|
21
|
+
Spork.each_run do
|
22
|
+
|
23
|
+
end
|
24
|
+
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ChuckTestar
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Mariusz Lusiak
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-11-15 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &70164759505860 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70164759505860
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: growl_notify
|
27
|
+
requirement: &70164759504460 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70164759504460
|
36
|
+
description: ''
|
37
|
+
email:
|
38
|
+
- mariusz@applicake.com
|
39
|
+
executables: []
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
43
|
+
- README.md
|
44
|
+
- chuck_testar.gemspec
|
45
|
+
- lib/chuck_testar.rb
|
46
|
+
- lib/notifications/growl.rb
|
47
|
+
- assets/chuck-nope.png
|
48
|
+
- assets/chuck-normal.png
|
49
|
+
- spec/chuck_testar_spec.rb
|
50
|
+
- spec/spec_helper.rb
|
51
|
+
homepage: http://applicake.com
|
52
|
+
licenses: []
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.3.6
|
69
|
+
requirements: []
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 1.8.10
|
72
|
+
signing_key:
|
73
|
+
specification_version: 3
|
74
|
+
summary: Chuck Testar Formatter for RSpec
|
75
|
+
test_files:
|
76
|
+
- spec/chuck_testar_spec.rb
|
77
|
+
- spec/spec_helper.rb
|