mirror of
https://github.com/awesome-print/awesome_print
synced 2023-03-27 23:22:34 -04:00
Improves spec runner harness, switches to better env detection.
Does not run rails specs when running mongoid specs WIP Start of remove BRE to check tests Remove old helper of active record Use RSpec skip to skip AR specs Run ActionView only when needed Run ActiveSupport only when needed Run Mongoid only when needed Create ExtVerifier.require_dependencies Run MongoMapper only when needed Always load nokogiri specs Always load ostruct specs Run Ripple only when needed Remove :: when check for defined constants Require spec_helper directly Remove 1.8.6 old monkey patch Add some RSpec configs
This commit is contained in:
parent
69815f01b2
commit
526f907629
24 changed files with 490 additions and 526 deletions
|
@ -15,17 +15,14 @@ appraise 'rails-4.2' do
|
|||
end
|
||||
|
||||
appraise 'mongoid-3.0' do
|
||||
gem 'rails', '~> 3.2.0'
|
||||
gem 'mongoid', '~> 3.0.0'
|
||||
end
|
||||
|
||||
appraise 'mongoid-3.1' do
|
||||
gem 'rails', '~> 3.2.0'
|
||||
gem 'mongoid', '~> 3.1.0'
|
||||
end
|
||||
|
||||
appraise 'mongoid-4.0' do
|
||||
gem 'rails', '~> 4.2.0'
|
||||
gem 'mongoid', '~> 4.0.0'
|
||||
end
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
source "https://rubygems.org"
|
||||
|
||||
gem "rails", "~> 3.2.0"
|
||||
gem "mongoid", "~> 3.0.0"
|
||||
|
||||
gemspec :path => "../"
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
source "https://rubygems.org"
|
||||
|
||||
gem "rails", "~> 3.2.0"
|
||||
gem "mongoid", "~> 3.1.0"
|
||||
|
||||
gemspec :path => "../"
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
source "https://rubygems.org"
|
||||
|
||||
gem "rails", "~> 4.2.0"
|
||||
gem "mongoid", "~> 4.0.0"
|
||||
|
||||
gemspec :path => "../"
|
||||
|
|
|
@ -1,34 +1,24 @@
|
|||
require 'active_record'
|
||||
|
||||
# Required to use the column support
|
||||
module Rails
|
||||
def self.env
|
||||
{}
|
||||
if ExtVerifier.has_rails?
|
||||
# Required to use the column support
|
||||
module Rails
|
||||
def self.env
|
||||
{}
|
||||
end
|
||||
end
|
||||
|
||||
# Establish connection to in-memory SQLite DB
|
||||
ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
|
||||
|
||||
# Create the users table
|
||||
ActiveRecord::Migration.verbose = false
|
||||
ActiveRecord::Migration.create_table :users do |t|
|
||||
t.string :name
|
||||
t.integer :rank
|
||||
t.boolean :admin
|
||||
t.datetime :created_at
|
||||
end
|
||||
|
||||
# Create models
|
||||
class User < ActiveRecord::Base; end
|
||||
class SubUser < User; end
|
||||
end
|
||||
|
||||
# Establish connection to in-memory SQLite DB
|
||||
ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
|
||||
|
||||
# Create the users table
|
||||
ActiveRecord::Migration.verbose = false
|
||||
ActiveRecord::Migration.create_table :users do |t|
|
||||
t.string :name
|
||||
t.integer :rank
|
||||
t.boolean :admin
|
||||
t.datetime :created_at
|
||||
end
|
||||
|
||||
# Create models
|
||||
class User < ActiveRecord::Base; end
|
||||
class SubUser < User; end
|
||||
|
||||
|
||||
# Helper methods
|
||||
# ##############
|
||||
|
||||
# we only work with ActiveRecord 2+
|
||||
def is_usable_activerecord?
|
||||
defined?(ActiveRecord::VERSION::MAJOR) && ActiveRecord::VERSION::MAJOR >= 2
|
||||
end
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
||||
require 'spec_helper'
|
||||
|
||||
describe "AwesomePrint" do
|
||||
RSpec.describe "AwesomePrint" do
|
||||
def stub_tty!(output = true, stream = STDOUT)
|
||||
if output
|
||||
stream.instance_eval { def tty?; true; end }
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
||||
require 'spec_helper'
|
||||
|
||||
|
||||
require 'logger'
|
||||
require 'awesome_print/core_ext/logger'
|
||||
|
||||
describe "AwesomePrint logging extensions" do
|
||||
RSpec.describe "AwesomePrint logging extensions" do
|
||||
before(:all) do
|
||||
@logger = Logger.new('/dev/null') rescue Logger.new('nul')
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
||||
require 'spec_helper'
|
||||
|
||||
describe "String extensions" do
|
||||
RSpec.describe "String extensions" do
|
||||
[ :gray, :red, :green, :yellow, :blue, :purple, :cyan, :white ].each_with_index do |color, i|
|
||||
it "should have #{color} color" do
|
||||
expect(color.to_s.send(color)).to eq("\e[1;#{30+i}m#{color}\e[0m")
|
||||
|
|
|
@ -1,25 +1,18 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
||||
require 'spec_helper'
|
||||
|
||||
begin
|
||||
require 'action_view'
|
||||
require 'awesome_print/ext/action_view'
|
||||
RSpec.describe "AwesomePrint ActionView extensions", skip: ->{ !ExtVerifier.has_rails? }.call do
|
||||
|
||||
describe "AwesomePrint ActionView extensions" do
|
||||
before do
|
||||
@view = ActionView::Base.new
|
||||
end
|
||||
|
||||
it "uses HTML and adds 'debug_dump' class to plain <pre> tag" do
|
||||
markup = rand
|
||||
expect(@view.ap(markup, :plain => true)).to eq(%Q|<pre class="debug_dump">#{markup}</pre>|)
|
||||
end
|
||||
|
||||
it "uses HTML and adds 'debug_dump' class to colorized <pre> tag" do
|
||||
markup = ' &<hello>'
|
||||
expect(@view.ap(markup)).to eq('<pre class="debug_dump"><kbd style="color:brown">" &<hello>"</kbd></pre>')
|
||||
end
|
||||
before do
|
||||
@view = ActionView::Base.new
|
||||
end
|
||||
|
||||
rescue LoadError => error
|
||||
puts "Skipping ActionView specs: #{error}"
|
||||
it "uses HTML and adds 'debug_dump' class to plain <pre> tag" do
|
||||
markup = rand
|
||||
expect(@view.ap(markup, :plain => true)).to eq(%Q|<pre class="debug_dump">#{markup}</pre>|)
|
||||
end
|
||||
|
||||
it "uses HTML and adds 'debug_dump' class to colorized <pre> tag" do
|
||||
markup = ' &<hello>'
|
||||
expect(@view.ap(markup)).to eq('<pre class="debug_dump"><kbd style="color:brown">" &<hello>"</kbd></pre>')
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,28 +1,24 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
||||
require 'spec_helper'
|
||||
require 'active_record_helper'
|
||||
|
||||
begin
|
||||
require 'awesome_print/ext/active_record'
|
||||
require File.expand_path(File.dirname(__FILE__) + '/../active_record_helper')
|
||||
RSpec.describe "AwesomePrint/ActiveRecord", skip: ->{ !ExtVerifier.has_rails? }.call do
|
||||
|
||||
if is_usable_activerecord?
|
||||
before do
|
||||
stub_dotfile!
|
||||
end
|
||||
|
||||
describe "AwesomePrint/ActiveRecord" do
|
||||
before do
|
||||
stub_dotfile!
|
||||
end
|
||||
#------------------------------------------------------------------------------
|
||||
describe "ActiveRecord instance, attributes only (default)" do
|
||||
before 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::Inspector.new(:plain => true, :sort_keys => true)
|
||||
end
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
describe "ActiveRecord instance, attributes only (default)" do
|
||||
before 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::Inspector.new(:plain => true, :sort_keys => true)
|
||||
end
|
||||
|
||||
it "display single record" do
|
||||
out = @ap.send(:awesome, @diana)
|
||||
str = <<-EOS.strip
|
||||
it "display single record" do
|
||||
out = @ap.send(:awesome, @diana)
|
||||
str = <<-EOS.strip
|
||||
#<User:0x01234567> {
|
||||
:admin => false,
|
||||
:created_at => ?,
|
||||
|
@ -30,18 +26,18 @@ begin
|
|||
:name => "Diana",
|
||||
:rank => 1
|
||||
}
|
||||
EOS
|
||||
if RUBY_VERSION < '1.9'
|
||||
str.sub!('?', 'Sat Oct 10 12:30:00 UTC 1992')
|
||||
else
|
||||
str.sub!('?', '1992-10-10 12:30:00 UTC')
|
||||
end
|
||||
expect(out.gsub(/0x([a-f\d]+)/, "0x01234567")).to eq(str)
|
||||
end
|
||||
EOS
|
||||
if RUBY_VERSION < '1.9'
|
||||
str.sub!('?', 'Sat Oct 10 12:30:00 UTC 1992')
|
||||
else
|
||||
str.sub!('?', '1992-10-10 12:30:00 UTC')
|
||||
end
|
||||
expect(out.gsub(/0x([a-f\d]+)/, "0x01234567")).to eq(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> {
|
||||
:admin => false,
|
||||
|
@ -58,32 +54,32 @@ EOS
|
|||
:rank => 2
|
||||
}
|
||||
]
|
||||
EOS
|
||||
if RUBY_VERSION < '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
|
||||
expect(out.gsub(/0x([a-f\d]+)/, "0x01234567")).to eq(str)
|
||||
end
|
||||
EOS
|
||||
if RUBY_VERSION < '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
|
||||
expect(out.gsub(/0x([a-f\d]+)/, "0x01234567")).to eq(str)
|
||||
end
|
||||
end
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
describe "ActiveRecord instance (raw)" do
|
||||
before 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::Inspector.new(:plain => true, :sort_keys => true, :raw => true)
|
||||
end
|
||||
#------------------------------------------------------------------------------
|
||||
describe "ActiveRecord instance (raw)" do
|
||||
before 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::Inspector.new(:plain => true, :sort_keys => true, :raw => true)
|
||||
end
|
||||
|
||||
it "display single record" do
|
||||
out = @ap.send(:awesome, @diana)
|
||||
it "display single record" do
|
||||
out = @ap.send(:awesome, @diana)
|
||||
|
||||
if activerecord_4_2?
|
||||
str = <<-EOS.strip
|
||||
if activerecord_4_2?
|
||||
str = <<-EOS.strip
|
||||
#<User:0x01234567
|
||||
@_start_transaction_state = {},
|
||||
@aggregation_cache = {},
|
||||
|
@ -207,9 +203,9 @@ EOS
|
|||
"rank" => nil
|
||||
}
|
||||
>
|
||||
EOS
|
||||
elsif activerecord_4_1?
|
||||
str = <<-EOS.strip
|
||||
EOS
|
||||
elsif activerecord_4_1?
|
||||
str = <<-EOS.strip
|
||||
#<User:0x01234567
|
||||
@_start_transaction_state = {},
|
||||
@aggregation_cache = {},
|
||||
|
@ -307,9 +303,9 @@ EOS
|
|||
"rank" => nil
|
||||
}
|
||||
>
|
||||
EOS
|
||||
elsif activerecord_4_0?
|
||||
str = <<-EOS.strip
|
||||
EOS
|
||||
elsif activerecord_4_0?
|
||||
str = <<-EOS.strip
|
||||
#<User:0x01234567
|
||||
@_start_transaction_state = {},
|
||||
@aggregation_cache = {},
|
||||
|
@ -408,9 +404,9 @@ EOS
|
|||
"rank" => nil
|
||||
}
|
||||
>
|
||||
EOS
|
||||
elsif activerecord_3_2?
|
||||
str = <<-EOS.strip
|
||||
EOS
|
||||
elsif activerecord_3_2?
|
||||
str = <<-EOS.strip
|
||||
#<User:0x01234567
|
||||
@aggregation_cache = {},
|
||||
@attributes_cache = {},
|
||||
|
@ -435,17 +431,17 @@ EOS
|
|||
"rank" => nil
|
||||
}
|
||||
>
|
||||
EOS
|
||||
end
|
||||
str.sub!('?', '1992-10-10 12:30:00')
|
||||
expect(out.gsub(/0x([a-f\d]+)/, "0x01234567")).to eq(str)
|
||||
end
|
||||
EOS
|
||||
end
|
||||
str.sub!('?', '1992-10-10 12:30:00')
|
||||
expect(out.gsub(/0x([a-f\d]+)/, "0x01234567")).to eq(str)
|
||||
end
|
||||
|
||||
it "display multiple records" do
|
||||
out = @ap.send(:awesome, [ @diana, @laura ])
|
||||
it "display multiple records" do
|
||||
out = @ap.send(:awesome, [ @diana, @laura ])
|
||||
|
||||
if activerecord_4_2?
|
||||
str = <<-EOS.strip
|
||||
if activerecord_4_2?
|
||||
str = <<-EOS.strip
|
||||
[
|
||||
[0] #<User:0x01234567
|
||||
@_start_transaction_state = {},
|
||||
|
@ -694,9 +690,9 @@ EOS
|
|||
}
|
||||
>
|
||||
]
|
||||
EOS
|
||||
elsif activerecord_4_1?
|
||||
str = <<-EOS.strip
|
||||
EOS
|
||||
elsif activerecord_4_1?
|
||||
str = <<-EOS.strip
|
||||
[
|
||||
[0] #<User:0x01234567
|
||||
@_start_transaction_state = {},
|
||||
|
@ -893,9 +889,9 @@ EOS
|
|||
}
|
||||
>
|
||||
]
|
||||
EOS
|
||||
elsif activerecord_4_0?
|
||||
str = <<-EOS.strip
|
||||
EOS
|
||||
elsif activerecord_4_0?
|
||||
str = <<-EOS.strip
|
||||
[
|
||||
[0] #<User:0x01234567
|
||||
@_start_transaction_state = {},
|
||||
|
@ -1094,9 +1090,9 @@ EOS
|
|||
}
|
||||
>
|
||||
]
|
||||
EOS
|
||||
elsif activerecord_3_2?
|
||||
str = <<-EOS.strip
|
||||
EOS
|
||||
elsif activerecord_3_2?
|
||||
str = <<-EOS.strip
|
||||
[
|
||||
[0] #<User:0x01234567
|
||||
@aggregation_cache = {},
|
||||
|
@ -1147,22 +1143,22 @@ EOS
|
|||
}
|
||||
>
|
||||
]
|
||||
EOS
|
||||
end
|
||||
str.sub!('?', '1992-10-10 12:30:00')
|
||||
str.sub!('?', '2003-05-26 14:15:00')
|
||||
expect(out.gsub(/0x([a-f\d]+)/, "0x01234567")).to eq(str)
|
||||
end
|
||||
EOS
|
||||
end
|
||||
str.sub!('?', '1992-10-10 12:30:00')
|
||||
str.sub!('?', '2003-05-26 14:15:00')
|
||||
expect(out.gsub(/0x([a-f\d]+)/, "0x01234567")).to eq(str)
|
||||
end
|
||||
end
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
describe "ActiveRecord class" do
|
||||
before do
|
||||
@ap = AwesomePrint::Inspector.new(:plain => true)
|
||||
end
|
||||
#------------------------------------------------------------------------------
|
||||
describe "ActiveRecord class" do
|
||||
before do
|
||||
@ap = AwesomePrint::Inspector.new(:plain => true)
|
||||
end
|
||||
|
||||
it "should print the class" do
|
||||
expect(@ap.send(:awesome, User)).to eq <<-EOS.strip
|
||||
it "should print the class" do
|
||||
expect(@ap.send(:awesome, User)).to eq <<-EOS.strip
|
||||
class User < ActiveRecord::Base {
|
||||
:id => :integer,
|
||||
:name => :string,
|
||||
|
@ -1170,12 +1166,12 @@ class User < ActiveRecord::Base {
|
|||
:admin => :boolean,
|
||||
:created_at => :datetime
|
||||
}
|
||||
EOS
|
||||
end
|
||||
EOS
|
||||
end
|
||||
|
||||
it "should print the class for non-direct subclasses of ActiveRecord::Base" do
|
||||
out = @ap.send(:awesome, SubUser)
|
||||
expect(out).to eq <<-EOS.strip
|
||||
it "should print the class for non-direct subclasses of ActiveRecord::Base" do
|
||||
out = @ap.send(:awesome, SubUser)
|
||||
expect(out).to eq <<-EOS.strip
|
||||
class SubUser < User {
|
||||
:id => :integer,
|
||||
:name => :string,
|
||||
|
@ -1183,51 +1179,47 @@ class SubUser < User {
|
|||
:admin => :boolean,
|
||||
:created_at => :datetime
|
||||
}
|
||||
EOS
|
||||
end
|
||||
EOS
|
||||
end
|
||||
|
||||
it "should print ActiveRecord::Base objects (ex. ancestors)" do
|
||||
expect { @ap.send(:awesome, User.ancestors) }.not_to raise_error
|
||||
end
|
||||
end
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
describe "ActiveRecord methods formatting" do
|
||||
before do
|
||||
@ap = AwesomePrint::Inspector.new(:plain => true)
|
||||
end
|
||||
|
||||
it "should format class methods properly" do
|
||||
# spec 1
|
||||
out = @ap.send(:awesome, User.methods.grep(/first/))
|
||||
|
||||
if ActiveRecord::VERSION::STRING >= "3.2"
|
||||
if RUBY_VERSION >= "1.9"
|
||||
expect(out).to match(/\sfirst\(\*args,\s&block\)\s+Class \(ActiveRecord::Querying\)/)
|
||||
else
|
||||
expect(out).to match(/\sfirst\(\*arg1\)\s+Class \(ActiveRecord::Querying\)/)
|
||||
end
|
||||
else
|
||||
expect(out).to match(/\sfirst\(\*arg.*?\)\s+User \(ActiveRecord::Base\)/)
|
||||
end
|
||||
|
||||
# spec 2
|
||||
out = @ap.send(:awesome, User.methods.grep(/primary_key/))
|
||||
expect(out).to match(/\sprimary_key\(.*?\)\s+Class \(ActiveRecord::AttributeMethods::PrimaryKey::ClassMethods\)/)
|
||||
|
||||
# spec 3
|
||||
out = @ap.send(:awesome, User.methods.grep(/validate/))
|
||||
|
||||
if ActiveRecord::VERSION::MAJOR < 3
|
||||
expect(out).to match(/\svalidate\(\*arg.*?\)\s+User \(ActiveRecord::Base\)/)
|
||||
else
|
||||
expect(out).to match(/\svalidate\(\*arg.*?\)\s+Class \(ActiveModel::Validations::ClassMethods\)/)
|
||||
end
|
||||
|
||||
it "should print ActiveRecord::Base objects (ex. ancestors)" do
|
||||
expect { @ap.send(:awesome, User.ancestors) }.not_to raise_error
|
||||
end
|
||||
end
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
describe "ActiveRecord methods formatting" do
|
||||
before do
|
||||
@ap = AwesomePrint::Inspector.new(:plain => true)
|
||||
end
|
||||
|
||||
it "should format class methods properly" do
|
||||
# spec 1
|
||||
out = @ap.send(:awesome, User.methods.grep(/first/))
|
||||
|
||||
if ActiveRecord::VERSION::STRING >= "3.2"
|
||||
if RUBY_VERSION >= "1.9"
|
||||
expect(out).to match(/\sfirst\(\*args,\s&block\)\s+Class \(ActiveRecord::Querying\)/)
|
||||
else
|
||||
expect(out).to match(/\sfirst\(\*arg1\)\s+Class \(ActiveRecord::Querying\)/)
|
||||
end
|
||||
else
|
||||
expect(out).to match(/\sfirst\(\*arg.*?\)\s+User \(ActiveRecord::Base\)/)
|
||||
end
|
||||
|
||||
# spec 2
|
||||
out = @ap.send(:awesome, User.methods.grep(/primary_key/))
|
||||
expect(out).to match(/\sprimary_key\(.*?\)\s+Class \(ActiveRecord::AttributeMethods::PrimaryKey::ClassMethods\)/)
|
||||
|
||||
# spec 3
|
||||
out = @ap.send(:awesome, User.methods.grep(/validate/))
|
||||
|
||||
if ActiveRecord::VERSION::MAJOR < 3
|
||||
expect(out).to match(/\svalidate\(\*arg.*?\)\s+User \(ActiveRecord::Base\)/)
|
||||
else
|
||||
expect(out).to match(/\svalidate\(\*arg.*?\)\s+Class \(ActiveModel::Validations::ClassMethods\)/)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
rescue LoadError => error
|
||||
puts "Skipping ActiveRecord specs: #{error}"
|
||||
end
|
||||
|
|
|
@ -1,35 +1,27 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
||||
require 'spec_helper'
|
||||
|
||||
begin
|
||||
require 'active_support/all'
|
||||
require 'awesome_print/ext/active_support'
|
||||
|
||||
describe "AwesomePrint::ActiveSupport" do
|
||||
before do
|
||||
stub_dotfile!
|
||||
@ap = AwesomePrint::Inspector.new
|
||||
end
|
||||
|
||||
it "should format ActiveSupport::TimeWithZone as regular Time" do
|
||||
Time.zone = 'Eastern Time (US & Canada)'
|
||||
time = Time.utc(2007, 2, 10, 20, 30, 45).in_time_zone
|
||||
expect(@ap.send(:awesome, time)).to eq("\e[0;32mSat, 10 Feb 2007 15:30:45 EST -05:00\e[0m")
|
||||
end
|
||||
|
||||
it "should format HashWithIndifferentAccess as regular Hash" do
|
||||
hash = HashWithIndifferentAccess.new({ :hello => "world" })
|
||||
expect(@ap.send(:awesome, hash)).to eq("{\n \"hello\"\e[0;37m => \e[0m\e[0;33m\"world\"\e[0m\n}")
|
||||
end
|
||||
|
||||
# ActiveSupport sticks in instance variables to the date object. Make sure
|
||||
# we ignore that and format Date instance as regular date.
|
||||
it "should formate Date object as date" do
|
||||
date = Date.new(2003, 5, 26)
|
||||
expect(date.ai(:plain => true)).to eq("Mon, 26 May 2003")
|
||||
expect(date.ai).to eq("\e[0;32mMon, 26 May 2003\e[0m")
|
||||
end
|
||||
RSpec.describe "AwesomePrint::ActiveSupport", skip: ->{ !ExtVerifier.has_rails? }.call do
|
||||
before do
|
||||
stub_dotfile!
|
||||
@ap = AwesomePrint::Inspector.new
|
||||
end
|
||||
|
||||
rescue LoadError => error
|
||||
puts "Skipping ActiveSupport specs: #{error}"
|
||||
it "should format ActiveSupport::TimeWithZone as regular Time" do
|
||||
Time.zone = 'Eastern Time (US & Canada)'
|
||||
time = Time.utc(2007, 2, 10, 20, 30, 45).in_time_zone
|
||||
expect(@ap.send(:awesome, time)).to eq("\e[0;32mSat, 10 Feb 2007 15:30:45 EST -05:00\e[0m")
|
||||
end
|
||||
|
||||
it "should format HashWithIndifferentAccess as regular Hash" do
|
||||
hash = HashWithIndifferentAccess.new({ :hello => "world" })
|
||||
expect(@ap.send(:awesome, hash)).to eq("{\n \"hello\"\e[0;37m => \e[0m\e[0;33m\"world\"\e[0m\n}")
|
||||
end
|
||||
|
||||
# ActiveSupport sticks in instance variables to the date object. Make sure
|
||||
# we ignore that and format Date instance as regular date.
|
||||
it "should formate Date object as date" do
|
||||
date = Date.new(2003, 5, 26)
|
||||
expect(date.ai(:plain => true)).to eq("Mon, 26 May 2003")
|
||||
expect(date.ai).to eq("\e[0;32mMon, 26 May 2003\e[0m")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
||||
require 'spec_helper'
|
||||
|
||||
begin
|
||||
require "mongo_mapper"
|
||||
require "awesome_print/ext/mongo_mapper"
|
||||
RSpec.describe "AwesomePrint/MongoMapper", skip: ->{ !ExtVerifier.has_mongo_mapper? }.call do
|
||||
|
||||
describe "AwesomePrint/MongoMapper" do
|
||||
if ExtVerifier.has_mongo_mapper?
|
||||
before :all do
|
||||
class MongoUser
|
||||
include MongoMapper::Document
|
||||
|
@ -18,25 +16,26 @@ begin
|
|||
Object.instance_eval{ remove_const :MongoUser }
|
||||
Object.instance_eval{ remove_const :Chamelion }
|
||||
end
|
||||
end
|
||||
|
||||
before do
|
||||
stub_dotfile!
|
||||
@ap = AwesomePrint::Inspector.new(:plain => true, :sort_keys => true)
|
||||
end
|
||||
before do
|
||||
stub_dotfile!
|
||||
@ap = AwesomePrint::Inspector.new(:plain => true, :sort_keys => true)
|
||||
end
|
||||
|
||||
describe "with the raw option set to true" do
|
||||
# before { @ap.options[:raw] = true }
|
||||
before { @ap = AwesomePrint::Inspector.new(:plain => true, :sort_keys => true, :raw => true) }
|
||||
describe "with the raw option set to true" do
|
||||
# before { @ap.options[:raw] = true }
|
||||
before { @ap = AwesomePrint::Inspector.new(:plain => true, :sort_keys => true, :raw => true) }
|
||||
|
||||
it "should print class instance" do
|
||||
user = MongoUser.new(:first_name => "Al", :last_name => "Capone")
|
||||
it "should print class instance" do
|
||||
user = MongoUser.new(:first_name => "Al", :last_name => "Capone")
|
||||
|
||||
out = @ap.send(:awesome, user)
|
||||
out.gsub!(/#\<Proc:.+?\>/, 'AWESOME_PRINT_PROC_STUB')
|
||||
out.gsub!(/BSON::ObjectId\('[\da-f]+?'\)/, "BSON::ObjectId('123456789')")
|
||||
out = @ap.send(:awesome, user)
|
||||
out.gsub!(/#\<Proc:.+?\>/, 'AWESOME_PRINT_PROC_STUB')
|
||||
out.gsub!(/BSON::ObjectId\('[\da-f]+?'\)/, "BSON::ObjectId('123456789')")
|
||||
|
||||
if MongoMapper::Version >= "0.13"
|
||||
str = <<-EOS.strip
|
||||
if MongoMapper::Version >= "0.13"
|
||||
str = <<-EOS.strip
|
||||
#<MongoUser:0x01234567
|
||||
@__mm_default_keys = [
|
||||
[0] #<MongoMapper::Plugins::Keys::Key:0x01234567
|
||||
|
@ -111,9 +110,9 @@ begin
|
|||
"last_name" => nil
|
||||
}
|
||||
>
|
||||
EOS
|
||||
else
|
||||
str = <<-EOS.strip
|
||||
EOS
|
||||
else
|
||||
str = <<-EOS.strip
|
||||
#<MongoUser:0x01234567
|
||||
@_new = true,
|
||||
attr_accessor :first_name = "Al",
|
||||
|
@ -125,38 +124,40 @@ EOS
|
|||
attr_reader :first_name_before_type_cast = "Al",
|
||||
attr_reader :last_name_before_type_cast = "Capone"
|
||||
>
|
||||
EOS
|
||||
end
|
||||
out.gsub!(/0x([a-f\d]+)/, "0x01234567")
|
||||
expect(out).to eq(str)
|
||||
EOS
|
||||
end
|
||||
out.gsub!(/0x([a-f\d]+)/, "0x01234567")
|
||||
expect(out).to eq(str)
|
||||
end
|
||||
|
||||
it "should print the class" do
|
||||
expect(@ap.send(:awesome, MongoUser)).to eq <<-EOS.strip
|
||||
it "should print the class" do
|
||||
expect(@ap.send(:awesome, MongoUser)).to eq <<-EOS.strip
|
||||
class MongoUser < Object {
|
||||
"_id" => :object_id,
|
||||
"first_name" => :string,
|
||||
"last_name" => :string
|
||||
}
|
||||
EOS
|
||||
EOS
|
||||
end
|
||||
|
||||
it "should print the class when type is undefined" do
|
||||
class Chamelion
|
||||
include MongoMapper::Document
|
||||
key :last_attribute
|
||||
end
|
||||
|
||||
it "should print the class when type is undefined" do
|
||||
class Chamelion
|
||||
include MongoMapper::Document
|
||||
key :last_attribute
|
||||
end
|
||||
|
||||
expect(@ap.send(:awesome, Chamelion)).to eq <<-EOS.strip
|
||||
expect(@ap.send(:awesome, Chamelion)).to eq <<-EOS.strip
|
||||
class Chamelion < Object {
|
||||
"_id" => :object_id,
|
||||
"last_attribute" => :undefined
|
||||
}
|
||||
EOS
|
||||
end
|
||||
EOS
|
||||
end
|
||||
end
|
||||
|
||||
describe "with associations" do
|
||||
describe "with associations" do
|
||||
|
||||
if ExtVerifier.has_mongo_mapper?
|
||||
before :all do
|
||||
class Child
|
||||
include MongoMapper::EmbeddedDocument
|
||||
|
@ -176,79 +177,80 @@ EOS
|
|||
one :sibling
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "with show associations turned off (default)" do
|
||||
it "should render the class as normal" do
|
||||
expect(@ap.send(:awesome, Parent)).to eq <<-EOS.strip
|
||||
describe "with show associations turned off (default)" do
|
||||
it "should render the class as normal" do
|
||||
expect(@ap.send(:awesome, Parent)).to eq <<-EOS.strip
|
||||
class Parent < Object {
|
||||
"_id" => :object_id,
|
||||
"name" => :undefined
|
||||
}
|
||||
EOS
|
||||
end
|
||||
EOS
|
||||
end
|
||||
|
||||
it "should render an instance as normal" do
|
||||
parent = Parent.new(:name => 'test')
|
||||
out = @ap.send(:awesome, parent)
|
||||
str = <<-EOS.strip
|
||||
it "should render an instance as normal" do
|
||||
parent = Parent.new(:name => 'test')
|
||||
out = @ap.send(:awesome, parent)
|
||||
str = <<-EOS.strip
|
||||
#<Parent:0x01234567> {
|
||||
"_id" => BSON::ObjectId('4d9183739a546f6806000001'),
|
||||
"name" => "test"
|
||||
}
|
||||
EOS
|
||||
out.gsub!(/'([\w]+){23}'/, "'4d9183739a546f6806000001'")
|
||||
out.gsub!(/0x([a-f\d]+)/, "0x01234567")
|
||||
expect(out).to eq(str)
|
||||
end
|
||||
EOS
|
||||
out.gsub!(/'([\w]+){23}'/, "'4d9183739a546f6806000001'")
|
||||
out.gsub!(/0x([a-f\d]+)/, "0x01234567")
|
||||
expect(out).to eq(str)
|
||||
end
|
||||
end
|
||||
|
||||
describe "with show associations turned on and inline embedded turned off" do
|
||||
before :each do
|
||||
@ap = AwesomePrint::Inspector.new(:plain => true, :mongo_mapper => { :show_associations => true })
|
||||
end
|
||||
|
||||
describe "with show associations turned on and inline embedded turned off" do
|
||||
before :each do
|
||||
@ap = AwesomePrint::Inspector.new(:plain => true, :mongo_mapper => { :show_associations => true })
|
||||
end
|
||||
|
||||
it "should render the class with associations shown" do
|
||||
expect(@ap.send(:awesome, Parent)).to eq <<-EOS.strip
|
||||
it "should render the class with associations shown" do
|
||||
expect(@ap.send(:awesome, Parent)).to eq <<-EOS.strip
|
||||
class Parent < Object {
|
||||
"_id" => :object_id,
|
||||
"name" => :undefined,
|
||||
"child" => embeds one Child,
|
||||
"sibling" => one Sibling
|
||||
}
|
||||
EOS
|
||||
end
|
||||
EOS
|
||||
end
|
||||
|
||||
it "should render an instance with associations shown" do
|
||||
parent = Parent.new(:name => 'test')
|
||||
out = @ap.send(:awesome, parent)
|
||||
str = <<-EOS.strip
|
||||
it "should render an instance with associations shown" do
|
||||
parent = Parent.new(:name => 'test')
|
||||
out = @ap.send(:awesome, parent)
|
||||
str = <<-EOS.strip
|
||||
#<Parent:0x01234567> {
|
||||
"_id" => BSON::ObjectId('4d9183739a546f6806000001'),
|
||||
"name" => "test",
|
||||
"child" => embeds one Child,
|
||||
"sibling" => one Sibling
|
||||
}
|
||||
EOS
|
||||
out.gsub!(/'([\w]+){23}'/, "'4d9183739a546f6806000001'")
|
||||
out.gsub!(/0x([a-f\d]+)/, "0x01234567")
|
||||
expect(out).to eq(str)
|
||||
end
|
||||
EOS
|
||||
out.gsub!(/'([\w]+){23}'/, "'4d9183739a546f6806000001'")
|
||||
out.gsub!(/0x([a-f\d]+)/, "0x01234567")
|
||||
expect(out).to eq(str)
|
||||
end
|
||||
end
|
||||
|
||||
describe "with show associations turned on and inline embedded turned on" do
|
||||
before :each do
|
||||
@ap = AwesomePrint::Inspector.new(:plain => true,
|
||||
:mongo_mapper => {
|
||||
:show_associations => true,
|
||||
:inline_embedded => true
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
describe "with show associations turned on and inline embedded turned on" do
|
||||
before :each do
|
||||
@ap = AwesomePrint::Inspector.new(:plain => true,
|
||||
:mongo_mapper => {
|
||||
:show_associations => true,
|
||||
:inline_embedded => true
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
it "should render an instance with associations shown and embeds there" do
|
||||
parent = Parent.new(:name => 'test', :child => Child.new(:data => 5))
|
||||
out = @ap.send(:awesome, parent)
|
||||
str = <<-EOS.strip
|
||||
it "should render an instance with associations shown and embeds there" do
|
||||
parent = Parent.new(:name => 'test', :child => Child.new(:data => 5))
|
||||
out = @ap.send(:awesome, parent)
|
||||
str = <<-EOS.strip
|
||||
#<Parent:0x01234567> {
|
||||
"_id" => BSON::ObjectId('4d9183739a546f6806000001'),
|
||||
"name" => "test",
|
||||
|
@ -258,15 +260,11 @@ EOS
|
|||
},
|
||||
"sibling" => one Sibling
|
||||
}
|
||||
EOS
|
||||
out.gsub!(/'([\w]+){23}'/, "'4d9183739a546f6806000001'")
|
||||
out.gsub!(/0x([a-f\d]+)/, "0x01234567")
|
||||
expect(out).to eq(str)
|
||||
end
|
||||
EOS
|
||||
out.gsub!(/'([\w]+){23}'/, "'4d9183739a546f6806000001'")
|
||||
out.gsub!(/0x([a-f\d]+)/, "0x01234567")
|
||||
expect(out).to eq(str)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
rescue LoadError => error
|
||||
puts "Skipping MongoMapper specs: #{error}"
|
||||
end
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
||||
require 'spec_helper'
|
||||
|
||||
begin
|
||||
require "mongoid"
|
||||
require "awesome_print/ext/mongoid"
|
||||
RSpec.describe "AwesomePrint/Mongoid", skip: ->{ !ExtVerifier.has_mongoid? }.call do
|
||||
|
||||
describe "AwesomePrint/Mongoid" do
|
||||
if ExtVerifier.has_mongoid?
|
||||
before :all do
|
||||
class MongoUser
|
||||
include Mongoid::Document
|
||||
|
@ -18,94 +16,91 @@ begin
|
|||
Object.instance_eval{ remove_const :MongoUser }
|
||||
Object.instance_eval{ remove_const :Chamelion }
|
||||
end
|
||||
end
|
||||
|
||||
before do
|
||||
stub_dotfile!
|
||||
@ap = AwesomePrint::Inspector.new :plain => true, :sort_keys => true
|
||||
end
|
||||
before do
|
||||
stub_dotfile!
|
||||
@ap = AwesomePrint::Inspector.new :plain => true, :sort_keys => true
|
||||
end
|
||||
|
||||
it "should print class instance" do
|
||||
user = MongoUser.new :first_name => "Al", :last_name => "Capone"
|
||||
out = @ap.send :awesome, user
|
||||
it "should print class instance" do
|
||||
user = MongoUser.new :first_name => "Al", :last_name => "Capone"
|
||||
out = @ap.send :awesome, user
|
||||
|
||||
object_id = user.id.inspect
|
||||
str = <<-EOS.strip
|
||||
object_id = user.id.inspect
|
||||
str = <<-EOS.strip
|
||||
#<MongoUser:0x01234567> {
|
||||
:_id => #{object_id},
|
||||
:first_name => "Al",
|
||||
:last_name => "Capone"
|
||||
}
|
||||
EOS
|
||||
out.gsub!(/0x([a-f\d]+)/, "0x01234567")
|
||||
expect(out).to eq(str)
|
||||
end
|
||||
EOS
|
||||
out.gsub!(/0x([a-f\d]+)/, "0x01234567")
|
||||
expect(out).to eq(str)
|
||||
end
|
||||
|
||||
it "should print the class" do
|
||||
class_spec = if mongoid_3_0?
|
||||
<<-EOS.strip
|
||||
it "should print the class" do
|
||||
class_spec = if mongoid_3_0?
|
||||
<<-EOS.strip
|
||||
class MongoUser < Object {
|
||||
:_id => :"moped/bson/object_id",
|
||||
:_type => :string,
|
||||
:first_name => :string,
|
||||
:last_name => :string
|
||||
}
|
||||
EOS
|
||||
elsif mongoid_3_1?
|
||||
<<-EOS.strip
|
||||
EOS
|
||||
elsif mongoid_3_1?
|
||||
<<-EOS.strip
|
||||
class MongoUser < Object {
|
||||
:_id => :"moped/bson/object_id",
|
||||
:first_name => :string,
|
||||
:last_name => :string
|
||||
}
|
||||
EOS
|
||||
elsif mongoid_4_0?
|
||||
<<-EOS.strip
|
||||
EOS
|
||||
elsif mongoid_4_0?
|
||||
<<-EOS.strip
|
||||
class MongoUser < Object {
|
||||
:_id => :"bson/object_id",
|
||||
:first_name => :string,
|
||||
:last_name => :string
|
||||
}
|
||||
EOS
|
||||
end
|
||||
EOS
|
||||
end
|
||||
|
||||
expect(@ap.send(:awesome, MongoUser)).to eq class_spec
|
||||
expect(@ap.send(:awesome, MongoUser)).to eq class_spec
|
||||
end
|
||||
|
||||
it "should print the class when type is undefined" do
|
||||
class Chamelion
|
||||
include Mongoid::Document
|
||||
field :last_attribute
|
||||
end
|
||||
|
||||
it "should print the class when type is undefined" do
|
||||
class Chamelion
|
||||
include Mongoid::Document
|
||||
field :last_attribute
|
||||
end
|
||||
|
||||
class_spec = if mongoid_3_0?
|
||||
<<-EOS.strip
|
||||
class_spec = if mongoid_3_0?
|
||||
<<-EOS.strip
|
||||
class Chamelion < Object {
|
||||
:_id => :"moped/bson/object_id",
|
||||
:_type => :string,
|
||||
:last_attribute => :object
|
||||
}
|
||||
EOS
|
||||
elsif mongoid_3_1?
|
||||
<<-EOS.strip
|
||||
EOS
|
||||
elsif mongoid_3_1?
|
||||
<<-EOS.strip
|
||||
class Chamelion < Object {
|
||||
:_id => :"moped/bson/object_id",
|
||||
:last_attribute => :object
|
||||
}
|
||||
EOS
|
||||
elsif mongoid_4_0?
|
||||
<<-EOS.strip
|
||||
EOS
|
||||
elsif mongoid_4_0?
|
||||
<<-EOS.strip
|
||||
class Chamelion < Object {
|
||||
:_id => :"bson/object_id",
|
||||
:last_attribute => :object
|
||||
}
|
||||
EOS
|
||||
end
|
||||
EOS
|
||||
end
|
||||
|
||||
|
||||
expect(@ap.send(:awesome, Chamelion)).to eq class_spec
|
||||
end
|
||||
expect(@ap.send(:awesome, Chamelion)).to eq class_spec
|
||||
end
|
||||
|
||||
rescue LoadError => error
|
||||
puts "Skipping Mongoid specs: #{error}"
|
||||
end
|
||||
|
|
|
@ -1,41 +1,37 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
||||
require 'spec_helper'
|
||||
|
||||
begin
|
||||
require "nokogiri"
|
||||
require "awesome_print/ext/nokogiri"
|
||||
RSpec.describe "AwesomePrint/Nokogiri" do
|
||||
before do
|
||||
stub_dotfile!
|
||||
end
|
||||
|
||||
describe "AwesomePrint/Nokogiri" do
|
||||
before do
|
||||
stub_dotfile!
|
||||
end
|
||||
|
||||
it "should colorize tags" do
|
||||
xml = Nokogiri::XML('<html><body><h1></h1></body></html>')
|
||||
expect(xml.ai).to eq <<-EOS
|
||||
it "should colorize tags" do
|
||||
xml = Nokogiri::XML('<html><body><h1></h1></body></html>')
|
||||
expect(xml.ai).to eq <<-EOS
|
||||
<?xml version=\"1.0\"?>\e[1;32m
|
||||
\e[0m<\e[1;36mhtml\e[0m>\e[1;32m
|
||||
\e[0m<\e[1;36mbody\e[0m>\e[1;32m
|
||||
\e[0m<\e[1;36mh1\e[0m/>\e[1;32m
|
||||
\e[0m<\e[1;36m/body\e[0m>\e[1;32m
|
||||
\e[0m<\e[1;36m/html\e[0m>
|
||||
EOS
|
||||
end
|
||||
EOS
|
||||
end
|
||||
|
||||
it "should colorize contents" do
|
||||
xml = Nokogiri::XML('<html><body><h1>Hello</h1></body></html>')
|
||||
expect(xml.ai).to eq <<-EOS
|
||||
it "should colorize contents" do
|
||||
xml = Nokogiri::XML('<html><body><h1>Hello</h1></body></html>')
|
||||
expect(xml.ai).to eq <<-EOS
|
||||
<?xml version=\"1.0\"?>\e[1;32m
|
||||
\e[0m<\e[1;36mhtml\e[0m>\e[1;32m
|
||||
\e[0m<\e[1;36mbody\e[0m>\e[1;32m
|
||||
\e[0m<\e[1;36mh1\e[0m>\e[1;32mHello\e[0m<\e[1;36m/h1\e[0m>\e[1;32m
|
||||
\e[0m<\e[1;36m/body\e[0m>\e[1;32m
|
||||
\e[0m<\e[1;36m/html\e[0m>
|
||||
EOS
|
||||
end
|
||||
EOS
|
||||
end
|
||||
|
||||
it "should colorize class and id" do
|
||||
xml = Nokogiri::XML('<html><body><h1><span id="hello" class="world"></span></h1></body></html>')
|
||||
expect(xml.ai).to eq <<-EOS
|
||||
it "should colorize class and id" do
|
||||
xml = Nokogiri::XML('<html><body><h1><span id="hello" class="world"></span></h1></body></html>')
|
||||
expect(xml.ai).to eq <<-EOS
|
||||
<?xml version=\"1.0\"?>\e[1;32m
|
||||
\e[0m<\e[1;36mhtml\e[0m>\e[1;32m
|
||||
\e[0m<\e[1;36mbody\e[0m>\e[1;32m
|
||||
|
@ -44,10 +40,6 @@ EOS
|
|||
\e[0m<\e[1;36m/h1\e[0m>\e[1;32m
|
||||
\e[0m<\e[1;36m/body\e[0m>\e[1;32m
|
||||
\e[0m<\e[1;36m/html\e[0m>
|
||||
EOS
|
||||
end
|
||||
EOS
|
||||
end
|
||||
|
||||
rescue LoadError => error
|
||||
puts "Skipping Nokogiri specs: #{error}"
|
||||
end
|
||||
|
|
|
@ -1,31 +1,23 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
||||
require 'spec_helper'
|
||||
|
||||
begin
|
||||
require 'ostruct'
|
||||
require 'awesome_print/ext/ostruct'
|
||||
RSpec.describe 'AwesomePrint Ostruct extension' do
|
||||
before do
|
||||
stub_dotfile!
|
||||
@ap = AwesomePrint::Inspector.new(:plain => true, :sort_keys => true)
|
||||
end
|
||||
|
||||
describe 'AwesomePrint Ostruct extension' do
|
||||
before do
|
||||
stub_dotfile!
|
||||
@ap = AwesomePrint::Inspector.new(:plain => true, :sort_keys => true)
|
||||
end
|
||||
it "empty hash" do
|
||||
struct = OpenStruct.new
|
||||
expect(@ap.send(:awesome, struct)).to eq("OpenStruct {}")
|
||||
end
|
||||
|
||||
it "empty hash" do
|
||||
struct = OpenStruct.new
|
||||
expect(@ap.send(:awesome, struct)).to eq("OpenStruct {}")
|
||||
end
|
||||
|
||||
it "plain multiline" do
|
||||
struct = OpenStruct.new :name => "Foo", :address => "Bar"
|
||||
expect(@ap.send(:awesome, struct)).to eq <<-EOS.strip
|
||||
it "plain multiline" do
|
||||
struct = OpenStruct.new :name => "Foo", :address => "Bar"
|
||||
expect(@ap.send(:awesome, struct)).to eq <<-EOS.strip
|
||||
OpenStruct {
|
||||
:address => "Bar",
|
||||
:name => "Foo"
|
||||
}
|
||||
EOS
|
||||
end
|
||||
EOS
|
||||
end
|
||||
|
||||
rescue LoadError => error
|
||||
puts "Skipping OpenStruct specs: #{error}"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
||||
require 'spec_helper'
|
||||
|
||||
begin
|
||||
require 'ripple'
|
||||
require 'awesome_print/ext/ripple'
|
||||
RSpec.describe 'AwesomePrint/Ripple', skip: ->{ !ExtVerifier.has_ripple? }.call do
|
||||
|
||||
describe 'AwesomePrint/Ripple' do
|
||||
if ExtVerifier.has_ripple?
|
||||
before :all do
|
||||
class RippleUser
|
||||
include Ripple::Document
|
||||
|
@ -19,36 +17,33 @@ begin
|
|||
after :all do
|
||||
Object.instance_eval { remove_const :RippleUser }
|
||||
end
|
||||
end
|
||||
|
||||
before do
|
||||
stub_dotfile!
|
||||
@ap = AwesomePrint::Inspector.new :plain => true, :sort_keys => true
|
||||
end
|
||||
before do
|
||||
stub_dotfile!
|
||||
@ap = AwesomePrint::Inspector.new :plain => true, :sort_keys => true
|
||||
end
|
||||
|
||||
it "should print class instance" do
|
||||
user = RippleUser.new :_id => "12345", :first_name => "Al", :last_name => "Capone"
|
||||
out = @ap.send :awesome, user
|
||||
it "should print class instance" do
|
||||
user = RippleUser.new :_id => "12345", :first_name => "Al", :last_name => "Capone"
|
||||
out = @ap.send :awesome, user
|
||||
|
||||
expect(out.gsub(/0x([a-f\d]+)/, "0x01234567")).to eq <<-EOS.strip
|
||||
expect(out.gsub(/0x([a-f\d]+)/, "0x01234567")).to eq <<-EOS.strip
|
||||
#<RippleUser:0x01234567> {
|
||||
:_id => "12345",
|
||||
:first_name => "Al",
|
||||
:last_name => "Capone"
|
||||
}
|
||||
EOS
|
||||
end
|
||||
EOS
|
||||
end
|
||||
|
||||
it "should print the class" do
|
||||
expect(@ap.send(:awesome, RippleUser)).to eq <<-EOS.strip
|
||||
it "should print the class" do
|
||||
expect(@ap.send(:awesome, RippleUser)).to eq <<-EOS.strip
|
||||
class RippleUser < Object {
|
||||
:_id => :string,
|
||||
:first_name => :string,
|
||||
:last_name => :string
|
||||
}
|
||||
EOS
|
||||
end
|
||||
EOS
|
||||
end
|
||||
|
||||
rescue LoadError => error
|
||||
puts "Skipping Ripple specs: #{error}"
|
||||
end
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
||||
require 'spec_helper'
|
||||
require "bigdecimal"
|
||||
require "rational"
|
||||
require "set"
|
||||
|
||||
describe "AwesomePrint" do
|
||||
RSpec.describe "AwesomePrint" do
|
||||
before do
|
||||
stub_dotfile!
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
||||
require 'spec_helper'
|
||||
|
||||
describe "Single method" do
|
||||
RSpec.describe "Single method" do
|
||||
before do
|
||||
stub_dotfile!
|
||||
end
|
||||
|
@ -80,7 +80,7 @@ describe "Single method" do
|
|||
end
|
||||
end
|
||||
|
||||
describe "Object methods" do
|
||||
RSpec.describe "Object methods" do
|
||||
before do
|
||||
stub_dotfile!
|
||||
end
|
||||
|
@ -202,7 +202,7 @@ describe "Object methods" do
|
|||
end
|
||||
end
|
||||
|
||||
describe "Class methods" do
|
||||
RSpec.describe "Class methods" do
|
||||
before do
|
||||
stub_dotfile!
|
||||
end
|
||||
|
@ -313,7 +313,7 @@ describe "Class methods" do
|
|||
end
|
||||
|
||||
if RUBY_VERSION >= '1.9.2'
|
||||
describe "Ruby 1.9.2+ Method#parameters" do
|
||||
RSpec.describe "Ruby 1.9.2+ Method#parameters" do
|
||||
before do
|
||||
stub_dotfile!
|
||||
end
|
||||
|
@ -364,7 +364,7 @@ if RUBY_VERSION >= '1.9.2'
|
|||
end
|
||||
end
|
||||
|
||||
describe "Methods arrays" do
|
||||
RSpec.describe "Methods arrays" do
|
||||
after do
|
||||
Object.instance_eval{ remove_const :Hello } if defined?(Hello)
|
||||
Object.instance_eval{ remove_const :World } if defined?(World)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
||||
require 'spec_helper'
|
||||
|
||||
describe "AwesomePrint" do
|
||||
RSpec.describe "AwesomePrint" do
|
||||
|
||||
describe "Misc" do
|
||||
before do
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
||||
require 'spec_helper'
|
||||
|
||||
describe "Objects" do
|
||||
RSpec.describe "Objects" do
|
||||
before do
|
||||
stub_dotfile!
|
||||
end
|
||||
|
|
|
@ -16,12 +16,35 @@
|
|||
#
|
||||
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
||||
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
||||
require 'awesome_print'
|
||||
|
||||
Dir[File.dirname(__FILE__) + '/support/**/*.rb'].each do |file|
|
||||
require file
|
||||
end
|
||||
|
||||
ExtVerifier.require_dependencies!(%w{rails active_record action_view
|
||||
active_support/all mongoid mongo_mapper ripple})
|
||||
require 'nokogiri'
|
||||
require 'awesome_print'
|
||||
|
||||
RSpec.configure do |config|
|
||||
config.disable_monkey_patching!
|
||||
# TODO: Make specs not order dependent
|
||||
# config.order = :random
|
||||
Kernel.srand config.seed
|
||||
config.filter_run focus: true
|
||||
config.run_all_when_everything_filtered = true
|
||||
config.expect_with :rspec do |expectations|
|
||||
expectations.syntax = :expect
|
||||
end
|
||||
config.mock_with :rspec do |mocks|
|
||||
mocks.syntax = :expect
|
||||
mocks.verify_partial_doubles = true
|
||||
end
|
||||
if config.files_to_run.one?
|
||||
config.default_formatter = 'doc'
|
||||
end
|
||||
end
|
||||
|
||||
def stub_dotfile!
|
||||
dotfile = File.join(ENV["HOME"], ".aprc")
|
||||
expect(File).to receive(:readable?).at_least(:once).with(dotfile).and_return(false)
|
||||
|
@ -33,36 +56,3 @@ def capture!
|
|||
ensure
|
||||
$stdout = standard
|
||||
end
|
||||
|
||||
# The following is needed for the Infinity Test. It runs tests as subprocesses,
|
||||
# which sets STDOUT.tty? to false and would otherwise prematurely disallow colors.
|
||||
### AwesomePrint.force_colors!
|
||||
|
||||
# Ruby 1.8.6 only: define missing String methods that are needed for the specs to pass.
|
||||
if RUBY_VERSION < '1.8.7'
|
||||
class String
|
||||
def shellescape # Taken from Ruby 1.9.2 standard library, see lib/shellwords.rb.
|
||||
return "''" if self.empty?
|
||||
str = self.dup
|
||||
str.gsub!(/([^A-Za-z0-9_\-.,:\/@\n])/n, "\\\\\\1")
|
||||
str.gsub!(/\n/, "'\n'")
|
||||
str
|
||||
end
|
||||
|
||||
def start_with?(*prefixes)
|
||||
prefixes.each do |prefix|
|
||||
prefix = prefix.to_s
|
||||
return true if prefix == self[0, prefix.size]
|
||||
end
|
||||
false
|
||||
end
|
||||
|
||||
def end_with?(*suffixes)
|
||||
suffixes.each do |suffix|
|
||||
suffix = suffix.to_s
|
||||
return true if suffix == self[-suffix.size, suffix.size]
|
||||
end
|
||||
false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
module ActiveRecordVersions
|
||||
def activerecord_version
|
||||
Gem::Version.new(ActiveRecord::VERSION::STRING)
|
||||
end
|
||||
|
||||
def activerecord_4_2?
|
||||
Gem::Requirement.new('~> 4.2.0').satisfied_by?(activerecord_version)
|
||||
end
|
||||
|
||||
def activerecord_4_1?
|
||||
Gem::Requirement.new('~> 4.1.0').satisfied_by?(activerecord_version)
|
||||
end
|
||||
|
||||
def activerecord_4_0?
|
||||
Gem::Requirement.new('~> 4.0.0').satisfied_by?(activerecord_version)
|
||||
end
|
||||
|
||||
def activerecord_3_2?
|
||||
Gem::Requirement.new('~> 3.2.0').satisfied_by?(activerecord_version)
|
||||
end
|
||||
end
|
||||
|
||||
RSpec.configure do |config|
|
||||
config.include(ActiveRecordVersions)
|
||||
config.extend(ActiveRecordVersions)
|
||||
end
|
37
spec/support/ext_verifier.rb
Normal file
37
spec/support/ext_verifier.rb
Normal file
|
@ -0,0 +1,37 @@
|
|||
module ExtVerifier
|
||||
|
||||
def require_dependencies!(dependencies)
|
||||
dependencies.each do |dependency|
|
||||
begin
|
||||
require dependency
|
||||
rescue LoadError
|
||||
end
|
||||
end
|
||||
end
|
||||
module_function :require_dependencies!
|
||||
|
||||
def has_rails?
|
||||
defined?(Rails)
|
||||
end
|
||||
module_function :has_rails?
|
||||
|
||||
def has_mongoid?
|
||||
defined?(Mongoid)
|
||||
end
|
||||
module_function :has_mongoid?
|
||||
|
||||
def has_mongo_mapper?
|
||||
defined?(MongoMapper)
|
||||
end
|
||||
module_function :has_mongo_mapper?
|
||||
|
||||
def has_ripple?
|
||||
defined?(Ripple)
|
||||
end
|
||||
module_function :has_ripple?
|
||||
end
|
||||
|
||||
RSpec.configure do |config|
|
||||
config.include(ExtVerifier)
|
||||
config.extend(ExtVerifier)
|
||||
end
|
30
spec/support/rails_versions.rb
Normal file
30
spec/support/rails_versions.rb
Normal file
|
@ -0,0 +1,30 @@
|
|||
module RailsVersions
|
||||
def rails_version
|
||||
Gem::Version.new(Rails::VERSION::STRING)
|
||||
end
|
||||
|
||||
def rails_4_2?
|
||||
Gem::Requirement.new('~> 4.2.0').satisfied_by?(rails_version)
|
||||
end
|
||||
alias_method :activerecord_4_2?, :rails_4_2?
|
||||
|
||||
def rails_4_1?
|
||||
Gem::Requirement.new('~> 4.1.0').satisfied_by?(rails_version)
|
||||
end
|
||||
alias_method :activerecord_4_1?, :rails_4_1?
|
||||
|
||||
def rails_4_0?
|
||||
Gem::Requirement.new('~> 4.0.0').satisfied_by?(rails_version)
|
||||
end
|
||||
alias_method :activerecord_4_0?, :rails_4_0?
|
||||
|
||||
def rails_3_2?
|
||||
Gem::Requirement.new('~> 3.2.0').satisfied_by?(rails_version)
|
||||
end
|
||||
alias_method :activerecord_3_2?, :rails_3_2?
|
||||
end
|
||||
|
||||
RSpec.configure do |config|
|
||||
config.include(RailsVersions)
|
||||
config.extend(RailsVersions)
|
||||
end
|
Loading…
Reference in a new issue