awesome_print 0.3.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +17 -0
- data/LICENSE +2 -1
- data/README.md +43 -22
- data/Rakefile +9 -29
- data/VERSION +1 -1
- data/init.rb +1 -1
- data/lib/ap/awesome_print.rb +38 -16
- data/lib/ap/core_ext/array.rb +9 -5
- data/lib/ap/core_ext/class.rb +6 -4
- data/lib/ap/core_ext/kernel.rb +2 -1
- data/lib/ap/core_ext/logger.rb +1 -1
- data/lib/ap/core_ext/method.rb +1 -1
- data/lib/ap/core_ext/object.rb +6 -6
- data/lib/ap/core_ext/string.rb +9 -8
- data/lib/ap/mixin/action_view.rb +4 -25
- data/lib/ap/mixin/active_record.rb +11 -10
- data/lib/ap/mixin/active_support.rb +3 -1
- data/lib/ap/mixin/mongo_mapper.rb +54 -0
- data/lib/ap.rb +19 -9
- data/lib/awesome_print.rb +16 -11
- data/rails/init.rb +1 -5
- data/spec/action_view_spec.rb +16 -26
- data/spec/active_record_spec.rb +73 -71
- data/spec/awesome_print_spec.rb +103 -2
- data/spec/colorization_spec.rb +84 -0
- data/spec/logger_spec.rb +1 -1
- data/spec/methods_spec.rb +19 -0
- data/spec/mongo_mapper_spec.rb +63 -0
- data/spec/spec_helper.rb +38 -15
- metadata +22 -18
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
2
|
+
|
|
3
|
+
begin
|
|
4
|
+
require "mongo_mapper"
|
|
5
|
+
require "ap/mixin/mongo_mapper"
|
|
6
|
+
|
|
7
|
+
describe "AwesomePrint/MongoMapper" do
|
|
8
|
+
before :all do
|
|
9
|
+
class MongoUser
|
|
10
|
+
include MongoMapper::Document
|
|
11
|
+
|
|
12
|
+
key :first_name, String
|
|
13
|
+
key :last_name, String
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
before :each do
|
|
18
|
+
@ap = AwesomePrint.new(:plain => true)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "should print for a class instance" do
|
|
22
|
+
user = MongoUser.new(:first_name => "Al", :last_name => "Capone")
|
|
23
|
+
out = @ap.send(:awesome, user)
|
|
24
|
+
str = <<-EOS.strip
|
|
25
|
+
#<MongoUser:0x01234567> {
|
|
26
|
+
"_id" => BSON::ObjectId('4d9183739a546f6806000001'),
|
|
27
|
+
"first_name" => "Al",
|
|
28
|
+
"last_name" => "Capone"
|
|
29
|
+
}
|
|
30
|
+
EOS
|
|
31
|
+
out.gsub!(/'([\w]+){23}'/, "'4d9183739a546f6806000001'")
|
|
32
|
+
out.gsub!(/0x([a-f\d]+)/, "0x01234567")
|
|
33
|
+
out.should == str
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "should print for a class" do
|
|
37
|
+
@ap.send(:awesome, MongoUser).should == <<-EOS.strip
|
|
38
|
+
class MongoUser < Object {
|
|
39
|
+
"_id" => :object_id,
|
|
40
|
+
"first_name" => :string,
|
|
41
|
+
"last_name" => :string
|
|
42
|
+
}
|
|
43
|
+
EOS
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it "should print for a class when type is undefined" do
|
|
47
|
+
class Chamelion
|
|
48
|
+
include MongoMapper::Document
|
|
49
|
+
key :last_attribute
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
@ap.send(:awesome, Chamelion).should == <<-EOS.strip
|
|
53
|
+
class Chamelion < Object {
|
|
54
|
+
"_id" => :object_id,
|
|
55
|
+
"last_attribute" => :undefined
|
|
56
|
+
}
|
|
57
|
+
EOS
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
rescue LoadError
|
|
62
|
+
puts "Skipping MongoMapper specs..."
|
|
63
|
+
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -1,28 +1,51 @@
|
|
|
1
|
-
# Copyright (c) 2010 Michael Dvorkin
|
|
1
|
+
# Copyright (c) 2010-2011 Michael Dvorkin
|
|
2
2
|
#
|
|
3
3
|
# Awesome Print is freely distributable under the terms of MIT license.
|
|
4
4
|
# See LICENSE file or http://www.opensource.org/licenses/mit-license.php
|
|
5
5
|
#------------------------------------------------------------------------------
|
|
6
6
|
#
|
|
7
|
-
# Running specs
|
|
8
|
-
# $ rake spec
|
|
9
|
-
# $
|
|
10
|
-
#
|
|
11
|
-
# Running specs with Ruby 1.9.2 and RSpec 2.0+:
|
|
12
|
-
# $ rake spec # Entire spec suite.
|
|
13
|
-
# $ rspec spec/logger_spec.rb # Individual spec file.
|
|
7
|
+
# Running specs from the command line:
|
|
8
|
+
# $ rake spec # Entire spec suite.
|
|
9
|
+
# $ rspec spec/logger_spec.rb # Individual spec file.
|
|
14
10
|
#
|
|
15
11
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
16
12
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
17
|
-
require '
|
|
18
|
-
|
|
19
|
-
if RUBY_VERSION.to_f < 1.9
|
|
20
|
-
require 'spec'
|
|
21
|
-
require 'spec/autorun'
|
|
22
|
-
require 'rubygems'
|
|
23
|
-
end
|
|
13
|
+
require 'awesome_print'
|
|
24
14
|
|
|
25
15
|
def stub_dotfile!
|
|
26
16
|
dotfile = File.join(ENV["HOME"], ".aprc")
|
|
27
17
|
File.should_receive(:readable?).at_least(:once).with(dotfile).and_return(false)
|
|
28
18
|
end
|
|
19
|
+
|
|
20
|
+
# The following is needed for the Infinity Test. It runs tests as subprocesses,
|
|
21
|
+
# which sets STDOUT.tty? to false and would otherwise prematurely disallow colors.
|
|
22
|
+
AwesomePrint.force_colors!
|
|
23
|
+
|
|
24
|
+
# Ruby 1.8.6 only: define missing String methods that are needed for the specs to pass.
|
|
25
|
+
if RUBY_VERSION < '1.8.7'
|
|
26
|
+
class String
|
|
27
|
+
def shellescape # Taken from Ruby 1.9.2 standard library, see lib/shellwords.rb.
|
|
28
|
+
return "''" if self.empty?
|
|
29
|
+
str = self.dup
|
|
30
|
+
str.gsub!(/([^A-Za-z0-9_\-.,:\/@\n])/n, "\\\\\\1")
|
|
31
|
+
str.gsub!(/\n/, "'\n'")
|
|
32
|
+
str
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def start_with?(*prefixes)
|
|
36
|
+
prefixes.each do |prefix|
|
|
37
|
+
prefix = prefix.to_s
|
|
38
|
+
return true if prefix == self[0, prefix.size]
|
|
39
|
+
end
|
|
40
|
+
false
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def end_with?(*suffixes)
|
|
44
|
+
suffixes.each do |suffix|
|
|
45
|
+
suffix = suffix.to_s
|
|
46
|
+
return true if suffix == self[-suffix.size, suffix.size]
|
|
47
|
+
end
|
|
48
|
+
false
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
metadata
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: awesome_print
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
+
hash: 15
|
|
4
5
|
prerelease: false
|
|
5
6
|
segments:
|
|
6
7
|
- 0
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
version: 0.
|
|
8
|
+
- 4
|
|
9
|
+
- 0
|
|
10
|
+
version: 0.4.0
|
|
10
11
|
platform: ruby
|
|
11
12
|
authors:
|
|
12
13
|
- Michael Dvorkin
|
|
@@ -14,21 +15,23 @@ autorequire:
|
|
|
14
15
|
bindir: bin
|
|
15
16
|
cert_chain: []
|
|
16
17
|
|
|
17
|
-
date:
|
|
18
|
+
date: 2011-05-13 00:00:00 -07:00
|
|
18
19
|
default_executable:
|
|
19
20
|
dependencies:
|
|
20
21
|
- !ruby/object:Gem::Dependency
|
|
21
22
|
name: rspec
|
|
22
23
|
prerelease: false
|
|
23
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
|
25
|
+
none: false
|
|
24
26
|
requirements:
|
|
25
27
|
- - ">="
|
|
26
28
|
- !ruby/object:Gem::Version
|
|
29
|
+
hash: 27
|
|
27
30
|
segments:
|
|
28
|
-
-
|
|
29
|
-
-
|
|
31
|
+
- 2
|
|
32
|
+
- 5
|
|
30
33
|
- 0
|
|
31
|
-
version:
|
|
34
|
+
version: 2.5.0
|
|
32
35
|
type: :development
|
|
33
36
|
version_requirements: *id001
|
|
34
37
|
description: "Great Ruby dubugging companion: pretty print Ruby objects to visualize their structure. Supports Rails ActiveRecord objects via included mixin."
|
|
@@ -59,13 +62,16 @@ files:
|
|
|
59
62
|
- lib/ap/mixin/action_view.rb
|
|
60
63
|
- lib/ap/mixin/active_record.rb
|
|
61
64
|
- lib/ap/mixin/active_support.rb
|
|
65
|
+
- lib/ap/mixin/mongo_mapper.rb
|
|
62
66
|
- lib/awesome_print.rb
|
|
63
67
|
- rails/init.rb
|
|
64
68
|
- spec/action_view_spec.rb
|
|
65
69
|
- spec/active_record_spec.rb
|
|
66
70
|
- spec/awesome_print_spec.rb
|
|
71
|
+
- spec/colorization_spec.rb
|
|
67
72
|
- spec/logger_spec.rb
|
|
68
73
|
- spec/methods_spec.rb
|
|
74
|
+
- spec/mongo_mapper_spec.rb
|
|
69
75
|
- spec/spec_helper.rb
|
|
70
76
|
- spec/string_spec.rb
|
|
71
77
|
has_rdoc: true
|
|
@@ -73,36 +79,34 @@ homepage: http://github.com/michaeldv/awesome_print
|
|
|
73
79
|
licenses: []
|
|
74
80
|
|
|
75
81
|
post_install_message:
|
|
76
|
-
rdoc_options:
|
|
77
|
-
|
|
82
|
+
rdoc_options: []
|
|
83
|
+
|
|
78
84
|
require_paths:
|
|
79
85
|
- lib
|
|
80
86
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
87
|
+
none: false
|
|
81
88
|
requirements:
|
|
82
89
|
- - ">="
|
|
83
90
|
- !ruby/object:Gem::Version
|
|
91
|
+
hash: 3
|
|
84
92
|
segments:
|
|
85
93
|
- 0
|
|
86
94
|
version: "0"
|
|
87
95
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
|
+
none: false
|
|
88
97
|
requirements:
|
|
89
98
|
- - ">="
|
|
90
99
|
- !ruby/object:Gem::Version
|
|
100
|
+
hash: 3
|
|
91
101
|
segments:
|
|
92
102
|
- 0
|
|
93
103
|
version: "0"
|
|
94
104
|
requirements: []
|
|
95
105
|
|
|
96
106
|
rubyforge_project: awesome_print
|
|
97
|
-
rubygems_version: 1.3.
|
|
107
|
+
rubygems_version: 1.3.7
|
|
98
108
|
signing_key:
|
|
99
109
|
specification_version: 3
|
|
100
110
|
summary: Pretty print Ruby objects with proper indentation and colors.
|
|
101
|
-
test_files:
|
|
102
|
-
|
|
103
|
-
- spec/active_record_spec.rb
|
|
104
|
-
- spec/awesome_print_spec.rb
|
|
105
|
-
- spec/logger_spec.rb
|
|
106
|
-
- spec/methods_spec.rb
|
|
107
|
-
- spec/spec_helper.rb
|
|
108
|
-
- spec/string_spec.rb
|
|
111
|
+
test_files: []
|
|
112
|
+
|