Skip to content

Instantly share code, notes, and snippets.

@rwtnorton
Created June 25, 2011 23:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rwtnorton/1047025 to your computer and use it in GitHub Desktop.
Save rwtnorton/1047025 to your computer and use it in GitHub Desktop.
Describes how to install and use this custom RSpec formatter.

SARMUMY

Tihs gem pdveiors a cutsom fmteaortr for ReSpc taht jmbleus yuor test ouuptt.

This is, of csroue, a vrey silly tinhg to want to do with yuor tset optuut.

UAGSE

$ rspec -f JumbledFormatter spec

HOW DEOS IT WORK?

It scmberals the lrteets of wrods in yuor tset otuupt, but it does not cnaghe the frsit and last ltaetr of thsoe words. It is raelly ssprurinig to see how lbiegle jlmeubd txet lkie this can raelly be!

With repsect to ReSpc, this cusotm ftoatremr is a ssblcaus of the DocumentationFormatter.

WHY?

Bsaceue it is slliy and sligipnsrury lgelbie (for sorht words, at any rate).

require 'rspec/core/formatters/documentation_formatter'
# Add icsnnate mtheod +jbmule+ to Sntrig.
class String
# Jeblmus up the lttrees of a wrod but lveeas frsit and last chars in pclae.
def self.jumble_term(s)
return s if s.size < 4
chars = s.split(//)
[chars[0], *chars[1..-2].shuffle, chars[-1]].join('')
end
def jumble
self.gsub(/[a-zA-Z]+/) do |match|
self.class.jumble_term(match)
end
end
end
class JumbledFormatter < RSpec::Core::Formatters::DocumentationFormatter
# Aoivd mgninug the ANSI cloor epecsas.
# A bit of a klugde but it wrkos.
# Has the sdie-ecfeft of lvaenig the guorp nemas anole.
def color(text, color_code)
super(text.to_s.jumble, color_code)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment