mirror of
https://github.com/awesome-print/awesome_print
synced 2023-03-27 23:22:34 -04:00
Merge branch 'master' into 0.1.4
This commit is contained in:
commit
0b472a7da3
5 changed files with 39 additions and 27 deletions
10
README.md
10
README.md
|
@ -23,7 +23,7 @@ Default options:
|
||||||
:multiline => true,
|
:multiline => true,
|
||||||
:plain => false,
|
:plain => false,
|
||||||
:indent => 4,
|
:indent => 4,
|
||||||
:colors => {
|
:color => {
|
||||||
:array => :white,
|
:array => :white,
|
||||||
:bignum => :blue,
|
:bignum => :blue,
|
||||||
:class => :yellow,
|
:class => :yellow,
|
||||||
|
@ -47,7 +47,7 @@ Supported color names:
|
||||||
### Examples ###
|
### Examples ###
|
||||||
$ cat > 1.rb
|
$ cat > 1.rb
|
||||||
require "ap"
|
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
|
ap data
|
||||||
^D
|
^D
|
||||||
$ ruby 1.rb
|
$ ruby 1.rb
|
||||||
|
@ -55,7 +55,7 @@ Supported color names:
|
||||||
[0] false,
|
[0] false,
|
||||||
[1] 42,
|
[1] 42,
|
||||||
[2] [
|
[2] [
|
||||||
[0] "fourty",
|
[0] "forty",
|
||||||
[1] "two"
|
[1] "two"
|
||||||
],
|
],
|
||||||
[3] {
|
[3] {
|
||||||
|
@ -79,12 +79,12 @@ Supported color names:
|
||||||
|
|
||||||
$ cat > 3.rb
|
$ cat > 3.rb
|
||||||
require "ap"
|
require "ap"
|
||||||
data = [ false, 42, %w(fourty two) ]
|
data = [ false, 42, %w(forty two) ]
|
||||||
data << data # <-- Nested array.
|
data << data # <-- Nested array.
|
||||||
ap data, :multiline => false
|
ap data, :multiline => false
|
||||||
^D
|
^D
|
||||||
$ ruby 3.rb
|
$ ruby 3.rb
|
||||||
[ false, 42, [ "fourty", "two" ], [...] ]
|
[ false, 42, [ "forty", "two" ], [...] ]
|
||||||
|
|
||||||
### Example (Rails console) ###
|
### Example (Rails console) ###
|
||||||
$ ruby script/console
|
$ ruby script/console
|
||||||
|
|
|
@ -223,8 +223,8 @@ class AwesomePrint
|
||||||
@@defaults ||= {}
|
@@defaults ||= {}
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.defaults=(*args)
|
def self.defaults=(args = {})
|
||||||
@@defaults = *args
|
@@defaults = args
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
||||||
|
|
||||||
describe "AwesomePrint" do
|
describe "AwesomePrint" do
|
||||||
|
before(:each) do
|
||||||
|
stub_dotfile!
|
||||||
|
end
|
||||||
|
|
||||||
describe "Array" do
|
describe "Array" do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
|
|
|
@ -20,17 +20,22 @@ if defined?(::Rails)
|
||||||
column :created_at, :datetime
|
column :created_at, :datetime
|
||||||
end
|
end
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
describe "AwesomePrint/Rails" do
|
||||||
describe "ActiveRecord instance" do
|
|
||||||
before(:each) do
|
before(:each) do
|
||||||
@diana = User.new(:name => "Diana", :rank => 1, :admin => false, :created_at => "1992-10-10 12:30:00")
|
stub_dotfile!
|
||||||
@laura = User.new(:name => "Laura", :rank => 2, :admin => true, :created_at => "2003-05-26 14:15:00")
|
|
||||||
@ap = AwesomePrint.new(:plain => true)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "display single record" do
|
#------------------------------------------------------------------------------
|
||||||
out = @ap.send(:awesome, @diana)
|
describe "ActiveRecord instance" do
|
||||||
out.gsub(/0x([a-f\d]+)/, "0x01234567").should == <<-EOS.strip
|
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
|
||||||
#<User:0x01234567> {
|
#<User:0x01234567> {
|
||||||
:id => nil,
|
:id => nil,
|
||||||
:name => "Diana",
|
:name => "Diana",
|
||||||
|
@ -39,11 +44,11 @@ if defined?(::Rails)
|
||||||
:created_at => Sat, 10 Oct 1992 12:30:00 UTC +00:00
|
:created_at => Sat, 10 Oct 1992 12:30:00 UTC +00:00
|
||||||
}
|
}
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
it "display multiple records" do
|
it "display multiple records" do
|
||||||
out = @ap.send(:awesome, [ @diana, @laura ])
|
out = @ap.send(:awesome, [ @diana, @laura ])
|
||||||
out.gsub(/0x([a-f\d]+)/, "0x01234567").should == <<-EOS.strip
|
out.gsub(/0x([a-f\d]+)/, "0x01234567").should == <<-EOS.strip
|
||||||
[
|
[
|
||||||
[0] #<User:0x01234567> {
|
[0] #<User:0x01234567> {
|
||||||
:id => nil,
|
:id => nil,
|
||||||
|
@ -61,14 +66,14 @@ EOS
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
EOS
|
EOS
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
describe "ActiveRecord class" do
|
describe "ActiveRecord class" do
|
||||||
it "should" do
|
it "should" do
|
||||||
@ap = AwesomePrint.new(:plain => true)
|
@ap = AwesomePrint.new(:plain => true)
|
||||||
@ap.send(:awesome, User).should == <<-EOS.strip
|
@ap.send(:awesome, User).should == <<-EOS.strip
|
||||||
class User < ActiveRecord::Base {
|
class User < ActiveRecord::Base {
|
||||||
:id => :integer,
|
:id => :integer,
|
||||||
:name => :string,
|
:name => :string,
|
||||||
|
@ -77,7 +82,7 @@ class User < ActiveRecord::Base {
|
||||||
:created_at => :datetime
|
:created_at => :datetime
|
||||||
}
|
}
|
||||||
EOS
|
EOS
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,5 +5,9 @@ require 'spec'
|
||||||
require 'spec/autorun'
|
require 'spec/autorun'
|
||||||
|
|
||||||
Spec::Runner.configure do |config|
|
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue