Get your fortune now! Let all your specs pass and the next fortune will appear.
$ rspec -r ./fortune_formatter.rb -f FortuneFormatter spec
- 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 |