2014-12-31 15:59:32 -05:00
|
|
|
require 'spec_helper'
|
2011-10-26 17:47:15 -04:00
|
|
|
|
2016-11-08 21:39:25 -05:00
|
|
|
RSpec.describe 'AwesomePrint/Mongoid', skip: -> { !ExtVerifier.has_mongoid? }.call do
|
2011-10-26 17:47:15 -04:00
|
|
|
|
2014-12-31 15:59:32 -05:00
|
|
|
if ExtVerifier.has_mongoid?
|
2011-10-26 17:47:15 -04:00
|
|
|
before :all do
|
|
|
|
class MongoUser
|
|
|
|
include Mongoid::Document
|
|
|
|
|
2016-11-08 09:53:17 -05:00
|
|
|
field :first_name, type: String
|
|
|
|
field :last_name, type: String
|
2011-10-26 17:47:15 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-09-06 19:34:11 -04:00
|
|
|
after :all do
|
2016-11-08 21:39:25 -05:00
|
|
|
Object.instance_eval { remove_const :MongoUser }
|
|
|
|
Object.instance_eval { remove_const :Chamelion }
|
2012-09-06 19:34:11 -04:00
|
|
|
end
|
2014-12-31 15:59:32 -05:00
|
|
|
end
|
2012-09-06 19:34:11 -04:00
|
|
|
|
2014-12-31 15:59:32 -05:00
|
|
|
before do
|
2016-11-08 09:53:17 -05:00
|
|
|
@ap = AwesomePrint::Inspector.new plain: true, sort_keys: true
|
2014-12-31 15:59:32 -05:00
|
|
|
end
|
2011-10-26 17:47:15 -04:00
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
it 'should print class instance' do
|
2016-11-08 09:53:17 -05:00
|
|
|
user = MongoUser.new first_name: 'Al', last_name: 'Capone'
|
2014-12-31 15:59:32 -05:00
|
|
|
out = @ap.send :awesome, user
|
2011-10-26 17:47:15 -04:00
|
|
|
|
2014-12-31 15:59:32 -05:00
|
|
|
object_id = user.id.inspect
|
|
|
|
str = <<-EOS.strip
|
2016-05-09 10:04:42 -04:00
|
|
|
#<MongoUser:placeholder_id> {
|
2012-08-08 07:59:19 -04:00
|
|
|
:_id => #{object_id},
|
2011-12-13 00:41:31 -05:00
|
|
|
:first_name => "Al",
|
|
|
|
:last_name => "Capone"
|
|
|
|
}
|
2014-12-31 15:59:32 -05:00
|
|
|
EOS
|
2016-11-08 21:39:25 -05:00
|
|
|
expect(out).to be_similar_to(str, { skip_bson: true })
|
2014-12-31 15:59:32 -05:00
|
|
|
end
|
2011-10-26 17:47:15 -04:00
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
it 'should print the class' do
|
2014-12-31 15:59:32 -05:00
|
|
|
class_spec = if mongoid_3_0?
|
|
|
|
<<-EOS.strip
|
2014-12-31 13:41:17 -05:00
|
|
|
class MongoUser < Object {
|
|
|
|
:_id => :"moped/bson/object_id",
|
|
|
|
:_type => :string,
|
|
|
|
:first_name => :string,
|
|
|
|
:last_name => :string
|
|
|
|
}
|
2014-12-31 15:59:32 -05:00
|
|
|
EOS
|
|
|
|
elsif mongoid_3_1?
|
|
|
|
<<-EOS.strip
|
2014-12-31 13:41:17 -05:00
|
|
|
class MongoUser < Object {
|
|
|
|
:_id => :"moped/bson/object_id",
|
|
|
|
:first_name => :string,
|
|
|
|
:last_name => :string
|
|
|
|
}
|
2014-12-31 15:59:32 -05:00
|
|
|
EOS
|
|
|
|
elsif mongoid_4_0?
|
|
|
|
<<-EOS.strip
|
2011-10-26 17:47:15 -04:00
|
|
|
class MongoUser < Object {
|
2014-08-07 21:56:23 -04:00
|
|
|
:_id => :"bson/object_id",
|
2011-12-13 00:41:31 -05:00
|
|
|
:first_name => :string,
|
|
|
|
:last_name => :string
|
2011-10-26 17:47:15 -04:00
|
|
|
}
|
2014-12-31 15:59:32 -05:00
|
|
|
EOS
|
|
|
|
end
|
2014-12-31 13:41:17 -05:00
|
|
|
|
2014-12-31 15:59:32 -05:00
|
|
|
expect(@ap.send(:awesome, MongoUser)).to eq class_spec
|
|
|
|
end
|
2011-10-26 17:47:15 -04:00
|
|
|
|
2016-11-08 00:07:03 -05:00
|
|
|
it 'should print the class when type is undefined' do
|
2014-12-31 15:59:32 -05:00
|
|
|
class Chamelion
|
|
|
|
include Mongoid::Document
|
|
|
|
field :last_attribute
|
|
|
|
end
|
2011-10-26 17:47:15 -04:00
|
|
|
|
2014-12-31 15:59:32 -05:00
|
|
|
class_spec = if mongoid_3_0?
|
|
|
|
<<-EOS.strip
|
2014-12-31 13:41:17 -05:00
|
|
|
class Chamelion < Object {
|
|
|
|
:_id => :"moped/bson/object_id",
|
|
|
|
:_type => :string,
|
|
|
|
:last_attribute => :object
|
|
|
|
}
|
2014-12-31 15:59:32 -05:00
|
|
|
EOS
|
|
|
|
elsif mongoid_3_1?
|
|
|
|
<<-EOS.strip
|
2014-12-31 13:41:17 -05:00
|
|
|
class Chamelion < Object {
|
|
|
|
:_id => :"moped/bson/object_id",
|
|
|
|
:last_attribute => :object
|
|
|
|
}
|
2014-12-31 15:59:32 -05:00
|
|
|
EOS
|
|
|
|
elsif mongoid_4_0?
|
|
|
|
<<-EOS.strip
|
2011-10-26 17:47:15 -04:00
|
|
|
class Chamelion < Object {
|
2014-08-07 21:56:23 -04:00
|
|
|
:_id => :"bson/object_id",
|
2014-12-31 13:41:17 -05:00
|
|
|
:last_attribute => :object
|
2011-10-26 17:47:15 -04:00
|
|
|
}
|
2014-12-31 15:59:32 -05:00
|
|
|
EOS
|
|
|
|
end
|
2014-12-31 13:41:17 -05:00
|
|
|
|
|
|
|
|
2014-12-31 15:59:32 -05:00
|
|
|
expect(@ap.send(:awesome, Chamelion)).to eq class_spec
|
2011-10-26 17:47:15 -04:00
|
|
|
end
|
|
|
|
end
|