Skip to content

Commit

Permalink
Better notification titles, show console success specs only without :…
Browse files Browse the repository at this point in the history
…hide_success enabled.
  • Loading branch information
netzpirat committed Sep 8, 2011
1 parent df45770 commit caf10d6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
11 changes: 6 additions & 5 deletions lib/guard/jasmine/runner.rb
Expand Up @@ -171,26 +171,27 @@ def notify_spec_result(result, options)
message = "#{ specs } specs, #{ failures } failure#{ plural }\nin #{ time } seconds"

if failures != 0
notify_specdoc(result, message)
Formatter.notify(message, :title => 'Jasmine results', :image => :failed, :priority => 2) if options[:notification]
notify_specdoc(result, message, options)
Formatter.notify(message, :title => 'Jasmine specs failed', :image => :failed, :priority => 2) if options[:notification]
else
Formatter.success(message)
Formatter.notify(message, :title => 'Jasmine results') if options[:notification] && !options[:hide_success]
Formatter.notify(message, :title => 'Jasmine specs passed') if options[:notification] && !options[:hide_success]
end
end

# Specdoc like formatting of the result.
#
# @param [Hash] result the suite result
# @param [String] stats the status information
# @option options [Boolean] :hide_success hide success message notification
#
def notify_specdoc(result, stats)
def notify_specdoc(result, stats, options)
result['suites'].each do |suite|
Formatter.suite_name("➥ #{ suite['description'] }")

suite['specs'].each do |spec|
if spec['passed']
Formatter.success(" ✔ #{ spec['description'] }")
Formatter.success(" ✔ #{ spec['description'] }") if !options[:hide_success]
else
Formatter.spec_failed(" ✘ #{ spec['description'] }#{ spec['error_message'] }")
end
Expand Down
31 changes: 23 additions & 8 deletions spec/guard/jasmine/runner_spec.rb
Expand Up @@ -159,7 +159,7 @@
it 'requests the jasmine specs from the server' do
File.should_receive(:foreach).with('spec/javascripts/x/b.js.coffee').and_yield 'describe "FailureTest", ->'
IO.should_receive(:popen).with("#{ phantomjs_command } http://localhost:3000/jasmine?spec=FailureTest")
runner.run(['spec/javascripts/x/b.js.coffee'], { :notification => false }.merge(defaults))
runner.run(['spec/javascripts/x/b.js.coffee'], defaults.merge({ :notification => false }))
end

it 'shows the specs in the console' do
Expand All @@ -172,26 +172,41 @@
formatter.should_receive(:spec_failed).with(
' ✘ Failure spec tests something ➤ Expected undefined to be defined.'
)
formatter.should_receive(:success).with(
' ✔ Success spec tests something'
)
formatter.should_receive(:info).with(
"4 specs, 1 failure\nin 0.007 seconds"
)
runner.run(['spec/javascripts/x/b.js.coffee'], { :notification => false }.merge(defaults))
runner.run(['spec/javascripts/x/b.js.coffee'], defaults.merge({ :notification => false }))
end

it 'returns the failures' do
response = runner.run(['spec/javascripts/x/b.js.coffee'], { :notification => false }.merge(defaults))
response = runner.run(['spec/javascripts/x/b.js.coffee'], defaults)
response.first.should be_false
response.last.should =~ ['spec/javascripts/x/b.js.coffee']
end

context 'with the :hide_success option disabled' do
it 'shows the passing specs in the console' do
formatter.should_receive(:success).with(
' ✔ Success spec tests something'
)
runner.run(['spec/javascripts/x/b.js.coffee'], defaults.merge({ :hide_success => false }))
end
end

context 'without the :hide_success option enabled' do
it 'does not shows the passing specs in the console' do
formatter.should_not_receive(:success).with(
' ✔ Success spec tests something'
)
runner.run(['spec/javascripts/x/b.js.coffee'], defaults.merge({ :hide_success => true }))
end
end

context 'with notifications' do
it 'shows a failure notification' do
formatter.should_receive(:notify).with(
"4 specs, 1 failure\nin 0.007 seconds",
:title => 'Jasmine results',
:title => 'Jasmine specs failed',
:image => :failed,
:priority => 2
)
Expand Down Expand Up @@ -237,7 +252,7 @@
it 'shows a success notification' do
formatter.should_receive(:notify).with(
"4 specs, 0 failures\nin 0.009 seconds",
:title => 'Jasmine results'
:title => 'Jasmine specs passed'
)
runner.run(['spec/javascripts/t.js'], defaults.merge({ :notification => true }))
end
Expand Down

0 comments on commit caf10d6

Please sign in to comment.