autotest-snarl 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ require 'rubygems/package_task'
2
+
3
+ # gemspec
4
+ spec = Gem::Specification.new do |s|
5
+ s.name = 'autotest-snarl'
6
+ s.summary = 'Clean and stolen easy integration of Net::Snarl and autotest'
7
+ s.version = '0.0.2'
8
+ s.author = 'Luis Lavena'
9
+ s.email = 'luislavena@gmail.com'
10
+ s.description = <<-EOT
11
+ This makes more easy to see autotest messages using Net::Snarl
12
+ EOT
13
+ s.homepage = 'http://github.com/luislavena/autotest-snarl'
14
+
15
+ s.require_path = 'lib'
16
+ s.files = FileList[
17
+ 'Rakefile', 'lib/**/*.rb', 'img/*.png'
18
+ ]
19
+
20
+ s.add_dependency 'net-snarl', '~> 0.0.1'
21
+ end
22
+
23
+ # packaging
24
+ Gem::PackageTask.new(spec) do |pkg|
25
+ pkg.need_zip = false
26
+ pkg.need_tar = false
27
+ end
data/img/failed.png ADDED
Binary file
data/img/passed.png ADDED
Binary file
data/img/pending.png ADDED
Binary file
@@ -0,0 +1,62 @@
1
+ # stolen from autotest-growl
2
+ # http://github.com/svoop/autotest-growl
3
+
4
+ class Autotest
5
+ class ResultsParser
6
+
7
+ ##
8
+ # Analyze test result lines and return the numbers in a hash.
9
+ def initialize(autotest)
10
+ @numbers = {}
11
+ lines = autotest.results.map {|s| s.gsub(/(\e.*?m|\n)/, '') } # remove escape sequences
12
+ lines.reject! {|line| !line.match(/\d+\s+(example|test|scenario|step)s?/) } # isolate result numbers
13
+ lines.each do |line|
14
+ prefix = nil
15
+ line.scan(/([1-9]\d*)\s(\w+)/) do |number, kind|
16
+ kind.sub!(/s$/, '') # singularize
17
+ kind.sub!(/failure/, 'failed') # homogenize
18
+ if prefix
19
+ @numbers["#{prefix}-#{kind}"] = number.to_i
20
+ else
21
+ @numbers[kind] = number.to_i
22
+ prefix = kind
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ ##
29
+ # Determine the testing framework used.
30
+ def framework
31
+ case
32
+ when @numbers['test'] then 'test-unit'
33
+ when @numbers['example'] then 'rspec'
34
+ when @numbers['scenario'] then 'cucumber'
35
+ end
36
+ end
37
+
38
+ ##
39
+ # Determine whether a result exists at all.
40
+ def exists?
41
+ !@numbers.empty?
42
+ end
43
+
44
+ ##
45
+ # Check whether a specific result is present.
46
+ def has?(kind)
47
+ @numbers.has_key?(kind)
48
+ end
49
+
50
+ ##
51
+ # Get a plain result number.
52
+ def [](kind)
53
+ @numbers[kind]
54
+ end
55
+
56
+ ##
57
+ # Get a labelled result number. The prefix is removed and the label pluralized if necessary.
58
+ def get(kind)
59
+ "#{@numbers[kind]} #{kind.sub(/^.*-/, '')}#{'s' if @numbers[kind] != 1 && !kind.match(/(ed|ing)$/)}" if @numbers[kind]
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,62 @@
1
+ require 'net/snarl'
2
+ require 'autotest/results_parser'
3
+
4
+ class Autotest
5
+ module Snarl
6
+ IMG_PATH = File.expand_path(File.join(File.dirname(__FILE__), '..' , '..', 'img'))
7
+
8
+ Autotest.add_hook :run_command do
9
+ @project = File.basename(Dir.pwd)
10
+ end
11
+
12
+ Autotest.add_hook :ran_command do |autotest|
13
+ unless @ran_tests
14
+ results = Autotest::ResultsParser.new(autotest)
15
+ if results.exists?
16
+ case results.framework
17
+ when 'rspec'
18
+ if results.has?('example-failed')
19
+ notify "#{@project}: some examples failed.",
20
+ "#{results['example-failed']} of #{results.get('example')} failed",
21
+ 'failed'
22
+ elsif results.has?('example-pending')
23
+ notify "#{@project}: some examples are pending.",
24
+ "#{results['example-pending']} of #{results.get('example')} pending",
25
+ 'pending'
26
+ else
27
+ notify "#{@project}: all examples passed.",
28
+ "#{results.get('example')}",
29
+ 'passed'
30
+ end
31
+ end
32
+ else
33
+ notify "#{@project}: Could not run tests.", '', 'error', true
34
+ end
35
+ false
36
+ end
37
+ end
38
+
39
+ def self.notify(title, text, klass, sticky = false)
40
+ snarl.notify(
41
+ :app => 'autotest',
42
+ :title => title,
43
+ :text => text,
44
+ :class => klass,
45
+ :timeout => sticky ? 0 : 5,
46
+ :icon => File.join(IMG_PATH, "#{klass}.png")
47
+ )
48
+ end
49
+
50
+ def self.snarl
51
+ return @@snarl if defined?(@@snarl)
52
+
53
+ @@snarl = Net::Snarl.new
54
+ @@snarl.register('autotest')
55
+ @@snarl.add_class('autotest', 'passed')
56
+ @@snarl.add_class('autotest', 'failed')
57
+ @@snarl.add_class('autotest', 'pending')
58
+ @@snarl.add_class('autotest', 'error')
59
+ @@snarl
60
+ end
61
+ end
62
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: autotest-snarl
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 2
9
+ version: 0.0.2
10
+ platform: ruby
11
+ authors:
12
+ - Luis Lavena
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-10-28 00:00:00 -02:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: net-snarl
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ - 0
31
+ - 1
32
+ version: 0.0.1
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ description: |
36
+ This makes more easy to see autotest messages using Net::Snarl
37
+
38
+ email: luislavena@gmail.com
39
+ executables: []
40
+
41
+ extensions: []
42
+
43
+ extra_rdoc_files: []
44
+
45
+ files:
46
+ - Rakefile
47
+ - lib/autotest/results_parser.rb
48
+ - lib/autotest/snarl.rb
49
+ - img/failed.png
50
+ - img/passed.png
51
+ - img/pending.png
52
+ has_rdoc: true
53
+ homepage: http://github.com/luislavena/autotest-snarl
54
+ licenses: []
55
+
56
+ post_install_message:
57
+ rdoc_options: []
58
+
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ segments:
67
+ - 0
68
+ version: "0"
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ requirements: []
78
+
79
+ rubyforge_project:
80
+ rubygems_version: 1.3.7
81
+ signing_key:
82
+ specification_version: 3
83
+ summary: Clean and stolen easy integration of Net::Snarl and autotest
84
+ test_files: []
85
+