Module: TestNotifier
- Defined in:
- lib/test_notifier.rb
Constant Summary collapse
- PASSED_IMAGE =
create a .test_notifier at your home directory and save the images as passed.png, failure.png and error.png for custom images
"passed.png"- FAILURE_IMAGE =
"failure.png"- ERROR_IMAGE =
"error.png"- FAILURE_TITLE =
"FAILED"- PASSED_TITLE =
"Passed"- RSPEC_REGEX =
/(\d+) examples?, (\d+) failures?(, (\d+) pendings?)?/- TEST_UNIT_REGEX =
/(\d+)\stests,\s(\d+)\sassertions,\s(\d+)\sfailures,\s(\d+)\serrors/
Class Method Summary collapse
- .notification_for_rspec(content) ⇒ Object
- .notification_for_test_unit(content) ⇒ Object
- .notify(image, title, message) ⇒ Object
- .rspec?(content) ⇒ Boolean
Class Method Details
.notification_for_rspec(content) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/test_notifier.rb', line 35 def self.notification_for_rspec(content) matches, *output = *content.to_s.match(RSPEC_REGEX) output = output.map {|i| i.to_i } e, f, none, p = output if f > 0 # test has failed title = FAILURE_TITLE image = FAILURE_IMAGE elsif e > 0 # everything's ok title = PASSED_TITLE image = PASSED_IMAGE else # no examples return end = "#{e} examples, #{f} failures, #{p} pending" notify(image, title, ) end |
.notification_for_test_unit(content) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/test_notifier.rb', line 57 def self.notification_for_test_unit(content) matches, *output = *content.to_s.match(TEST_UNIT_REGEX) output = output.map {|i| i.to_i } t, a, f, e = output if f > 0 || e > 0 # test has failed or raised an error title = FAILURE_TITLE image = e > 0 ? ERROR_IMAGE : FAILURE_IMAGE elsif a > 0 # everything's ok title = PASSED_TITLE image = PASSED_IMAGE else # no assertions return end = "#{t} tests, #{a} assertions, #{f} failures, #{e} errors" notify(image, title, ) end |
.notify(image, title, message) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/test_notifier.rb', line 16 def self.notify(image, title, ) image ||= "none.png" custom_image = File.join(File.("~/.test_notifier"), image) image = File.exists?(custom_image) ? custom_image : File.join(File.dirname(__FILE__), "test_notifier", "icons", image) if RUBY_PLATFORM =~ /darwin/ system("growlnotify -n test_notifier --image #{image} -p 2 -m \"#{}\" -t \"#{title}\"") elsif RUBY_PLATFORM =~ /mswin/ Snarl.(title, , image) elsif RUBY_PLATFORM =~ /(linux|freebsd)/ system("notify-send -i #{image} #{title} \"#{}\"") end end |
.rspec?(content) ⇒ Boolean
31 32 33 |
# File 'lib/test_notifier.rb', line 31 def self.rspec?(content) (RSPEC_REGEX =~ content) end |