Skip to content

Instantly share code, notes, and snippets.

@duncanjbrown
Forked from mcoms/custom_formatter.rb
Last active October 6, 2022 09:55
Show Gist options
  • Save duncanjbrown/3bc25ef6b0a851062d16254050199397 to your computer and use it in GitHub Desktop.
Save duncanjbrown/3bc25ef6b0a851062d16254050199397 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
# 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]
regex = /^(\s*)(it|scenario) /
line.gsub!(regex, '\1x\2 ')
@output << line
end
tf.write line
counter += 1
end
end
tf.close
FileUtils.mv tf.path, notification.example.metadata[:file_path]
end
end
rspec --require ./custom_formatter.rb --format CustomFormatter
@duncanjbrown
Copy link
Author

Use xs instead of skip, and use a regex to put in the xs, otherwise a spec called "doesn't submit" became "doesn't submxit"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment