Last active
December 10, 2018 11:09
-
-
Save benoittgt/0b4673fda1e779d01ed9355a1bcdadb7 to your computer and use it in GitHub Desktop.
Display "it" in RSpec example documentation format output
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rspec/core/formatters/console_codes' | |
require 'rspec/core/formatters/documentation_formatter' | |
# Display "it" in RSpec doc format output | |
# $ rspec spec/foo/bar_spec.rb --format DocIt | |
class DocIt < RSpec::Core::Formatters::DocumentationFormatter | |
RSpec::Core::Formatters.register self, | |
:example_passed, | |
:example_pending, | |
:example_failed | |
def example_passed(passed) | |
output.puts passed_output(passed.example) | |
end | |
def example_pending(pending) | |
output.puts pending_output(pending.example, | |
pending.example.execution_result.pending_message) | |
end | |
def example_failed(failure) | |
output.puts failure_output(failure.example) | |
end | |
private | |
def doc_it_ouptut(example) | |
"It #{example.description.strip}" | |
end | |
def passed_output(example) | |
RSpec::Core::Formatters::ConsoleCodes | |
.wrap("#{current_indentation}#{doc_it_ouptut(example)}", :success) | |
end | |
def pending_output(example, message) | |
RSpec::Core::Formatters::ConsoleCodes | |
.wrap("#{current_indentation}#{doc_it_ouptut(example)} " \ | |
"(PENDING: #{message})", | |
:pending) | |
end | |
def failure_output(example) | |
RSpec::Core::Formatters::ConsoleCodes | |
.wrap("#{current_indentation}#{doc_it_ouptut(example)} " \ | |
"(FAILED - #{next_failure_index})", | |
:failure) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'support/formatters/doc_it' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment