Created
June 12, 2017 20:07
-
-
Save mcoms/77954d191bde31d4677872d2ab3d0cd5 to your computer and use it in GitHub Desktop.
When you're having a bad day and just want to skip every failing RSpec test
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
# frozen_string_literal: true | |
class CustomFormatter | |
RSpec::Core::Formatters.register self, :example_failed | |
def initialize(output) | |
@output = output | |
end | |
def example_failed(notification) | |
tf = Tempfile.new | |
File.open(notification.example.metadata[:file_path]) do |f| | |
counter = 1 | |
while (line = f.gets) | |
if counter == notification.example.metadata[:line_number] | |
line.sub!('it', 'skip') | |
line.sub!('scenario', 'skip') | |
@output << line | |
end | |
tf.write line | |
counter += 1 | |
end | |
end | |
tf.close | |
FileUtils.mv tf.path, notification.example.metadata[:file_path] | |
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
rspec --require ./custom_formatter.rb --format CustomFormatter |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment