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
|
end
|
||||||
|
|
||||||
appraise 'mongoid-3.0' do
|
appraise 'mongoid-3.0' do
|
||||||
gem 'rails', '~> 3.2.0'
|
|
||||||
gem 'mongoid', '~> 3.0.0'
|
gem 'mongoid', '~> 3.0.0'
|
||||||
end
|
end
|
||||||
|
|
||||||
appraise 'mongoid-3.1' do
|
appraise 'mongoid-3.1' do
|
||||||
gem 'rails', '~> 3.2.0'
|
|
||||||
gem 'mongoid', '~> 3.1.0'
|
gem 'mongoid', '~> 3.1.0'
|
||||||
end
|
end
|
||||||
|
|
||||||
appraise 'mongoid-4.0' do
|
appraise 'mongoid-4.0' do
|
||||||
gem 'rails', '~> 4.2.0'
|
|
||||||
gem 'mongoid', '~> 4.0.0'
|
gem 'mongoid', '~> 4.0.0'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
source "https://rubygems.org"
|
source "https://rubygems.org"
|
||||||
|
|
||||||
gem "rails", "~> 3.2.0"
|
|
||||||
gem "mongoid", "~> 3.0.0"
|
gem "mongoid", "~> 3.0.0"
|
||||||
|
|
||||||
gemspec :path => "../"
|
gemspec :path => "../"
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
source "https://rubygems.org"
|
source "https://rubygems.org"
|
||||||
|
|
||||||
gem "rails", "~> 3.2.0"
|
|
||||||
gem "mongoid", "~> 3.1.0"
|
gem "mongoid", "~> 3.1.0"
|
||||||
|
|
||||||
gemspec :path => "../"
|
gemspec :path => "../"
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
source "https://rubygems.org"
|
source "https://rubygems.org"
|
||||||
|
|
||||||
gem "rails", "~> 4.2.0"
|
|
||||||
gem "mongoid", "~> 4.0.0"
|
gem "mongoid", "~> 4.0.0"
|
||||||
|
|
||||||
gemspec :path => "../"
|
gemspec :path => "../"
|
||||||
|
|
|
@ -1,34 +1,24 @@
|
||||||
require 'active_record'
|
if ExtVerifier.has_rails?
|
||||||
|
# Required to use the column support
|
||||||
# Required to use the column support
|
module Rails
|
||||||
module Rails
|
def self.env
|
||||||
def self.env
|
{}
|
||||||
{}
|
end
|
||||||
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
|
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)
|
def stub_tty!(output = true, stream = STDOUT)
|
||||||
if output
|
if output
|
||||||
stream.instance_eval { def tty?; true; end }
|
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 'logger'
|
||||||
require 'awesome_print/core_ext/logger'
|
require 'awesome_print/core_ext/logger'
|
||||||
|
|
||||||
describe "AwesomePrint logging extensions" do
|
RSpec.describe "AwesomePrint logging extensions" do
|
||||||
before(:all) do
|
before(:all) do
|
||||||
@logger = Logger.new('/dev/null') rescue Logger.new('nul')
|
@logger = Logger.new('/dev/null') rescue Logger.new('nul')
|
||||||
end
|
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|
|
[ :gray, :red, :green, :yellow, :blue, :purple, :cyan, :white ].each_with_index do |color, i|
|
||||||
it "should have #{color} color" do
|
it "should have #{color} color" do
|
||||||
expect(color.to_s.send(color)).to eq("\e[1;#{30+i}m#{color}\e[0m")
|
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
|
RSpec.describe "AwesomePrint ActionView extensions", skip: ->{ !ExtVerifier.has_rails? }.call do
|
||||||
require 'action_view'
|
|
||||||
require 'awesome_print/ext/action_view'
|
|
||||||
|
|
||||||
describe "AwesomePrint ActionView extensions" do
|
before do
|
||||||
before do
|
@view = ActionView::Base.new
|
||||||
@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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
rescue LoadError => error
|
it "uses HTML and adds 'debug_dump' class to plain <pre> tag" do
|
||||||
puts "Skipping ActionView specs: #{error}"
|
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
|
end
|
||||||
|
|
|
@ -1,28 +1,24 @@
|
||||||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
require 'spec_helper'
|
||||||
|
require 'active_record_helper'
|
||||||
|
|
||||||
begin
|
RSpec.describe "AwesomePrint/ActiveRecord", skip: ->{ !ExtVerifier.has_rails? }.call do
|
||||||
require 'awesome_print/ext/active_record'
|
|
||||||
require File.expand_path(File.dirname(__FILE__) + '/../active_record_helper')
|
|
||||||
|
|
||||||
if is_usable_activerecord?
|
before do
|
||||||
|
stub_dotfile!
|
||||||
|
end
|
||||||
|
|
||||||
describe "AwesomePrint/ActiveRecord" do
|
#------------------------------------------------------------------------------
|
||||||
before do
|
describe "ActiveRecord instance, attributes only (default)" do
|
||||||
stub_dotfile!
|
before do
|
||||||
end
|
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
|
||||||
describe "ActiveRecord instance, attributes only (default)" do
|
out = @ap.send(:awesome, @diana)
|
||||||
before do
|
str = <<-EOS.strip
|
||||||
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
|
|
||||||
#<User:0x01234567> {
|
#<User:0x01234567> {
|
||||||
:admin => false,
|
:admin => false,
|
||||||
:created_at => ?,
|
:created_at => ?,
|
||||||
|
@ -30,18 +26,18 @@ begin
|
||||||
:name => "Diana",
|
:name => "Diana",
|
||||||
:rank => 1
|
:rank => 1
|
||||||
}
|
}
|
||||||
EOS
|
EOS
|
||||||
if RUBY_VERSION < '1.9'
|
if RUBY_VERSION < '1.9'
|
||||||
str.sub!('?', 'Sat Oct 10 12:30:00 UTC 1992')
|
str.sub!('?', 'Sat Oct 10 12:30:00 UTC 1992')
|
||||||
else
|
else
|
||||||
str.sub!('?', '1992-10-10 12:30:00 UTC')
|
str.sub!('?', '1992-10-10 12:30:00 UTC')
|
||||||
end
|
end
|
||||||
expect(out.gsub(/0x([a-f\d]+)/, "0x01234567")).to eq(str)
|
expect(out.gsub(/0x([a-f\d]+)/, "0x01234567")).to eq(str)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "display multiple records" do
|
it "display multiple records" do
|
||||||
out = @ap.send(:awesome, [ @diana, @laura ])
|
out = @ap.send(:awesome, [ @diana, @laura ])
|
||||||
str = <<-EOS.strip
|
str = <<-EOS.strip
|
||||||
[
|
[
|
||||||
[0] #<User:0x01234567> {
|
[0] #<User:0x01234567> {
|
||||||
:admin => false,
|
:admin => false,
|
||||||
|
@ -58,32 +54,32 @@ EOS
|
||||||
:rank => 2
|
:rank => 2
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
EOS
|
EOS
|
||||||
if RUBY_VERSION < '1.9'
|
if RUBY_VERSION < '1.9'
|
||||||
str.sub!('??', 'Sat Oct 10 12:30:00 UTC 1992')
|
str.sub!('??', 'Sat Oct 10 12:30:00 UTC 1992')
|
||||||
str.sub!('?!', 'Mon May 26 14:15:00 UTC 2003')
|
str.sub!('?!', 'Mon May 26 14:15:00 UTC 2003')
|
||||||
else
|
else
|
||||||
str.sub!('??', '1992-10-10 12:30:00 UTC')
|
str.sub!('??', '1992-10-10 12:30:00 UTC')
|
||||||
str.sub!('?!', '2003-05-26 14:15: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
|
end
|
||||||
|
expect(out.gsub(/0x([a-f\d]+)/, "0x01234567")).to eq(str)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
describe "ActiveRecord instance (raw)" do
|
describe "ActiveRecord instance (raw)" do
|
||||||
before do
|
before do
|
||||||
ActiveRecord::Base.default_timezone = :utc
|
ActiveRecord::Base.default_timezone = :utc
|
||||||
@diana = User.new(:name => "Diana", :rank => 1, :admin => false, :created_at => "1992-10-10 12:30:00")
|
@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")
|
@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)
|
@ap = AwesomePrint::Inspector.new(:plain => true, :sort_keys => true, :raw => true)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "display single record" do
|
it "display single record" do
|
||||||
out = @ap.send(:awesome, @diana)
|
out = @ap.send(:awesome, @diana)
|
||||||
|
|
||||||
if activerecord_4_2?
|
if activerecord_4_2?
|
||||||
str = <<-EOS.strip
|
str = <<-EOS.strip
|
||||||
#<User:0x01234567
|
#<User:0x01234567
|
||||||
@_start_transaction_state = {},
|
@_start_transaction_state = {},
|
||||||
@aggregation_cache = {},
|
@aggregation_cache = {},
|
||||||
|
@ -207,9 +203,9 @@ EOS
|
||||||
"rank" => nil
|
"rank" => nil
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
EOS
|
EOS
|
||||||
elsif activerecord_4_1?
|
elsif activerecord_4_1?
|
||||||
str = <<-EOS.strip
|
str = <<-EOS.strip
|
||||||
#<User:0x01234567
|
#<User:0x01234567
|
||||||
@_start_transaction_state = {},
|
@_start_transaction_state = {},
|
||||||
@aggregation_cache = {},
|
@aggregation_cache = {},
|
||||||
|
@ -307,9 +303,9 @@ EOS
|
||||||
"rank" => nil
|
"rank" => nil
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
EOS
|
EOS
|
||||||
elsif activerecord_4_0?
|
elsif activerecord_4_0?
|
||||||
str = <<-EOS.strip
|
str = <<-EOS.strip
|
||||||
#<User:0x01234567
|
#<User:0x01234567
|
||||||
@_start_transaction_state = {},
|
@_start_transaction_state = {},
|
||||||
@aggregation_cache = {},
|
@aggregation_cache = {},
|
||||||
|
@ -408,9 +404,9 @@ EOS
|
||||||
"rank" => nil
|
"rank" => nil
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
EOS
|
EOS
|
||||||
elsif activerecord_3_2?
|
elsif activerecord_3_2?
|
||||||
str = <<-EOS.strip
|
str = <<-EOS.strip
|
||||||
#<User:0x01234567
|
#<User:0x01234567
|
||||||
@aggregation_cache = {},
|
@aggregation_cache = {},
|
||||||
@attributes_cache = {},
|
@attributes_cache = {},
|
||||||
|
@ -435,17 +431,17 @@ EOS
|
||||||
"rank" => nil
|
"rank" => nil
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
str.sub!('?', '1992-10-10 12:30:00')
|
str.sub!('?', '1992-10-10 12:30:00')
|
||||||
expect(out.gsub(/0x([a-f\d]+)/, "0x01234567")).to eq(str)
|
expect(out.gsub(/0x([a-f\d]+)/, "0x01234567")).to eq(str)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "display multiple records" do
|
it "display multiple records" do
|
||||||
out = @ap.send(:awesome, [ @diana, @laura ])
|
out = @ap.send(:awesome, [ @diana, @laura ])
|
||||||
|
|
||||||
if activerecord_4_2?
|
if activerecord_4_2?
|
||||||
str = <<-EOS.strip
|
str = <<-EOS.strip
|
||||||
[
|
[
|
||||||
[0] #<User:0x01234567
|
[0] #<User:0x01234567
|
||||||
@_start_transaction_state = {},
|
@_start_transaction_state = {},
|
||||||
|
@ -694,9 +690,9 @@ EOS
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
]
|
]
|
||||||
EOS
|
EOS
|
||||||
elsif activerecord_4_1?
|
elsif activerecord_4_1?
|
||||||
str = <<-EOS.strip
|
str = <<-EOS.strip
|
||||||
[
|
[
|
||||||
[0] #<User:0x01234567
|
[0] #<User:0x01234567
|
||||||
@_start_transaction_state = {},
|
@_start_transaction_state = {},
|
||||||
|
@ -893,9 +889,9 @@ EOS
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
]
|
]
|
||||||
EOS
|
EOS
|
||||||
elsif activerecord_4_0?
|
elsif activerecord_4_0?
|
||||||
str = <<-EOS.strip
|
str = <<-EOS.strip
|
||||||
[
|
[
|
||||||
[0] #<User:0x01234567
|
[0] #<User:0x01234567
|
||||||
@_start_transaction_state = {},
|
@_start_transaction_state = {},
|
||||||
|
@ -1094,9 +1090,9 @@ EOS
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
]
|
]
|
||||||
EOS
|
EOS
|
||||||
elsif activerecord_3_2?
|
elsif activerecord_3_2?
|
||||||
str = <<-EOS.strip
|
str = <<-EOS.strip
|
||||||
[
|
[
|
||||||
[0] #<User:0x01234567
|
[0] #<User:0x01234567
|
||||||
@aggregation_cache = {},
|
@aggregation_cache = {},
|
||||||
|
@ -1147,22 +1143,22 @@ EOS
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
]
|
]
|
||||||
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
|
|
||||||
end
|
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
|
describe "ActiveRecord class" do
|
||||||
before do
|
before do
|
||||||
@ap = AwesomePrint::Inspector.new(:plain => true)
|
@ap = AwesomePrint::Inspector.new(:plain => true)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should print the class" do
|
it "should print the class" do
|
||||||
expect(@ap.send(:awesome, User)).to eq <<-EOS.strip
|
expect(@ap.send(:awesome, User)).to eq <<-EOS.strip
|
||||||
class User < ActiveRecord::Base {
|
class User < ActiveRecord::Base {
|
||||||
:id => :integer,
|
:id => :integer,
|
||||||
:name => :string,
|
:name => :string,
|
||||||
|
@ -1170,12 +1166,12 @@ class User < ActiveRecord::Base {
|
||||||
:admin => :boolean,
|
:admin => :boolean,
|
||||||
:created_at => :datetime
|
:created_at => :datetime
|
||||||
}
|
}
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should print the class for non-direct subclasses of ActiveRecord::Base" do
|
it "should print the class for non-direct subclasses of ActiveRecord::Base" do
|
||||||
out = @ap.send(:awesome, SubUser)
|
out = @ap.send(:awesome, SubUser)
|
||||||
expect(out).to eq <<-EOS.strip
|
expect(out).to eq <<-EOS.strip
|
||||||
class SubUser < User {
|
class SubUser < User {
|
||||||
:id => :integer,
|
:id => :integer,
|
||||||
:name => :string,
|
:name => :string,
|
||||||
|
@ -1183,51 +1179,47 @@ class SubUser < User {
|
||||||
:admin => :boolean,
|
:admin => :boolean,
|
||||||
:created_at => :datetime
|
:created_at => :datetime
|
||||||
}
|
}
|
||||||
EOS
|
EOS
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
rescue LoadError => error
|
|
||||||
puts "Skipping ActiveRecord specs: #{error}"
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,35 +1,27 @@
|
||||||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
require 'spec_helper'
|
||||||
|
|
||||||
begin
|
RSpec.describe "AwesomePrint::ActiveSupport", skip: ->{ !ExtVerifier.has_rails? }.call do
|
||||||
require 'active_support/all'
|
before do
|
||||||
require 'awesome_print/ext/active_support'
|
stub_dotfile!
|
||||||
|
@ap = AwesomePrint::Inspector.new
|
||||||
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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
rescue LoadError => error
|
it "should format ActiveSupport::TimeWithZone as regular Time" do
|
||||||
puts "Skipping ActiveSupport specs: #{error}"
|
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
|
end
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
require 'spec_helper'
|
||||||
|
|
||||||
begin
|
RSpec.describe "AwesomePrint/MongoMapper", skip: ->{ !ExtVerifier.has_mongo_mapper? }.call do
|
||||||
require "mongo_mapper"
|
|
||||||
require "awesome_print/ext/mongo_mapper"
|
|
||||||
|
|
||||||
describe "AwesomePrint/MongoMapper" do
|
if ExtVerifier.has_mongo_mapper?
|
||||||
before :all do
|
before :all do
|
||||||
class MongoUser
|
class MongoUser
|
||||||
include MongoMapper::Document
|
include MongoMapper::Document
|
||||||
|
@ -18,25 +16,26 @@ begin
|
||||||
Object.instance_eval{ remove_const :MongoUser }
|
Object.instance_eval{ remove_const :MongoUser }
|
||||||
Object.instance_eval{ remove_const :Chamelion }
|
Object.instance_eval{ remove_const :Chamelion }
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
before do
|
before do
|
||||||
stub_dotfile!
|
stub_dotfile!
|
||||||
@ap = AwesomePrint::Inspector.new(:plain => true, :sort_keys => true)
|
@ap = AwesomePrint::Inspector.new(:plain => true, :sort_keys => true)
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "with the raw option set to true" do
|
describe "with the raw option set to true" do
|
||||||
# before { @ap.options[:raw] = true }
|
# before { @ap.options[:raw] = true }
|
||||||
before { @ap = AwesomePrint::Inspector.new(:plain => true, :sort_keys => true, :raw => true) }
|
before { @ap = AwesomePrint::Inspector.new(:plain => true, :sort_keys => true, :raw => true) }
|
||||||
|
|
||||||
it "should print class instance" do
|
it "should print class instance" do
|
||||||
user = MongoUser.new(:first_name => "Al", :last_name => "Capone")
|
user = MongoUser.new(:first_name => "Al", :last_name => "Capone")
|
||||||
|
|
||||||
out = @ap.send(:awesome, user)
|
out = @ap.send(:awesome, user)
|
||||||
out.gsub!(/#\<Proc:.+?\>/, 'AWESOME_PRINT_PROC_STUB')
|
out.gsub!(/#\<Proc:.+?\>/, 'AWESOME_PRINT_PROC_STUB')
|
||||||
out.gsub!(/BSON::ObjectId\('[\da-f]+?'\)/, "BSON::ObjectId('123456789')")
|
out.gsub!(/BSON::ObjectId\('[\da-f]+?'\)/, "BSON::ObjectId('123456789')")
|
||||||
|
|
||||||
if MongoMapper::Version >= "0.13"
|
if MongoMapper::Version >= "0.13"
|
||||||
str = <<-EOS.strip
|
str = <<-EOS.strip
|
||||||
#<MongoUser:0x01234567
|
#<MongoUser:0x01234567
|
||||||
@__mm_default_keys = [
|
@__mm_default_keys = [
|
||||||
[0] #<MongoMapper::Plugins::Keys::Key:0x01234567
|
[0] #<MongoMapper::Plugins::Keys::Key:0x01234567
|
||||||
|
@ -111,9 +110,9 @@ begin
|
||||||
"last_name" => nil
|
"last_name" => nil
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
EOS
|
EOS
|
||||||
else
|
else
|
||||||
str = <<-EOS.strip
|
str = <<-EOS.strip
|
||||||
#<MongoUser:0x01234567
|
#<MongoUser:0x01234567
|
||||||
@_new = true,
|
@_new = true,
|
||||||
attr_accessor :first_name = "Al",
|
attr_accessor :first_name = "Al",
|
||||||
|
@ -125,38 +124,40 @@ EOS
|
||||||
attr_reader :first_name_before_type_cast = "Al",
|
attr_reader :first_name_before_type_cast = "Al",
|
||||||
attr_reader :last_name_before_type_cast = "Capone"
|
attr_reader :last_name_before_type_cast = "Capone"
|
||||||
>
|
>
|
||||||
EOS
|
EOS
|
||||||
end
|
|
||||||
out.gsub!(/0x([a-f\d]+)/, "0x01234567")
|
|
||||||
expect(out).to eq(str)
|
|
||||||
end
|
end
|
||||||
|
out.gsub!(/0x([a-f\d]+)/, "0x01234567")
|
||||||
|
expect(out).to eq(str)
|
||||||
|
end
|
||||||
|
|
||||||
it "should print the class" do
|
it "should print the class" do
|
||||||
expect(@ap.send(:awesome, MongoUser)).to eq <<-EOS.strip
|
expect(@ap.send(:awesome, MongoUser)).to eq <<-EOS.strip
|
||||||
class MongoUser < Object {
|
class MongoUser < Object {
|
||||||
"_id" => :object_id,
|
"_id" => :object_id,
|
||||||
"first_name" => :string,
|
"first_name" => :string,
|
||||||
"last_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
|
end
|
||||||
|
|
||||||
it "should print the class when type is undefined" do
|
expect(@ap.send(:awesome, Chamelion)).to eq <<-EOS.strip
|
||||||
class Chamelion
|
|
||||||
include MongoMapper::Document
|
|
||||||
key :last_attribute
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(@ap.send(:awesome, Chamelion)).to eq <<-EOS.strip
|
|
||||||
class Chamelion < Object {
|
class Chamelion < Object {
|
||||||
"_id" => :object_id,
|
"_id" => :object_id,
|
||||||
"last_attribute" => :undefined
|
"last_attribute" => :undefined
|
||||||
}
|
}
|
||||||
EOS
|
EOS
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "with associations" do
|
describe "with associations" do
|
||||||
|
|
||||||
|
if ExtVerifier.has_mongo_mapper?
|
||||||
before :all do
|
before :all do
|
||||||
class Child
|
class Child
|
||||||
include MongoMapper::EmbeddedDocument
|
include MongoMapper::EmbeddedDocument
|
||||||
|
@ -176,79 +177,80 @@ EOS
|
||||||
one :sibling
|
one :sibling
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "with show associations turned off (default)" do
|
describe "with show associations turned off (default)" do
|
||||||
it "should render the class as normal" do
|
it "should render the class as normal" do
|
||||||
expect(@ap.send(:awesome, Parent)).to eq <<-EOS.strip
|
expect(@ap.send(:awesome, Parent)).to eq <<-EOS.strip
|
||||||
class Parent < Object {
|
class Parent < Object {
|
||||||
"_id" => :object_id,
|
"_id" => :object_id,
|
||||||
"name" => :undefined
|
"name" => :undefined
|
||||||
}
|
}
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should render an instance as normal" do
|
it "should render an instance as normal" do
|
||||||
parent = Parent.new(:name => 'test')
|
parent = Parent.new(:name => 'test')
|
||||||
out = @ap.send(:awesome, parent)
|
out = @ap.send(:awesome, parent)
|
||||||
str = <<-EOS.strip
|
str = <<-EOS.strip
|
||||||
#<Parent:0x01234567> {
|
#<Parent:0x01234567> {
|
||||||
"_id" => BSON::ObjectId('4d9183739a546f6806000001'),
|
"_id" => BSON::ObjectId('4d9183739a546f6806000001'),
|
||||||
"name" => "test"
|
"name" => "test"
|
||||||
}
|
}
|
||||||
EOS
|
EOS
|
||||||
out.gsub!(/'([\w]+){23}'/, "'4d9183739a546f6806000001'")
|
out.gsub!(/'([\w]+){23}'/, "'4d9183739a546f6806000001'")
|
||||||
out.gsub!(/0x([a-f\d]+)/, "0x01234567")
|
out.gsub!(/0x([a-f\d]+)/, "0x01234567")
|
||||||
expect(out).to eq(str)
|
expect(out).to eq(str)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
describe "with show associations turned on and inline embedded turned off" do
|
it "should render the class with associations shown" do
|
||||||
before :each do
|
expect(@ap.send(:awesome, Parent)).to eq <<-EOS.strip
|
||||||
@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
|
|
||||||
class Parent < Object {
|
class Parent < Object {
|
||||||
"_id" => :object_id,
|
"_id" => :object_id,
|
||||||
"name" => :undefined,
|
"name" => :undefined,
|
||||||
"child" => embeds one Child,
|
"child" => embeds one Child,
|
||||||
"sibling" => one Sibling
|
"sibling" => one Sibling
|
||||||
}
|
}
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should render an instance with associations shown" do
|
it "should render an instance with associations shown" do
|
||||||
parent = Parent.new(:name => 'test')
|
parent = Parent.new(:name => 'test')
|
||||||
out = @ap.send(:awesome, parent)
|
out = @ap.send(:awesome, parent)
|
||||||
str = <<-EOS.strip
|
str = <<-EOS.strip
|
||||||
#<Parent:0x01234567> {
|
#<Parent:0x01234567> {
|
||||||
"_id" => BSON::ObjectId('4d9183739a546f6806000001'),
|
"_id" => BSON::ObjectId('4d9183739a546f6806000001'),
|
||||||
"name" => "test",
|
"name" => "test",
|
||||||
"child" => embeds one Child,
|
"child" => embeds one Child,
|
||||||
"sibling" => one Sibling
|
"sibling" => one Sibling
|
||||||
}
|
}
|
||||||
EOS
|
EOS
|
||||||
out.gsub!(/'([\w]+){23}'/, "'4d9183739a546f6806000001'")
|
out.gsub!(/'([\w]+){23}'/, "'4d9183739a546f6806000001'")
|
||||||
out.gsub!(/0x([a-f\d]+)/, "0x01234567")
|
out.gsub!(/0x([a-f\d]+)/, "0x01234567")
|
||||||
expect(out).to eq(str)
|
expect(out).to eq(str)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
describe "with show associations turned on and inline embedded turned on" do
|
it "should render an instance with associations shown and embeds there" do
|
||||||
before :each do
|
parent = Parent.new(:name => 'test', :child => Child.new(:data => 5))
|
||||||
@ap = AwesomePrint::Inspector.new(:plain => true,
|
out = @ap.send(:awesome, parent)
|
||||||
:mongo_mapper => {
|
str = <<-EOS.strip
|
||||||
: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
|
|
||||||
#<Parent:0x01234567> {
|
#<Parent:0x01234567> {
|
||||||
"_id" => BSON::ObjectId('4d9183739a546f6806000001'),
|
"_id" => BSON::ObjectId('4d9183739a546f6806000001'),
|
||||||
"name" => "test",
|
"name" => "test",
|
||||||
|
@ -258,15 +260,11 @@ EOS
|
||||||
},
|
},
|
||||||
"sibling" => one Sibling
|
"sibling" => one Sibling
|
||||||
}
|
}
|
||||||
EOS
|
EOS
|
||||||
out.gsub!(/'([\w]+){23}'/, "'4d9183739a546f6806000001'")
|
out.gsub!(/'([\w]+){23}'/, "'4d9183739a546f6806000001'")
|
||||||
out.gsub!(/0x([a-f\d]+)/, "0x01234567")
|
out.gsub!(/0x([a-f\d]+)/, "0x01234567")
|
||||||
expect(out).to eq(str)
|
expect(out).to eq(str)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
rescue LoadError => error
|
|
||||||
puts "Skipping MongoMapper specs: #{error}"
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
require 'spec_helper'
|
||||||
|
|
||||||
begin
|
RSpec.describe "AwesomePrint/Mongoid", skip: ->{ !ExtVerifier.has_mongoid? }.call do
|
||||||
require "mongoid"
|
|
||||||
require "awesome_print/ext/mongoid"
|
|
||||||
|
|
||||||
describe "AwesomePrint/Mongoid" do
|
if ExtVerifier.has_mongoid?
|
||||||
before :all do
|
before :all do
|
||||||
class MongoUser
|
class MongoUser
|
||||||
include Mongoid::Document
|
include Mongoid::Document
|
||||||
|
@ -18,94 +16,91 @@ begin
|
||||||
Object.instance_eval{ remove_const :MongoUser }
|
Object.instance_eval{ remove_const :MongoUser }
|
||||||
Object.instance_eval{ remove_const :Chamelion }
|
Object.instance_eval{ remove_const :Chamelion }
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
before do
|
before do
|
||||||
stub_dotfile!
|
stub_dotfile!
|
||||||
@ap = AwesomePrint::Inspector.new :plain => true, :sort_keys => true
|
@ap = AwesomePrint::Inspector.new :plain => true, :sort_keys => true
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should print class instance" do
|
it "should print class instance" do
|
||||||
user = MongoUser.new :first_name => "Al", :last_name => "Capone"
|
user = MongoUser.new :first_name => "Al", :last_name => "Capone"
|
||||||
out = @ap.send :awesome, user
|
out = @ap.send :awesome, user
|
||||||
|
|
||||||
object_id = user.id.inspect
|
object_id = user.id.inspect
|
||||||
str = <<-EOS.strip
|
str = <<-EOS.strip
|
||||||
#<MongoUser:0x01234567> {
|
#<MongoUser:0x01234567> {
|
||||||
:_id => #{object_id},
|
:_id => #{object_id},
|
||||||
:first_name => "Al",
|
:first_name => "Al",
|
||||||
:last_name => "Capone"
|
:last_name => "Capone"
|
||||||
}
|
}
|
||||||
EOS
|
EOS
|
||||||
out.gsub!(/0x([a-f\d]+)/, "0x01234567")
|
out.gsub!(/0x([a-f\d]+)/, "0x01234567")
|
||||||
expect(out).to eq(str)
|
expect(out).to eq(str)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should print the class" do
|
it "should print the class" do
|
||||||
class_spec = if mongoid_3_0?
|
class_spec = if mongoid_3_0?
|
||||||
<<-EOS.strip
|
<<-EOS.strip
|
||||||
class MongoUser < Object {
|
class MongoUser < Object {
|
||||||
:_id => :"moped/bson/object_id",
|
:_id => :"moped/bson/object_id",
|
||||||
:_type => :string,
|
:_type => :string,
|
||||||
:first_name => :string,
|
:first_name => :string,
|
||||||
:last_name => :string
|
:last_name => :string
|
||||||
}
|
}
|
||||||
EOS
|
EOS
|
||||||
elsif mongoid_3_1?
|
elsif mongoid_3_1?
|
||||||
<<-EOS.strip
|
<<-EOS.strip
|
||||||
class MongoUser < Object {
|
class MongoUser < Object {
|
||||||
:_id => :"moped/bson/object_id",
|
:_id => :"moped/bson/object_id",
|
||||||
:first_name => :string,
|
:first_name => :string,
|
||||||
:last_name => :string
|
:last_name => :string
|
||||||
}
|
}
|
||||||
EOS
|
EOS
|
||||||
elsif mongoid_4_0?
|
elsif mongoid_4_0?
|
||||||
<<-EOS.strip
|
<<-EOS.strip
|
||||||
class MongoUser < Object {
|
class MongoUser < Object {
|
||||||
:_id => :"bson/object_id",
|
:_id => :"bson/object_id",
|
||||||
:first_name => :string,
|
:first_name => :string,
|
||||||
:last_name => :string
|
:last_name => :string
|
||||||
}
|
}
|
||||||
EOS
|
EOS
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
it "should print the class when type is undefined" do
|
class_spec = if mongoid_3_0?
|
||||||
class Chamelion
|
<<-EOS.strip
|
||||||
include Mongoid::Document
|
|
||||||
field :last_attribute
|
|
||||||
end
|
|
||||||
|
|
||||||
class_spec = if mongoid_3_0?
|
|
||||||
<<-EOS.strip
|
|
||||||
class Chamelion < Object {
|
class Chamelion < Object {
|
||||||
:_id => :"moped/bson/object_id",
|
:_id => :"moped/bson/object_id",
|
||||||
:_type => :string,
|
:_type => :string,
|
||||||
:last_attribute => :object
|
:last_attribute => :object
|
||||||
}
|
}
|
||||||
EOS
|
EOS
|
||||||
elsif mongoid_3_1?
|
elsif mongoid_3_1?
|
||||||
<<-EOS.strip
|
<<-EOS.strip
|
||||||
class Chamelion < Object {
|
class Chamelion < Object {
|
||||||
:_id => :"moped/bson/object_id",
|
:_id => :"moped/bson/object_id",
|
||||||
:last_attribute => :object
|
:last_attribute => :object
|
||||||
}
|
}
|
||||||
EOS
|
EOS
|
||||||
elsif mongoid_4_0?
|
elsif mongoid_4_0?
|
||||||
<<-EOS.strip
|
<<-EOS.strip
|
||||||
class Chamelion < Object {
|
class Chamelion < Object {
|
||||||
:_id => :"bson/object_id",
|
:_id => :"bson/object_id",
|
||||||
:last_attribute => :object
|
:last_attribute => :object
|
||||||
}
|
}
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
expect(@ap.send(:awesome, Chamelion)).to eq class_spec
|
expect(@ap.send(:awesome, Chamelion)).to eq class_spec
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
rescue LoadError => error
|
|
||||||
puts "Skipping Mongoid specs: #{error}"
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,41 +1,37 @@
|
||||||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
require 'spec_helper'
|
||||||
|
|
||||||
begin
|
RSpec.describe "AwesomePrint/Nokogiri" do
|
||||||
require "nokogiri"
|
before do
|
||||||
require "awesome_print/ext/nokogiri"
|
stub_dotfile!
|
||||||
|
end
|
||||||
|
|
||||||
describe "AwesomePrint/Nokogiri" do
|
it "should colorize tags" do
|
||||||
before do
|
xml = Nokogiri::XML('<html><body><h1></h1></body></html>')
|
||||||
stub_dotfile!
|
expect(xml.ai).to eq <<-EOS
|
||||||
end
|
|
||||||
|
|
||||||
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
|
<?xml version=\"1.0\"?>\e[1;32m
|
||||||
\e[0m<\e[1;36mhtml\e[0m>\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;36mbody\e[0m>\e[1;32m
|
||||||
\e[0m<\e[1;36mh1\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/body\e[0m>\e[1;32m
|
||||||
\e[0m<\e[1;36m/html\e[0m>
|
\e[0m<\e[1;36m/html\e[0m>
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should colorize contents" do
|
it "should colorize contents" do
|
||||||
xml = Nokogiri::XML('<html><body><h1>Hello</h1></body></html>')
|
xml = Nokogiri::XML('<html><body><h1>Hello</h1></body></html>')
|
||||||
expect(xml.ai).to eq <<-EOS
|
expect(xml.ai).to eq <<-EOS
|
||||||
<?xml version=\"1.0\"?>\e[1;32m
|
<?xml version=\"1.0\"?>\e[1;32m
|
||||||
\e[0m<\e[1;36mhtml\e[0m>\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;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;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/body\e[0m>\e[1;32m
|
||||||
\e[0m<\e[1;36m/html\e[0m>
|
\e[0m<\e[1;36m/html\e[0m>
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should colorize class and id" do
|
it "should colorize class and id" do
|
||||||
xml = Nokogiri::XML('<html><body><h1><span id="hello" class="world"></span></h1></body></html>')
|
xml = Nokogiri::XML('<html><body><h1><span id="hello" class="world"></span></h1></body></html>')
|
||||||
expect(xml.ai).to eq <<-EOS
|
expect(xml.ai).to eq <<-EOS
|
||||||
<?xml version=\"1.0\"?>\e[1;32m
|
<?xml version=\"1.0\"?>\e[1;32m
|
||||||
\e[0m<\e[1;36mhtml\e[0m>\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;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/h1\e[0m>\e[1;32m
|
||||||
\e[0m<\e[1;36m/body\e[0m>\e[1;32m
|
\e[0m<\e[1;36m/body\e[0m>\e[1;32m
|
||||||
\e[0m<\e[1;36m/html\e[0m>
|
\e[0m<\e[1;36m/html\e[0m>
|
||||||
EOS
|
EOS
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
rescue LoadError => error
|
|
||||||
puts "Skipping Nokogiri specs: #{error}"
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,31 +1,23 @@
|
||||||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
require 'spec_helper'
|
||||||
|
|
||||||
begin
|
RSpec.describe 'AwesomePrint Ostruct extension' do
|
||||||
require 'ostruct'
|
before do
|
||||||
require 'awesome_print/ext/ostruct'
|
stub_dotfile!
|
||||||
|
@ap = AwesomePrint::Inspector.new(:plain => true, :sort_keys => true)
|
||||||
|
end
|
||||||
|
|
||||||
describe 'AwesomePrint Ostruct extension' do
|
it "empty hash" do
|
||||||
before do
|
struct = OpenStruct.new
|
||||||
stub_dotfile!
|
expect(@ap.send(:awesome, struct)).to eq("OpenStruct {}")
|
||||||
@ap = AwesomePrint::Inspector.new(:plain => true, :sort_keys => true)
|
end
|
||||||
end
|
|
||||||
|
|
||||||
it "empty hash" do
|
it "plain multiline" do
|
||||||
struct = OpenStruct.new
|
struct = OpenStruct.new :name => "Foo", :address => "Bar"
|
||||||
expect(@ap.send(:awesome, struct)).to eq("OpenStruct {}")
|
expect(@ap.send(:awesome, struct)).to eq <<-EOS.strip
|
||||||
end
|
|
||||||
|
|
||||||
it "plain multiline" do
|
|
||||||
struct = OpenStruct.new :name => "Foo", :address => "Bar"
|
|
||||||
expect(@ap.send(:awesome, struct)).to eq <<-EOS.strip
|
|
||||||
OpenStruct {
|
OpenStruct {
|
||||||
:address => "Bar",
|
:address => "Bar",
|
||||||
:name => "Foo"
|
:name => "Foo"
|
||||||
}
|
}
|
||||||
EOS
|
EOS
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
end
|
||||||
rescue LoadError => error
|
|
||||||
puts "Skipping OpenStruct specs: #{error}"
|
|
||||||
end
|
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
require 'spec_helper'
|
||||||
|
|
||||||
begin
|
RSpec.describe 'AwesomePrint/Ripple', skip: ->{ !ExtVerifier.has_ripple? }.call do
|
||||||
require 'ripple'
|
|
||||||
require 'awesome_print/ext/ripple'
|
|
||||||
|
|
||||||
describe 'AwesomePrint/Ripple' do
|
if ExtVerifier.has_ripple?
|
||||||
before :all do
|
before :all do
|
||||||
class RippleUser
|
class RippleUser
|
||||||
include Ripple::Document
|
include Ripple::Document
|
||||||
|
@ -19,36 +17,33 @@ begin
|
||||||
after :all do
|
after :all do
|
||||||
Object.instance_eval { remove_const :RippleUser }
|
Object.instance_eval { remove_const :RippleUser }
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
before do
|
before do
|
||||||
stub_dotfile!
|
stub_dotfile!
|
||||||
@ap = AwesomePrint::Inspector.new :plain => true, :sort_keys => true
|
@ap = AwesomePrint::Inspector.new :plain => true, :sort_keys => true
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should print class instance" do
|
it "should print class instance" do
|
||||||
user = RippleUser.new :_id => "12345", :first_name => "Al", :last_name => "Capone"
|
user = RippleUser.new :_id => "12345", :first_name => "Al", :last_name => "Capone"
|
||||||
out = @ap.send :awesome, user
|
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> {
|
#<RippleUser:0x01234567> {
|
||||||
:_id => "12345",
|
:_id => "12345",
|
||||||
:first_name => "Al",
|
:first_name => "Al",
|
||||||
:last_name => "Capone"
|
:last_name => "Capone"
|
||||||
}
|
}
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should print the class" do
|
it "should print the class" do
|
||||||
expect(@ap.send(:awesome, RippleUser)).to eq <<-EOS.strip
|
expect(@ap.send(:awesome, RippleUser)).to eq <<-EOS.strip
|
||||||
class RippleUser < Object {
|
class RippleUser < Object {
|
||||||
:_id => :string,
|
:_id => :string,
|
||||||
:first_name => :string,
|
:first_name => :string,
|
||||||
:last_name => :string
|
:last_name => :string
|
||||||
}
|
}
|
||||||
EOS
|
EOS
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
rescue LoadError => error
|
|
||||||
puts "Skipping Ripple specs: #{error}"
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
require 'spec_helper'
|
||||||
require "bigdecimal"
|
require "bigdecimal"
|
||||||
require "rational"
|
require "rational"
|
||||||
require "set"
|
require "set"
|
||||||
|
|
||||||
describe "AwesomePrint" do
|
RSpec.describe "AwesomePrint" do
|
||||||
before do
|
before do
|
||||||
stub_dotfile!
|
stub_dotfile!
|
||||||
end
|
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
|
before do
|
||||||
stub_dotfile!
|
stub_dotfile!
|
||||||
end
|
end
|
||||||
|
@ -80,7 +80,7 @@ describe "Single method" do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "Object methods" do
|
RSpec.describe "Object methods" do
|
||||||
before do
|
before do
|
||||||
stub_dotfile!
|
stub_dotfile!
|
||||||
end
|
end
|
||||||
|
@ -202,7 +202,7 @@ describe "Object methods" do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "Class methods" do
|
RSpec.describe "Class methods" do
|
||||||
before do
|
before do
|
||||||
stub_dotfile!
|
stub_dotfile!
|
||||||
end
|
end
|
||||||
|
@ -313,7 +313,7 @@ describe "Class methods" do
|
||||||
end
|
end
|
||||||
|
|
||||||
if RUBY_VERSION >= '1.9.2'
|
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
|
before do
|
||||||
stub_dotfile!
|
stub_dotfile!
|
||||||
end
|
end
|
||||||
|
@ -364,7 +364,7 @@ if RUBY_VERSION >= '1.9.2'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "Methods arrays" do
|
RSpec.describe "Methods arrays" do
|
||||||
after do
|
after do
|
||||||
Object.instance_eval{ remove_const :Hello } if defined?(Hello)
|
Object.instance_eval{ remove_const :Hello } if defined?(Hello)
|
||||||
Object.instance_eval{ remove_const :World } if defined?(World)
|
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
|
describe "Misc" do
|
||||||
before 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
|
before do
|
||||||
stub_dotfile!
|
stub_dotfile!
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,12 +16,35 @@
|
||||||
#
|
#
|
||||||
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
||||||
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
||||||
require 'awesome_print'
|
|
||||||
|
|
||||||
Dir[File.dirname(__FILE__) + '/support/**/*.rb'].each do |file|
|
Dir[File.dirname(__FILE__) + '/support/**/*.rb'].each do |file|
|
||||||
require file
|
require file
|
||||||
end
|
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!
|
def stub_dotfile!
|
||||||
dotfile = File.join(ENV["HOME"], ".aprc")
|
dotfile = File.join(ENV["HOME"], ".aprc")
|
||||||
expect(File).to receive(:readable?).at_least(:once).with(dotfile).and_return(false)
|
expect(File).to receive(:readable?).at_least(:once).with(dotfile).and_return(false)
|
||||||
|
@ -33,36 +56,3 @@ def capture!
|
||||||
ensure
|
ensure
|
||||||
$stdout = standard
|
$stdout = standard
|
||||||
end
|
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