minitest-libnotify 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm @minitest-libnotify --create
data/README.rdoc CHANGED
@@ -14,6 +14,39 @@ RDoc[http://rdoc.info/github/splattael/minitest-libnotify/master/file/README.rdo
14
14
 
15
15
  gem install minitest-libnotify
16
16
 
17
+ == Config
18
+
19
+ === Tweaking
20
+
21
+ require 'minitest/autorun'
22
+ require 'minitest/libnotify'
23
+
24
+ reporter = MiniTest::Unit.output
25
+ reporter.config[:global][:description] = "TESTS"
26
+ reporter.config[:pass][:description] = proc { |desc| "#{desc} :)" }
27
+ reporter.config[:fail][:description] = proc { |desc| "#{desc} :(" }
28
+ reporter.config[:fail][:icon_path] = "face-crying.*"
29
+
30
+ === Default config
31
+
32
+ reporter.default_config = {
33
+ :global => {
34
+ :timeout => 2.5,
35
+ :append => false,
36
+ :description => proc { [ defined?(RUBY_ENGINE) ? RUBY_ENGINE : "ruby", RUBY_VERSION, RUBY_PLATFORM ].join(" ") },
37
+ },
38
+ :pass => {
39
+ :description => proc { |description| ":-) #{description}" },
40
+ :urgency => :critical,
41
+ :icon_path => "face-laugh.*"
42
+ },
43
+ :fail => {
44
+ :description => proc { |description| ":-( #{description}" },
45
+ :urgency => :critical,
46
+ :icon_path => "face-angry.*"
47
+ }
48
+ }
49
+
17
50
  == Authors
18
51
 
19
52
  * Peter Suschlik (http://github.com/splattael)
data/example.rb ADDED
@@ -0,0 +1,11 @@
1
+ require 'minitest/libnotify'
2
+ require 'stringio'
3
+
4
+ reporter = MiniTest::Unit.output
5
+ reporter.config[:global][:description] = "TESTS"
6
+ reporter.config[:pass][:description] = proc { |desc| "#{desc} :)" }
7
+ reporter.config[:fail][:description] = proc { |desc| "#{desc} :(" }
8
+ reporter.config[:fail][:icon_path] = "face-crying*"
9
+
10
+ reporter.puts "0 failures, 1 errors"
11
+ reporter.puts "0 failures, 0 errors"
@@ -12,32 +12,58 @@ module MiniTest
12
12
  # require 'minitest/autorun'
13
13
  # require 'minitest/libnotify'
14
14
  #
15
+ # == Config
16
+ #
17
+ # require 'minitest/autorun'
18
+ # require 'minitest/libnotify'
19
+ #
20
+ # reporter = MiniTest::Unit.output
21
+ # reporter.config[:global][:description] = "TESTS"
22
+ # reporter.config[:pass][:description] = proc { |desc| "#{desc} :)" }
23
+ # reporter.config[:fail][:description] = proc { |desc| "#{desc} :(" }
24
+ # reporter.config[:fail][:icon_path] = "face-crying.*"
15
25
  class Libnotify
16
- def initialize io
17
- @io = io
18
- @libnotify = begin
19
- require 'libnotify'
20
- ::Libnotify.new(:timeout => 2.5, :append => false)
21
- rescue => e
22
- warn e
23
- false
24
- end
26
+ class << self
27
+ attr_accessor :default_config
28
+ end
29
+
30
+ # Default configuration
31
+ self.default_config = {
32
+ :global => {
33
+ :timeout => 2.5,
34
+ :append => false,
35
+ :description => proc { [ defined?(RUBY_ENGINE) ? RUBY_ENGINE : "ruby", RUBY_VERSION, RUBY_PLATFORM ].join(" ") },
36
+ },
37
+ :pass => {
38
+ :description => proc { |description| ":-) #{description}" },
39
+ :urgency => :critical,
40
+ :icon_path => "face-laugh.*"
41
+ },
42
+ :fail => {
43
+ :description => proc { |description| ":-( #{description}" },
44
+ :urgency => :critical,
45
+ :icon_path => "face-angry.*"
46
+ }
47
+ }
48
+
49
+ attr_accessor :config
50
+
51
+ def initialize io, config = self.class.default_config
52
+ @io = io
53
+ @libnotify = nil
54
+ @config = config.dup
25
55
  end
26
56
 
27
57
  def puts(*o)
28
- if @libnotify && o.first =~ /(\d+) failures, (\d+) errors/
29
- description = [ defined?(RUBY_ENGINE) ? RUBY_ENGINE : "ruby", RUBY_VERSION, RUBY_PLATFORM ].join(" ")
30
- @libnotify.body = o.first
31
- if $1.to_i > 0 || $2.to_i > 0 # fail?
32
- @libnotify.summary = ":-( #{description}"
33
- @libnotify.urgency = :critical
34
- @libnotify.icon_path = "face-angry.*"
35
- else
36
- @libnotify.summary += ":-) #{description}"
37
- @libnotify.urgency = :normal
38
- @libnotify.icon_path = "face-laugh.*"
39
- end
40
- @libnotify.show!
58
+ if libnotify && ((body = o.first) =~ /(\d+) failures, (\d+) errors/)
59
+ default_description = config_for(:description)
60
+ state = $1.to_i > 0 || $2.to_i > 0 ? :fail : :pass
61
+ libnotify.body = config_for(:body, state, body)
62
+ libnotify.summary = config_for(:description, state, default_description)
63
+ libnotify.urgency = config_for(:urgency, state)
64
+ libnotify.icon_path = config_for(:icon_path, state)
65
+ p libnotify
66
+ libnotify.show!
41
67
  end
42
68
  @io.puts(*o)
43
69
  end
@@ -45,6 +71,30 @@ module MiniTest
45
71
  def method_missing(msg, *args, &block)
46
72
  @io.send(msg, *args, &block)
47
73
  end
74
+
75
+ private
76
+
77
+ def libnotify
78
+ if @libnotify.nil?
79
+ @libnotify = begin
80
+ require 'libnotify'
81
+ ::Libnotify.new(:timeout => config_for(:timeout), :append => config_for(:append))
82
+ rescue => e
83
+ warn e
84
+ false
85
+ end
86
+ end
87
+ @libnotify
88
+ end
89
+
90
+ def config_for(name, state=:global, default=nil)
91
+ value = config[state][name] || config[:global][name]
92
+ if value.respond_to?(:call)
93
+ value.call(default)
94
+ else
95
+ value.nil? ? default : value
96
+ end
97
+ end
48
98
  end
49
99
  end
50
100
 
@@ -1,5 +1,5 @@
1
1
  module MiniTest
2
2
  class Libnotify
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,99 +1,76 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: minitest-libnotify
3
- version: !ruby/object:Gem::Version
4
- hash: 27
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 1
9
- - 0
10
- version: 0.1.0
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Peter Suschlik
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-12-07 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2012-03-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: minitest
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &17041080 !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 3
29
- segments:
30
- - 0
31
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
32
22
  type: :runtime
33
- version_requirements: *id001
34
- - !ruby/object:Gem::Dependency
35
- name: libnotify
36
23
  prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *17041080
25
+ - !ruby/object:Gem::Dependency
26
+ name: libnotify
27
+ requirement: &17067120 !ruby/object:Gem::Requirement
38
28
  none: false
39
- requirements:
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- hash: 3
43
- segments:
44
- - 0
45
- version: "0"
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
46
33
  type: :runtime
47
- version_requirements: *id002
34
+ prerelease: false
35
+ version_requirements: *17067120
48
36
  description: Display graphical notfications when testing with minitest.
49
- email:
37
+ email:
50
38
  - peter-minitest-libnotify@suschlik.de
51
39
  executables: []
52
-
53
40
  extensions: []
54
-
55
41
  extra_rdoc_files: []
56
-
57
- files:
42
+ files:
58
43
  - .gitignore
44
+ - .rvmrc
59
45
  - Gemfile
60
46
  - README.rdoc
61
47
  - Rakefile
48
+ - example.rb
62
49
  - lib/minitest/libnotify.rb
63
50
  - lib/minitest/libnotify/version.rb
64
51
  - minitest-libnotify.gemspec
65
52
  homepage: https://github.com/splattael/minitest-libnotify
66
53
  licenses: []
67
-
68
54
  post_install_message:
69
55
  rdoc_options: []
70
-
71
- require_paths:
56
+ require_paths:
72
57
  - lib
73
- required_ruby_version: !ruby/object:Gem::Requirement
58
+ required_ruby_version: !ruby/object:Gem::Requirement
74
59
  none: false
75
- requirements:
76
- - - ">="
77
- - !ruby/object:Gem::Version
78
- hash: 3
79
- segments:
80
- - 0
81
- version: "0"
82
- required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
65
  none: false
84
- requirements:
85
- - - ">="
86
- - !ruby/object:Gem::Version
87
- hash: 3
88
- segments:
89
- - 0
90
- version: "0"
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
91
70
  requirements: []
92
-
93
71
  rubyforge_project: minitest-libnotify
94
- rubygems_version: 1.8.10
72
+ rubygems_version: 1.8.17
95
73
  signing_key:
96
74
  specification_version: 3
97
75
  summary: Test notifier for minitest via libnotify.
98
76
  test_files: []
99
-