From e2dc41c4eb03c9b25cbe865f65334b91458c5749 Mon Sep 17 00:00:00 2001 From: eregon Date: Thu, 8 Apr 2010 14:01:39 +0200 Subject: [PATCH 1/2] Corrected params for AwesomePrint.defaults: it is a single Hash and then *args does not work on 1.9. Also fixed typos in Readme --- README.md | 10 +++++----- lib/ap/awesome_print.rb | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 3adc2d9..f6238f4 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Default options: :multiline => true, :plain => false, :indent => 4, - :colors => { + :color => { :array => :white, :bignum => :blue, :class => :yellow, @@ -47,7 +47,7 @@ Supported color names: ### Examples ### $ cat > 1.rb require "ap" - data = [ false, 42, %w(fourty two), { :now => Time.now, :class => Time.now.class, :distance => 42e42 } ] + data = [ false, 42, %w(forty two), { :now => Time.now, :class => Time.now.class, :distance => 42e42 } ] ap data ^D $ ruby 1.rb @@ -55,7 +55,7 @@ Supported color names: [0] false, [1] 42, [2] [ - [0] "fourty", + [0] "forty", [1] "two" ], [3] { @@ -79,12 +79,12 @@ Supported color names: $ cat > 3.rb require "ap" - data = [ false, 42, %w(fourty two) ] + data = [ false, 42, %w(forty two) ] data << data # <-- Nested array. ap data, :multiline => false ^D $ ruby 3.rb - [ false, 42, [ "fourty", "two" ], [...] ] + [ false, 42, [ "forty", "two" ], [...] ] ### Example (Rails console) ### $ ruby script/console diff --git a/lib/ap/awesome_print.rb b/lib/ap/awesome_print.rb index 3f395f2..2de42d8 100755 --- a/lib/ap/awesome_print.rb +++ b/lib/ap/awesome_print.rb @@ -224,8 +224,8 @@ class AwesomePrint @@defaults ||= {} end - def self.defaults=(*args) - @@defaults = *args + def self.defaults=(args = {}) + @@defaults = args end end From bf3c9915b649f1d2823226607580abbc96490fe9 Mon Sep 17 00:00:00 2001 From: Mike Dvorkin Date: Thu, 8 Apr 2010 19:57:58 -0700 Subject: [PATCH 2/2] Stub ~/.aprc in specs to make sure custom defaults do not affect them --- spec/awesome_print_spec.rb | 3 +++ spec/rails_spec.rb | 43 +++++++++++++++++++++----------------- spec/spec_helper.rb | 6 +++++- 3 files changed, 32 insertions(+), 20 deletions(-) diff --git a/spec/awesome_print_spec.rb b/spec/awesome_print_spec.rb index bdf674a..c122f95 100644 --- a/spec/awesome_print_spec.rb +++ b/spec/awesome_print_spec.rb @@ -1,6 +1,9 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper') describe "AwesomePrint" do + before(:each) do + stub_dotfile! + end describe "Array" do before(:each) do diff --git a/spec/rails_spec.rb b/spec/rails_spec.rb index d4841b0..0ff8b53 100644 --- a/spec/rails_spec.rb +++ b/spec/rails_spec.rb @@ -20,17 +20,22 @@ if defined?(::Rails) column :created_at, :datetime end - #------------------------------------------------------------------------------ - describe "ActiveRecord instance" do + describe "AwesomePrint/Rails" do before(:each) do - @diana = User.new(:name => "Diana", :rank => 1, :admin => false, :created_at => "1992-10-10 12:30:00") - @laura = User.new(:name => "Laura", :rank => 2, :admin => true, :created_at => "2003-05-26 14:15:00") - @ap = AwesomePrint.new(:plain => true) + stub_dotfile! end - it "display single record" do - out = @ap.send(:awesome, @diana) - out.gsub(/0x([a-f\d]+)/, "0x01234567").should == <<-EOS.strip + #------------------------------------------------------------------------------ + describe "ActiveRecord instance" do + before(:each) do + @diana = User.new(:name => "Diana", :rank => 1, :admin => false, :created_at => "1992-10-10 12:30:00") + @laura = User.new(:name => "Laura", :rank => 2, :admin => true, :created_at => "2003-05-26 14:15:00") + @ap = AwesomePrint.new(:plain => true) + end + + it "display single record" do + out = @ap.send(:awesome, @diana) + out.gsub(/0x([a-f\d]+)/, "0x01234567").should == <<-EOS.strip # { :id => nil, :name => "Diana", @@ -39,11 +44,11 @@ if defined?(::Rails) :created_at => Sat, 10 Oct 1992 12:30:00 UTC +00:00 } EOS - end + end - it "display multiple records" do - out = @ap.send(:awesome, [ @diana, @laura ]) - out.gsub(/0x([a-f\d]+)/, "0x01234567").should == <<-EOS.strip + it "display multiple records" do + out = @ap.send(:awesome, [ @diana, @laura ]) + out.gsub(/0x([a-f\d]+)/, "0x01234567").should == <<-EOS.strip [ [0] # { :id => nil, @@ -61,14 +66,14 @@ EOS } ] EOS + end end - end - #------------------------------------------------------------------------------ - describe "ActiveRecord class" do - it "should" do - @ap = AwesomePrint.new(:plain => true) - @ap.send(:awesome, User).should == <<-EOS.strip + #------------------------------------------------------------------------------ + describe "ActiveRecord class" do + it "should" do + @ap = AwesomePrint.new(:plain => true) + @ap.send(:awesome, User).should == <<-EOS.strip class User < ActiveRecord::Base { :id => :integer, :name => :string, @@ -77,7 +82,7 @@ class User < ActiveRecord::Base { :created_at => :datetime } EOS + end end end - end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 8093bb3..3fbbd28 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -5,5 +5,9 @@ require 'spec' require 'spec/autorun' Spec::Runner.configure do |config| - +end + +def stub_dotfile! + dotfile = File.join(ENV["HOME"], ".aprc") + File.should_receive(:readable?).at_least(:once).with(dotfile).and_return(false) end