1
0
Fork 0
mirror of https://github.com/awesome-print/awesome_print synced 2023-03-27 23:22:34 -04:00

Skip ActionView, ActiveRecord, and MongoMapper specs if the gems are not installed

This commit is contained in:
Mike Dvorkin 2011-05-04 17:55:31 -07:00
parent 272380fe21
commit b0e47f11d2
3 changed files with 145 additions and 133 deletions

View file

@ -1,35 +1,40 @@
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
require 'action_view'
require 'ap/mixin/action_view'
begin
require 'action_view'
require 'ap/mixin/action_view'
describe "AwesomePrint ActionView extensions" do
before(:each) do
@view = ActionView::Base.new
end
describe "AwesomePrint ActionView extensions" do
before(:each) do
@view = ActionView::Base.new
end
it "should wrap ap output with <pre> tag" do
obj = 42
@view.ap(obj, :plain => true).should == '<pre class="debug_dump">42</pre>'
end
it "should wrap ap output with <pre> tag" do
obj = 42
@view.ap(obj, :plain => true).should == '<pre class="debug_dump">42</pre>'
end
it "should encode HTML entities" do
obj = " &<hello>"
@view.ap(obj, :plain => true).should == '<pre class="debug_dump">&quot; &amp;&lt;hello&gt;&quot;</pre>'
end
it "should encode HTML entities" do
obj = " &<hello>"
@view.ap(obj, :plain => true).should == '<pre class="debug_dump">&quot; &amp;&lt;hello&gt;&quot;</pre>'
end
it "should convert primary ANSI colors to HTML" do
obj = 42
[ :gray, :red, :green, :yellow, :blue, :purple, :cyan, :white ].each do |color|
@view.ap(obj, :color => { :fixnum => color }).should == %Q|<pre class="debug_dump"><font color="#{color}">42</font></pre>|
it "should convert primary ANSI colors to HTML" do
obj = 42
[ :gray, :red, :green, :yellow, :blue, :purple, :cyan, :white ].each do |color|
@view.ap(obj, :color => { :fixnum => color }).should == %Q|<pre class="debug_dump"><font color="#{color}">42</font></pre>|
end
end
it "should convert mixed ANSI colors to HTML" do
obj = 42
[ :grayish, :redish, :greenish, :yellowish, :blueish, :purpleish, :cyanish, :whiteish, :black, :pale ].zip(
[ :black, :darkred, :darkgreen, :brown, :navy, :darkmagenta, :darkcyan, :slategray, :black, :slategray ]) do |ansi, html|
@view.ap(obj, :color => { :fixnum => ansi }).should == %Q|<pre class="debug_dump"><font color="#{html}">42</font></pre>|
end
end
end
it "should convert mixed ANSI colors to HTML" do
obj = 42
[ :grayish, :redish, :greenish, :yellowish, :blueish, :purpleish, :cyanish, :whiteish, :black, :pale ].zip(
[ :black, :darkred, :darkgreen, :brown, :navy, :darkmagenta, :darkcyan, :slategray, :black, :slategray ]) do |ansi, html|
@view.ap(obj, :color => { :fixnum => ansi }).should == %Q|<pre class="debug_dump"><font color="#{html}">42</font></pre>|
end
end
rescue LoadError
puts "Skipping ActionView specs..."
end

View file

@ -1,56 +1,56 @@
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
require 'active_record'
require 'ap/mixin/active_record'
begin
require 'active_record'
require 'ap/mixin/active_record'
if defined?(::ActiveRecord)
if defined?(::ActiveRecord)
# Create tableless ActiveRecord model.
#------------------------------------------------------------------------------
class User < ActiveRecord::Base
def self.columns()
@columns ||= []
end
def self.column(name, sql_type = nil, default = nil, null = true)
columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null)
end
column :id, :integer
column :name, :string
column :rank, :integer
column :admin, :boolean
column :created_at, :datetime
def self.table_exists?
true
end
end
class SubUser < User
def self.columns
User.columns
end
end
describe "AwesomePrint/ActiveRecord" do
before(:each) do
stub_dotfile!
end
# Create tableless ActiveRecord model.
#------------------------------------------------------------------------------
describe "ActiveRecord instance" do
before(:each) do
ActiveRecord::Base.default_timezone = :utc
@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)
class User < ActiveRecord::Base
def self.columns()
@columns ||= []
end
it "display single record" do
out = @ap.send(:awesome, @diana)
str = <<-EOS.strip
def self.column(name, sql_type = nil, default = nil, null = true)
columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null)
end
column :id, :integer
column :name, :string
column :rank, :integer
column :admin, :boolean
column :created_at, :datetime
def self.table_exists?
true
end
end
class SubUser < User
def self.columns
User.columns
end
end
describe "AwesomePrint/ActiveRecord" do
before(:each) do
stub_dotfile!
end
#------------------------------------------------------------------------------
describe "ActiveRecord instance" do
before(:each) do
ActiveRecord::Base.default_timezone = :utc
@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)
str = <<-EOS.strip
#<User:0x01234567> {
:id => nil,
:name => "Diana",
@ -59,18 +59,18 @@ if defined?(::ActiveRecord)
:created_at => ?
}
EOS
if RUBY_VERSION.to_f < 1.9
str.sub!('?', 'Sat Oct 10 12:30:00 UTC 1992')
else
str.sub!('?', '1992-10-10 12:30:00 UTC')
if RUBY_VERSION.to_f < 1.9
str.sub!('?', 'Sat Oct 10 12:30:00 UTC 1992')
else
str.sub!('?', '1992-10-10 12:30:00 UTC')
end
out.gsub(/0x([a-f\d]+)/, "0x01234567").should == str
end
out.gsub(/0x([a-f\d]+)/, "0x01234567").should == str
end
it "display multiple records" do
out = @ap.send(:awesome, [ @diana, @laura ])
str = <<-EOS.strip
it "display multiple records" do
out = @ap.send(:awesome, [ @diana, @laura ])
str = <<-EOS.strip
[
[0] #<User:0x01234567> {
:id => nil,
@ -88,23 +88,23 @@ EOS
}
]
EOS
if RUBY_VERSION.to_f < 1.9
str.sub!('?', 'Sat Oct 10 12:30:00 UTC 1992')
str.sub!('!', 'Mon May 26 14:15:00 UTC 2003')
else
str.sub!('?', '1992-10-10 12:30:00 UTC')
str.sub!('!', '2003-05-26 14:15:00 UTC')
if RUBY_VERSION.to_f < 1.9
str.sub!('?', 'Sat Oct 10 12:30:00 UTC 1992')
str.sub!('!', 'Mon May 26 14:15:00 UTC 2003')
else
str.sub!('?', '1992-10-10 12:30:00 UTC')
str.sub!('!', '2003-05-26 14:15:00 UTC')
end
out.gsub(/0x([a-f\d]+)/, "0x01234567").should == str
end
out.gsub(/0x([a-f\d]+)/, "0x01234567").should == str
end
end
#------------------------------------------------------------------------------
describe "ActiveRecord class" do
it "should print the class" do
@ap = AwesomePrint.new(:plain => true)
@ap.send(:awesome, User).should == <<-EOS.strip
#------------------------------------------------------------------------------
describe "ActiveRecord class" do
it "should print the class" do
@ap = AwesomePrint.new(:plain => true)
@ap.send(:awesome, User).should == <<-EOS.strip
class User < ActiveRecord::Base {
:id => :integer,
:name => :string,
@ -112,13 +112,12 @@ class User < ActiveRecord::Base {
:admin => :boolean,
:created_at => :datetime
}
EOS
end
EOS
end
it "should print the class for non-direct subclasses of AR::Base" do
@ap = AwesomePrint.new(:plain => true)
@ap.send(:awesome, SubUser).should == <<-EOS.strip
it "should print the class for non-direct subclasses of AR::Base" do
@ap = AwesomePrint.new(:plain => true)
@ap.send(:awesome, SubUser).should == <<-EOS.strip
class SubUser < User {
:id => :integer,
:name => :string,
@ -126,9 +125,12 @@ class SubUser < User {
:admin => :boolean,
:created_at => :datetime
}
EOS
EOS
end
end
end
end
rescue LoadError
puts "Skipping ActiveRecord specs..."
end

View file

@ -1,58 +1,63 @@
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
require "mongo_mapper"
require "ap/mixin/mongo_mapper"
begin
require "mongo_mapper"
require "ap/mixin/mongo_mapper"
if defined?(MongoMapper)
class User
include MongoMapper::Document
if defined?(MongoMapper)
class User
include MongoMapper::Document
key :first_name, String
key :last_name, String
end
describe "AwesomePrint/MongoMapper" do
before :each do
@ap = AwesomePrint.new(:plain => true)
key :first_name, String
key :last_name, String
end
it "should print for a class instance" do
user = User.new(:first_name => "Al", :last_name => "Capone")
out = @ap.send(:awesome, user)
str = <<-EOS.strip
describe "AwesomePrint/MongoMapper" do
before :each do
@ap = AwesomePrint.new(:plain => true)
end
it "should print for a class instance" do
user = User.new(:first_name => "Al", :last_name => "Capone")
out = @ap.send(:awesome, user)
str = <<-EOS.strip
#<User:0x01234567> {
"_id" => BSON::ObjectId('4d9183739a546f6806000001'),
"last_name" => "Capone",
"first_name" => "Al"
}
EOS
out.gsub!(/'([\w]+){23}'/, "'4d9183739a546f6806000001'")
out.gsub!(/0x([a-f\d]+)/, "0x01234567")
out.should == str
end
out.gsub!(/'([\w]+){23}'/, "'4d9183739a546f6806000001'")
out.gsub!(/0x([a-f\d]+)/, "0x01234567")
out.should == str
end
it "should print for a class" do
@ap.send(:awesome, User).should == <<-EOS.strip
it "should print for a class" do
@ap.send(:awesome, User).should == <<-EOS.strip
class User < Object {
"_id" => :object_id,
"last_name" => :string,
"first_name" => :string
}
EOS
end
it "should print for a class when type is undefined" do
class Chamelion
include MongoMapper::Document
key :last_attribute
end
@ap.send(:awesome, Chamelion).should == <<-EOS.strip
it "should print for a class when type is undefined" do
class Chamelion
include MongoMapper::Document
key :last_attribute
end
@ap.send(:awesome, Chamelion).should == <<-EOS.strip
class Chamelion < Object {
"_id" => :object_id,
"last_attribute" => :undefined
}
EOS
end
end
end
end
rescue LoadError
puts "Skipping MongoMapper specs..."
end