Permalink
Browse files

a screengrab

  • Loading branch information...
stefl committed Feb 19, 2011
1 parent 1bcc09c commit ffa8d71f05765568ab4d401242c47e4d8a2cb2ce
Showing with 43 additions and 7 deletions.
  1. +22 −0 demo_spec.rb
  2. +9 −0 pretty_printer.rb
  3. +12 −7 readme.md
View
@@ -0,0 +1,22 @@
+require 'rspec'
+require 'json'
+require 'pretty_printer'
+require 'textmate_puts_helper'
+
+class MyClass
+ include PrettyPrinter
+
+ def as_json
+ {:id => 1, :description => 'oddness', :emotion => 'confused'}
+ end
+end
+
+describe "Meaningful debugging output in Textmate" do
+
+ it "should actually display objects not just the # symbol" do
+ puts "Let's see what is going on here..."
+ pp MyClass.new
+ MyClass.new.as_json.should be_nil # force rspec to fail so you can see how this is useful
+ end
+
+end
View
@@ -0,0 +1,9 @@
+module PrettyPrinter
+ def self.included(c)
+ c.class_eval do
+ def pp *args
+ puts JSON.pretty_generate(self.as_json)
+ end
+ end
+ end
+end
View
@@ -1,20 +1,25 @@
-Nicely formats debugging output in Textmate for BDD people who occasionally need to do
+Nicely formats debugging puts and pp statements in Textmate (for Rspec).
- puts MyObject.inspect
- pp MyClass.last
- puts "What the hell is going on?"
+Sometimes you need to do things like this:
+
+ puts "Let's see what's going on here..."
+ pp MyClass.new
+
And usually see just this on the screen:
+ Let's see what's going on here...
#
- #
- What the hell is going on?
+
+You can right-click to inspect element, but that's a pain.
Drop the textmate_puts_helper.rb in your spec folder
require 'textmate_puts_helper'
-Watch as your objects appear as you would normally expect.
+Watch as your objects appear as you would expect:
+
+![Rspec debugging](https://img.skitch.com/20110219-ecx1pefh5eqtxxibcispcjikqg.png)
If you define a method 'pp' on any class instance, this will be used when using 'pp'.

0 comments on commit ffa8d71

Please sign in to comment.