Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show console log messages and errors independently from specdocs in Guard #62

Merged
merged 3 commits into from
May 21, 2012
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 32 additions & 22 deletions lib/guard/jasmine/runner.rb
Original file line number Diff line number Diff line change
@@ -254,47 +254,57 @@ def report_specdoc(result, passed, options)
# @param [Number] level the indention level
#
def report_specdoc_suite(suite, passed, options, level = 0)
# Should the specdoc be shown?
show_specdoc = (options[:specdoc] == :always || (options[:specdoc] == :failure && !passed))
# Are console messages displayed?
console_messages = (options[:console] == :always || (options[:console] == :failure && !passed))
# Are there any logs to display at all for this suite?
logs_for_current_options = suite['specs'].select do |spec|
spec['logs'] && (options[:console] == :always || (options[:console] == :failure && !spec['passed']))
end
any_logs_present = (!logs_for_current_options.empty?)

# Print the suite description when the specdoc is shown or there are logs to display
if show_specdoc || (any_logs_present && console_messages)
if (specdoc_shown?(passed, options) || console_logs_shown?(suite, passed, options))
Formatter.suite_name((' ' * level) + suite['description']) if passed || options[:focus] && contains_failed_spec?(suite)
end

suite['specs'].each do |spec|
if spec['passed']
# Should the spec description be shown?
show_description = (show_specdoc || (spec['logs'] && options[:console] == :always))

if passed || !options[:focus] || (options[:console] == :always && spec['logs'])
Formatter.success(indent(" ✔ #{ spec['description'] }", level)) if show_description
report_specdoc_errors(spec, options, level) if show_specdoc
Formatter.success(indent(" ✔ #{ spec['description'] }", level)) if description_shown?(passed, spec, options)
report_specdoc_errors(spec, options, level) if specdoc_shown?(passed, options)
report_specdoc_logs(spec, options, level)
end
else
# Should the spec description be shown?
show_description = (show_specdoc || (spec['logs'] && options[:console] != :never))

Formatter.spec_failed(indent(" ✘ #{ spec['description'] }", level)) if show_description
Formatter.spec_failed(indent(" ✘ #{ spec['description'] }", level)) if description_shown?(passed, spec, options)
spec['messages'].each do |message|
Formatter.spec_failed(indent(" ➤ #{ format_message(message, false) }", level)) if show_specdoc
Formatter.spec_failed(indent(" ➤ #{ format_message(message, false) }", level)) if specdoc_shown?(passed, options)
end
report_specdoc_errors(spec, options, level) if show_specdoc
report_specdoc_errors(spec, options, level) if specdoc_shown?(passed, options)
report_specdoc_logs(spec, options, level)
end
end

suite['suites'].each { |suite| report_specdoc_suite(suite, passed, options, level + 2) } if suite['suites']
end

# Is the specdoc shown for this suite?
def specdoc_shown?(passed, options = {})
(options[:specdoc] == :always || (options[:specdoc] == :failure && !passed))
end

# Are console logs shown for this suite?
def console_logs_shown?(suite, passed, options = {})
# Are console messages displayed?
console_messages = (options[:console] == :always || (options[:console] == :failure && !passed))
# Are there any logs to display at all for this suite?
logs_for_current_options = suite['specs'].select do |spec|
spec['logs'] && (options[:console] == :always || (options[:console] == :failure && !spec['passed']))
end
any_logs_present = (!logs_for_current_options.empty?)
(console_messages && any_logs_present)
end

# Is the description shown for this spec?
def description_shown?(passed, spec, options = {})
specdoc = specdoc_shown?(passed, options)
console = (spec['logs'] && ((spec['passed'] && options[:console] == :always) ||
options[:console] != :never))
(specdoc || console)
end


# Shows the logs for a given spec.
#
# @param [Hash] spec the spec result