Skip to content

Instantly share code, notes, and snippets.

@thilko
Created June 20, 2011 20:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save thilko/1036437 to your computer and use it in GitHub Desktop.
Save thilko/1036437 to your computer and use it in GitHub Desktop.
A fortune rspec formatter. Make all your specs pass to get a new fortune!

FortuneFormatter

Get your fortune now! Let all your specs pass and the next fortune will appear.

Usage

$ rspec -r ./fortune_formatter.rb -f FortuneFormatter

Notes

  • Doesn´t work very well with webmock :-)
require 'rspec/core/formatters/progress_formatter'
require "net/http"
class FortuneFormatter < RSpec::Core::Formatters::ProgressFormatter
def stop
super
print_fortune if all_passed?
end
def all_passed?
failure_count == 0 && pending_count == 0
end
def print_fortune
response = Net::HTTP.start("brenocon.com") { |connect| connect.get "/fortune.cgi" }
message "\n<====FORTUNE=============>"
message response.body.scan(/<PRE>.(.*).?<\/PRE>/im).flatten.first.chomp
message "<========================>"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment