mirror of
https://github.com/awesome-print/awesome_print
synced 2023-03-27 23:22:34 -04:00
Fix spacing inoconsistencies which conflict with style guide
This is also so that Hound can be introduced without it bugging people about issues in existing code. --- If git-blame brought you here you may want to read this, the problem is with git-blame, not this change. Try running these two lines just once: `` git config --global alias.praise 'log -p -M --follow --stat --' git config --global alias.praise-line 'log -p -M --pretty=format:"%h (%an %ai)" -L' `` Now in future you can use `git praise <path/to/your/file>` or if you want to see the evolution of a specific line or range of lines `git praise-line <start-line>:<end-line>:<path/to/your/file>` Some examples you should try: `` git praise lib/awesome_print/version.rb git praise-line 8:8:lib/awesome_print/version.rb `` Inspiration for these aliases: http://blog.andrewray.me/a-better-git-blame/`
This commit is contained in:
parent
1e8134d867
commit
4e99526c25
27 changed files with 90 additions and 90 deletions
|
@ -17,11 +17,11 @@ class String
|
|||
%w(gray red green yellow blue purple cyan white).zip(
|
||||
%w(black darkred darkgreen brown navy darkmagenta darkcyan slategray)).each_with_index do |(color, shade), i|
|
||||
define_method color do |*html|
|
||||
html[0] ? %Q|<kbd style="color:#{color}">#{self}</kbd>| : "\e[1;#{30+i}m#{self}\e[0m"
|
||||
html[0] ? %Q|<kbd style="color:#{color}">#{self}</kbd>| : "\e[1;#{30 + i}m#{self}\e[0m"
|
||||
end
|
||||
|
||||
define_method "#{color}ish" do |*html|
|
||||
html[0] ? %Q|<kbd style="color:#{shade}">#{self}</kbd>| : "\e[0;#{30+i}m#{self}\e[0m"
|
||||
html[0] ? %Q|<kbd style="color:#{shade}">#{self}</kbd>| : "\e[0;#{30 + i}m#{self}\e[0m"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ module AwesomePrint
|
|||
cast = cast_without_mongo_mapper(object, type)
|
||||
|
||||
if defined?(::MongoMapper::Document)
|
||||
if object.is_a?(Class) && (object.ancestors & [ ::MongoMapper::Document, ::MongoMapper::EmbeddedDocument ]).size > 0
|
||||
if object.is_a?(Class) && (object.ancestors & [::MongoMapper::Document, ::MongoMapper::EmbeddedDocument]).size > 0
|
||||
cast = :mongo_mapper_class
|
||||
elsif object.is_a?(::MongoMapper::Document) || object.is_a?(::MongoMapper::EmbeddedDocument)
|
||||
cast = :mongo_mapper_instance
|
||||
|
@ -65,7 +65,7 @@ module AwesomePrint
|
|||
return object.inspect if !defined?(::ActiveSupport::OrderedHash)
|
||||
return awesome_object(object) if @options[:raw]
|
||||
|
||||
data = object.keys.keys.sort_by{|k| k}.inject(::ActiveSupport::OrderedHash.new) do |hash, name|
|
||||
data = object.keys.keys.sort_by { |k| k }.inject(::ActiveSupport::OrderedHash.new) do |hash, name|
|
||||
hash[name] = object[name]
|
||||
hash
|
||||
end
|
||||
|
@ -93,7 +93,7 @@ module AwesomePrint
|
|||
return object.inspect if !defined?(::ActiveSupport::OrderedHash)
|
||||
return awesome_object(object) if @options[:raw]
|
||||
|
||||
association = object.class.name.split('::').last.titleize.downcase.sub(/ association$/,'')
|
||||
association = object.class.name.split('::').last.titleize.downcase.sub(/ association$/, '')
|
||||
association = "embeds #{association}" if object.embeddable?
|
||||
class_name = object.class_name
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ module AwesomePrint
|
|||
hash[c[0].to_sym] = c[1]
|
||||
hash
|
||||
end
|
||||
data = {errors: object.errors, attributes: data} if !object.errors.empty?
|
||||
data = { errors: object.errors, attributes: data } if !object.errors.empty?
|
||||
"#{object} #{awesome_hash(data)}"
|
||||
end
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ module AwesomePrint
|
|||
#------------------------------------------------------------------------------
|
||||
def awesome_nobrainer_document(object)
|
||||
data = object.inspectable_attributes.symbolize_keys
|
||||
data = {errors: object.errors, attributes: data} if object.errors.present?
|
||||
data = { errors: object.errors, attributes: data } if object.errors.present?
|
||||
"#{object} #{awesome_hash(data)}"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -32,7 +32,7 @@ module AwesomePrint
|
|||
hash[c[0].to_sym] = c[1]
|
||||
hash
|
||||
end
|
||||
data = {errors: object.errors, values: data} if !object.errors.empty?
|
||||
data = { errors: object.errors, values: data } if !object.errors.empty?
|
||||
"#{object} #{awesome_hash(data)}"
|
||||
end
|
||||
|
||||
|
@ -45,7 +45,7 @@ module AwesomePrint
|
|||
# Format Sequel Model class.
|
||||
#------------------------------------------------------------------------------
|
||||
def awesome_sequel_model_class(object)
|
||||
data = object.db_schema.inject({}) {|h, (name,data)| h.merge(name => data[:db_type])}
|
||||
data = object.db_schema.inject({}) { |h, (name, data)| h.merge(name => data[:db_type]) }
|
||||
"class #{object} < #{object.superclass} " << awesome_hash(data)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,7 +11,7 @@ module AwesomePrint
|
|||
|
||||
attr_reader :inspector, :options
|
||||
|
||||
CORE = [ :array, :bigdecimal, :class, :dir, :file, :hash, :method, :rational, :set, :struct, :unboundmethod ]
|
||||
CORE = [:array, :bigdecimal, :class, :dir, :file, :hash, :method, :rational, :set, :struct, :unboundmethod]
|
||||
|
||||
def initialize(inspector)
|
||||
@inspector = inspector
|
||||
|
@ -107,7 +107,7 @@ module AwesomePrint
|
|||
# Utility methods.
|
||||
#------------------------------------------------------------------------------
|
||||
def convert_to_hash(object)
|
||||
if ! object.respond_to?(:to_hash)
|
||||
if !object.respond_to?(:to_hash)
|
||||
return nil
|
||||
end
|
||||
|
||||
|
@ -116,7 +116,7 @@ module AwesomePrint
|
|||
end
|
||||
|
||||
hash = object.to_hash
|
||||
if ! hash.respond_to?(:keys) || ! hash.respond_to?('[]')
|
||||
if !hash.respond_to?(:keys) || !hash.respond_to?('[]')
|
||||
return nil
|
||||
end
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ module AwesomePrint
|
|||
data = limited(data, width) if should_be_limited?
|
||||
"[\n" << data.join(",\n") << "\n#{outdent}]"
|
||||
else
|
||||
'[ ' << array.map{ |item| inspector.awesome(item) }.join(', ') << ' ]'
|
||||
'[ ' << array.map { |item| inspector.awesome(item) }.join(', ') << ' ]'
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -51,7 +51,7 @@ module AwesomePrint
|
|||
method_tuple(object.instance_method(name)) rescue nil # Rescue to avoid NameError when the method is not
|
||||
end # available (ex. File.lchmod on Ubuntu 12).
|
||||
end
|
||||
tuple || [ name.to_s, '(?)', '?' ] # Return WTF default if all the above fails.
|
||||
tuple || [name.to_s, '(?)', '?'] # Return WTF default if all the above fails.
|
||||
end
|
||||
|
||||
width = (tuples.size - 1).to_s.size
|
||||
|
|
|
@ -50,7 +50,7 @@ module AwesomePrint
|
|||
tail = head - (limit - 1) % 2
|
||||
|
||||
# Add the proper elements to the temp array and format the separator.
|
||||
temp = data[0, head] + [ nil ] + data[-tail, tail]
|
||||
temp = data[0, head] + [nil] + data[-tail, tail]
|
||||
|
||||
if is_hash
|
||||
temp[head] = "#{indent}#{data[head].strip} .. #{data[data.length - tail - 1].strip}"
|
||||
|
@ -97,7 +97,7 @@ module AwesomePrint
|
|||
owner = "#{klass}#{unbound}".gsub('(', ' (')
|
||||
end
|
||||
|
||||
[ method.name.to_s, "(#{args.join(', ')})", owner.to_s ]
|
||||
[method.name.to_s, "(#{args.join(', ')})", owner.to_s]
|
||||
end
|
||||
|
||||
#
|
||||
|
|
|
@ -19,11 +19,11 @@ module AwesomePrint
|
|||
keys = keys.sort { |a, b| a.to_s <=> b.to_s } if options[:sort_keys]
|
||||
data = keys.map do |key|
|
||||
plain_single_line do
|
||||
[ inspector.awesome(key), hash[key] ]
|
||||
[inspector.awesome(key), hash[key]]
|
||||
end
|
||||
end
|
||||
|
||||
width = data.map { |key, | key.size }.max || 0
|
||||
width = data.map { |key, _value| key.size }.max || 0
|
||||
width += indentation if options[:indent] > 0
|
||||
|
||||
data = data.map do |key, value|
|
||||
|
|
|
@ -22,9 +22,9 @@ module AwesomePrint
|
|||
object.respond_to?(property) ? :reader : nil
|
||||
end
|
||||
if accessor
|
||||
[ "attr_#{accessor} :#{property}", var ]
|
||||
["attr_#{accessor} :#{property}", var]
|
||||
else
|
||||
[ var.to_s, var ]
|
||||
[var.to_s, var]
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -22,9 +22,9 @@ module AwesomePrint
|
|||
struct.respond_to?(property) ? :reader : nil
|
||||
end
|
||||
if accessor
|
||||
[ "attr_#{accessor} :#{property}", var ]
|
||||
["attr_#{accessor} :#{property}", var]
|
||||
else
|
||||
[ var.to_s, var ]
|
||||
[var.to_s, var]
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ RSpec.describe 'AwesomePrint' do
|
|||
before do
|
||||
ENV['TERM'] = 'xterm-colors'
|
||||
ENV.delete('ANSICON')
|
||||
@arr = [ 1, :two, 'three', [ nil, [ true, false] ] ]
|
||||
@arr = [1, :two, 'three', [nil, [true, false]]]
|
||||
end
|
||||
|
||||
describe 'default settings (no forced colors)' do
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
require 'spec_helper'
|
||||
|
||||
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
|
||||
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")
|
||||
end
|
||||
|
||||
it "should have #{color}ish color" do
|
||||
expect(color.to_s.send(:"#{color}ish")).to eq("\e[0;#{30+i}m#{color}\e[0m")
|
||||
expect(color.to_s.send(:"#{color}ish")).to eq("\e[0;#{30 + i}m#{color}\e[0m")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'spec_helper'
|
||||
|
||||
RSpec.describe 'AwesomePrint ActionView extensions', skip: ->{ !ExtVerifier.has_rails? }.call do
|
||||
RSpec.describe 'AwesomePrint ActionView extensions', skip: -> { !ExtVerifier.has_rails? }.call do
|
||||
|
||||
before do
|
||||
@view = ActionView::Base.new
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require 'spec_helper'
|
||||
require 'active_record_helper'
|
||||
|
||||
RSpec.describe 'AwesomePrint/ActiveRecord', skip: ->{ !ExtVerifier.has_rails? }.call do
|
||||
RSpec.describe 'AwesomePrint/ActiveRecord', skip: -> { !ExtVerifier.has_rails? }.call do
|
||||
describe 'ActiveRecord instance, attributes only (default)' do
|
||||
before do
|
||||
ActiveRecord::Base.default_timezone = :utc
|
||||
|
@ -30,7 +30,7 @@ RSpec.describe 'AwesomePrint/ActiveRecord', skip: ->{ !ExtVerifier.has_rails? }.
|
|||
end
|
||||
|
||||
it 'display multiple records' do
|
||||
out = @ap.awesome([ @diana, @laura ])
|
||||
out = @ap.awesome([@diana, @laura])
|
||||
str = <<-EOS.strip
|
||||
[
|
||||
[0] #<User:placeholder_id> {
|
||||
|
@ -150,7 +150,7 @@ EOS
|
|||
end
|
||||
|
||||
it 'display multiple records' do
|
||||
out = @ap.awesome([ @diana, @laura ])
|
||||
out = @ap.awesome([@diana, @laura])
|
||||
|
||||
raw_object_string =
|
||||
if activerecord_5_0?
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'spec_helper'
|
||||
|
||||
RSpec.describe 'AwesomePrint::ActiveSupport', skip: ->{ !ExtVerifier.has_rails? }.call do
|
||||
RSpec.describe 'AwesomePrint::ActiveSupport', skip: -> { !ExtVerifier.has_rails? }.call do
|
||||
before do
|
||||
@ap = AwesomePrint::Inspector.new
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'spec_helper'
|
||||
|
||||
RSpec.describe 'AwesomePrint/MongoMapper', skip: ->{ !ExtVerifier.has_mongo_mapper? }.call do
|
||||
RSpec.describe 'AwesomePrint/MongoMapper', skip: -> { !ExtVerifier.has_mongo_mapper? }.call do
|
||||
if ExtVerifier.has_mongo_mapper?
|
||||
before :all do
|
||||
class MongoUser
|
||||
|
@ -12,8 +12,8 @@ RSpec.describe 'AwesomePrint/MongoMapper', skip: ->{ !ExtVerifier.has_mongo_mapp
|
|||
end
|
||||
|
||||
after :all do
|
||||
Object.instance_eval{ remove_const :MongoUser }
|
||||
Object.instance_eval{ remove_const :Chamelion }
|
||||
Object.instance_eval { remove_const :MongoUser }
|
||||
Object.instance_eval { remove_const :Chamelion }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'spec_helper'
|
||||
|
||||
RSpec.describe 'AwesomePrint/Mongoid', skip: ->{ !ExtVerifier.has_mongoid? }.call do
|
||||
RSpec.describe 'AwesomePrint/Mongoid', skip: -> { !ExtVerifier.has_mongoid? }.call do
|
||||
|
||||
if ExtVerifier.has_mongoid?
|
||||
before :all do
|
||||
|
@ -13,8 +13,8 @@ RSpec.describe 'AwesomePrint/Mongoid', skip: ->{ !ExtVerifier.has_mongoid? }.cal
|
|||
end
|
||||
|
||||
after :all do
|
||||
Object.instance_eval{ remove_const :MongoUser }
|
||||
Object.instance_eval{ remove_const :Chamelion }
|
||||
Object.instance_eval { remove_const :MongoUser }
|
||||
Object.instance_eval { remove_const :Chamelion }
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -34,7 +34,7 @@ RSpec.describe 'AwesomePrint/Mongoid', skip: ->{ !ExtVerifier.has_mongoid? }.cal
|
|||
:last_name => "Capone"
|
||||
}
|
||||
EOS
|
||||
expect(out).to be_similar_to(str, {skip_bson: true})
|
||||
expect(out).to be_similar_to(str, { skip_bson: true })
|
||||
end
|
||||
|
||||
it 'should print the class' do
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'spec_helper'
|
||||
|
||||
RSpec.describe 'AwesomePrint/NoBrainer', skip: ->{ !ExtVerifier.has_nobrainer? }.call do
|
||||
RSpec.describe 'AwesomePrint/NoBrainer', skip: -> { !ExtVerifier.has_nobrainer? }.call do
|
||||
|
||||
if ExtVerifier.has_nobrainer?
|
||||
before :all do
|
||||
|
@ -21,7 +21,7 @@ RSpec.describe 'AwesomePrint/NoBrainer', skip: ->{ !ExtVerifier.has_nobrainer? }
|
|||
end
|
||||
|
||||
after :all do
|
||||
Object.instance_eval{ remove_const :SomeModel }
|
||||
Object.instance_eval { remove_const :SomeModel }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'spec_helper'
|
||||
|
||||
RSpec.describe 'AwesomePrint/Ripple', skip: ->{ !ExtVerifier.has_ripple? }.call do
|
||||
RSpec.describe 'AwesomePrint/Ripple', skip: -> { !ExtVerifier.has_ripple? }.call do
|
||||
|
||||
if ExtVerifier.has_ripple?
|
||||
before :all do
|
||||
|
|
|
@ -6,7 +6,7 @@ require 'set'
|
|||
RSpec.describe 'AwesomePrint' do
|
||||
describe 'Array' do
|
||||
before do
|
||||
@arr = [ 1, :two, 'three', [ nil, [ true, false] ] ]
|
||||
@arr = [1, :two, 'three', [nil, [true, false]]]
|
||||
end
|
||||
|
||||
it 'empty array' do
|
||||
|
@ -127,7 +127,7 @@ EOS
|
|||
#------------------------------------------------------------------------------
|
||||
describe 'Nested Array' do
|
||||
before do
|
||||
@arr = [ 1, 2 ]
|
||||
@arr = [1, 2]
|
||||
@arr << @arr
|
||||
end
|
||||
|
||||
|
@ -384,7 +384,7 @@ EOS
|
|||
#------------------------------------------------------------------------------
|
||||
describe 'Hash with several keys' do
|
||||
before do
|
||||
@hash = {'b' => 'b', :a => 'a', :z => 'z', 'alpha' => 'alpha'}
|
||||
@hash = { 'b' => 'b', :a => 'a', :z => 'z', 'alpha' => 'alpha' }
|
||||
end
|
||||
|
||||
it 'plain multiline' do
|
||||
|
@ -439,7 +439,7 @@ EOS
|
|||
end
|
||||
|
||||
it 'nested hash keys should be indented (array of hashes)' do
|
||||
arr = [ { a: 1, bb: 22, ccc: 333}, { 1 => :a, 22 => :bb, 333 => :ccc} ]
|
||||
arr = [{ a: 1, bb: 22, ccc: 333 }, { 1 => :a, 22 => :bb, 333 => :ccc }]
|
||||
out = arr.ai(plain: true, indent: -4, sort_keys: true)
|
||||
expect(out).to eq <<-EOS.strip
|
||||
[
|
||||
|
@ -458,7 +458,7 @@ EOS
|
|||
end
|
||||
|
||||
it 'nested hash keys should be indented (hash of hashes)' do
|
||||
arr = { first: { a: 1, bb: 22, ccc: 333}, second: { 1 => :a, 22 => :bb, 333 => :ccc} }
|
||||
arr = { first: { a: 1, bb: 22, ccc: 333 }, second: { 1 => :a, 22 => :bb, 333 => :ccc } }
|
||||
out = arr.ai(plain: true, indent: -4, sort_keys: true)
|
||||
expect(out).to eq <<-EOS.strip
|
||||
{
|
||||
|
@ -543,7 +543,7 @@ EOS
|
|||
#------------------------------------------------------------------------------
|
||||
describe 'Set' do
|
||||
before do
|
||||
@arr = [1, :two, 'three' ]
|
||||
@arr = [1, :two, 'three']
|
||||
@set = Set.new(@arr)
|
||||
end
|
||||
|
||||
|
@ -569,19 +569,19 @@ EOS
|
|||
end
|
||||
else # Prior to Ruby 1.9 the order of set values is unpredicatble.
|
||||
it 'plain multiline' do
|
||||
expect(@set.sort_by{ |x| x.to_s }.ai(plain: true)).to eq(@arr.sort_by{ |x| x.to_s }.ai(plain: true))
|
||||
expect(@set.sort_by { |x| x.to_s }.ai(plain: true)).to eq(@arr.sort_by { |x| x.to_s }.ai(plain: true))
|
||||
end
|
||||
|
||||
it 'plain multiline indented' do
|
||||
expect(@set.sort_by{ |x| x.to_s }.ai(plain: true, indent: 1)).to eq(@arr.sort_by{ |x| x.to_s }.ai(plain: true, indent: 1))
|
||||
expect(@set.sort_by { |x| x.to_s }.ai(plain: true, indent: 1)).to eq(@arr.sort_by { |x| x.to_s }.ai(plain: true, indent: 1))
|
||||
end
|
||||
|
||||
it 'plain single line' do
|
||||
expect(@set.sort_by{ |x| x.to_s }.ai(plain: true, multiline: false)).to eq(@arr.sort_by{ |x| x.to_s }.ai(plain: true, multiline: false))
|
||||
expect(@set.sort_by { |x| x.to_s }.ai(plain: true, multiline: false)).to eq(@arr.sort_by { |x| x.to_s }.ai(plain: true, multiline: false))
|
||||
end
|
||||
|
||||
it 'colored multiline (default)' do
|
||||
expect(@set.sort_by{ |x| x.to_s }.ai).to eq(@arr.sort_by{ |x| x.to_s }.ai)
|
||||
expect(@set.sort_by { |x| x.to_s }.ai).to eq(@arr.sort_by { |x| x.to_s }.ai)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -648,13 +648,13 @@ EOS
|
|||
#------------------------------------------------------------------------------
|
||||
describe 'Inherited from standard Ruby classes' do
|
||||
after do
|
||||
Object.instance_eval{ remove_const :My } if defined?(My)
|
||||
Object.instance_eval { remove_const :My } if defined?(My)
|
||||
end
|
||||
|
||||
it 'inherited from Array should be displayed as Array' do
|
||||
class My < Array; end
|
||||
|
||||
my = My.new([ 1, :two, 'three', [ nil, [ true, false ] ] ])
|
||||
my = My.new([1, :two, 'three', [nil, [true, false]]])
|
||||
expect(my.ai(plain: true)).to eq <<-EOS.strip
|
||||
[
|
||||
[0] 1,
|
||||
|
@ -674,7 +674,7 @@ EOS
|
|||
it 'inherited from Hash should be displayed as Hash' do
|
||||
class My < Hash; end
|
||||
|
||||
my = My[ { 1 => { sym: { 'str' => { [1, 2, 3] => { { k: :v } => Hash } } } } } ]
|
||||
my = My[{ 1 => { sym: { 'str' => { [1, 2, 3] => { { k: :v } => Hash } } } } }]
|
||||
expect(my.ai(plain: true)).to eq <<-EOS.strip
|
||||
{
|
||||
1 => {
|
||||
|
|
|
@ -2,7 +2,7 @@ require 'spec_helper'
|
|||
|
||||
RSpec.describe 'Single method' do
|
||||
after do
|
||||
Object.instance_eval{ remove_const :Hello } if defined?(Hello)
|
||||
Object.instance_eval { remove_const :Hello } if defined?(Hello)
|
||||
end
|
||||
|
||||
it 'plain: should handle a method with no arguments' do
|
||||
|
@ -65,7 +65,7 @@ RSpec.describe 'Single method' do
|
|||
|
||||
it 'color: should handle an unbound method' do
|
||||
class Hello
|
||||
def world(a,b); end
|
||||
def world(a, b); end
|
||||
end
|
||||
method = Hello.instance_method(:world)
|
||||
if RUBY_VERSION < '1.9.2'
|
||||
|
@ -78,7 +78,7 @@ end
|
|||
|
||||
RSpec.describe 'Object methods' do
|
||||
after do
|
||||
Object.instance_eval{ remove_const :Hello } if defined?(Hello)
|
||||
Object.instance_eval { remove_const :Hello } if defined?(Hello)
|
||||
end
|
||||
|
||||
describe 'object.methods' do
|
||||
|
@ -130,7 +130,7 @@ RSpec.describe 'Object methods' do
|
|||
it 'no index: should handle object.protected_methods' do
|
||||
class Hello
|
||||
protected
|
||||
def m3(a,b); end
|
||||
def m3(a, b); end
|
||||
end
|
||||
if RUBY_VERSION < '1.9.2'
|
||||
expect(Hello.new.protected_methods.ai(plain: true, index: false)).to eq("[\n m3(arg1, arg2) Hello\n]")
|
||||
|
@ -156,7 +156,7 @@ RSpec.describe 'Object methods' do
|
|||
it 'no index: should handle object.private_methods' do
|
||||
class Hello
|
||||
private
|
||||
def m3(a,b); end
|
||||
def m3(a, b); end
|
||||
end
|
||||
out = Hello.new.private_methods.ai(plain: true).split("\n").grep(/m\d/)
|
||||
if RUBY_VERSION < '1.9.2'
|
||||
|
@ -182,7 +182,7 @@ RSpec.describe 'Object methods' do
|
|||
|
||||
it 'no index: should handle object.singleton_methods' do
|
||||
class Hello
|
||||
def self.m3(a,b); end
|
||||
def self.m3(a, b); end
|
||||
end
|
||||
out = Hello.singleton_methods.ai(plain: true, index: false).split("\n").grep(/m\d/)
|
||||
if RUBY_VERSION < '1.9.2'
|
||||
|
@ -196,7 +196,7 @@ end
|
|||
|
||||
RSpec.describe 'Class methods' do
|
||||
after do
|
||||
Object.instance_eval{ remove_const :Hello } if defined?(Hello)
|
||||
Object.instance_eval { remove_const :Hello } if defined?(Hello)
|
||||
end
|
||||
|
||||
describe 'class.instance_methods' do
|
||||
|
@ -212,7 +212,7 @@ RSpec.describe 'Class methods' do
|
|||
|
||||
it 'no index: should handle unbound class.instance_methods' do
|
||||
class Hello
|
||||
def m3(a,b); end
|
||||
def m3(a, b); end
|
||||
end
|
||||
out = Hello.instance_methods.ai(plain: true, index: false).split("\n").grep(/m\d/)
|
||||
if RUBY_VERSION < '1.9.2'
|
||||
|
@ -236,7 +236,7 @@ RSpec.describe 'Class methods' do
|
|||
|
||||
it 'no index: should handle class.public_instance_methods' do
|
||||
class Hello
|
||||
def m3(a,b); end
|
||||
def m3(a, b); end
|
||||
end
|
||||
out = Hello.public_instance_methods.ai(plain: true, index: false).split("\n").grep(/m\d/)
|
||||
if RUBY_VERSION < '1.9.2'
|
||||
|
@ -262,7 +262,7 @@ RSpec.describe 'Class methods' do
|
|||
it 'no index: should handle class.protected_instance_methods' do
|
||||
class Hello
|
||||
protected
|
||||
def m3(a,b); end
|
||||
def m3(a, b); end
|
||||
end
|
||||
out = Hello.protected_instance_methods.ai(plain: true, index: false).split("\n").grep(/m\d/)
|
||||
if RUBY_VERSION < '1.9.2'
|
||||
|
@ -288,7 +288,7 @@ RSpec.describe 'Class methods' do
|
|||
it 'no index: should handle class.private_instance_methods' do
|
||||
class Hello
|
||||
private
|
||||
def m3(a,b); end
|
||||
def m3(a, b); end
|
||||
end
|
||||
out = Hello.private_instance_methods.ai(plain: true, index: false).split("\n").grep(/m\d/)
|
||||
if RUBY_VERSION < '1.9.2'
|
||||
|
@ -307,7 +307,7 @@ if RUBY_VERSION >= '1.9.2'
|
|||
end
|
||||
|
||||
after do
|
||||
Object.instance_eval{ remove_const :Hello } if defined?(Hello)
|
||||
Object.instance_eval { remove_const :Hello } if defined?(Hello)
|
||||
end
|
||||
|
||||
it '()' do
|
||||
|
@ -354,8 +354,8 @@ end
|
|||
|
||||
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)
|
||||
Object.instance_eval { remove_const :Hello } if defined?(Hello)
|
||||
Object.instance_eval { remove_const :World } if defined?(World)
|
||||
end
|
||||
|
||||
it 'obj1.methods - obj2.methods should be awesome printed' do
|
||||
|
@ -432,11 +432,11 @@ RSpec.describe 'Methods arrays' do
|
|||
end
|
||||
|
||||
hello = Hello.new
|
||||
expect((hello.send(:his) - hello.send(:her)).sort_by { |x| x.to_s }).to eq([ :him, :his ])
|
||||
expect((hello.send(:his) - hello.send(:her)).sort_by { |x| x.to_s }).to eq([:him, :his])
|
||||
end
|
||||
|
||||
it 'appending garbage to methods array should not raise error' do
|
||||
arr = 42.methods << [ :wtf ]
|
||||
arr = 42.methods << [:wtf]
|
||||
expect { arr.ai(plain: true) }.not_to raise_error
|
||||
if RUBY_VERSION < '1.9.2'
|
||||
expect(arr.ai(plain: true)).to match(/\s+wtf\(\?\)\s+\?/) # [ :wtf ].to_s => "wtf"
|
||||
|
|
|
@ -87,7 +87,7 @@ RSpec.describe 'AwesomePrint' do
|
|||
end
|
||||
|
||||
it 'wraps multiline ap output with <pre> tag with colorized <kbd>' do
|
||||
markup = [ 1, :two, 'three' ]
|
||||
markup = [1, :two, 'three']
|
||||
expect(markup.ai(html: true)).to eq <<-EOS.strip_heredoc.strip
|
||||
<pre>[
|
||||
<kbd style="color:white">[0] </kbd><kbd style="color:blue">1</kbd>,
|
||||
|
@ -98,7 +98,7 @@ RSpec.describe 'AwesomePrint' do
|
|||
end
|
||||
|
||||
it 'wraps hash ap output with only an outer <pre> tag' do
|
||||
markup = [ { 'hello' => 'world' } ]
|
||||
markup = [{ 'hello' => 'world' }]
|
||||
expect(markup.ai(html: true)).to eq <<-EOS.strip_heredoc.strip
|
||||
<pre>[
|
||||
<kbd style="color:white">[0] </kbd>{
|
||||
|
@ -191,7 +191,7 @@ RSpec.describe 'AwesomePrint' do
|
|||
ENV.delete('RAILS_ENV')
|
||||
expect(AwesomePrint.console?).to eq(true)
|
||||
expect(AwesomePrint.rails_console?).to eq(false)
|
||||
Object.instance_eval{ remove_const :IRB }
|
||||
Object.instance_eval { remove_const :IRB }
|
||||
end
|
||||
|
||||
it 'should detect Pry' do
|
||||
|
@ -199,7 +199,7 @@ RSpec.describe 'AwesomePrint' do
|
|||
ENV.delete('RAILS_ENV')
|
||||
expect(AwesomePrint.console?).to eq(true)
|
||||
expect(AwesomePrint.rails_console?).to eq(false)
|
||||
Object.instance_eval{ remove_const :Pry }
|
||||
Object.instance_eval { remove_const :Pry }
|
||||
end
|
||||
|
||||
it 'should detect Rails::Console' do
|
||||
|
@ -207,8 +207,8 @@ RSpec.describe 'AwesomePrint' do
|
|||
module Rails; class Console; end; end
|
||||
expect(AwesomePrint.console?).to eq(true)
|
||||
expect(AwesomePrint.rails_console?).to eq(true)
|
||||
Object.instance_eval{ remove_const :IRB }
|
||||
Object.instance_eval{ remove_const :Rails }
|
||||
Object.instance_eval { remove_const :IRB }
|
||||
Object.instance_eval { remove_const :Rails }
|
||||
end
|
||||
|
||||
it "should detect ENV['RAILS_ENV']" do
|
||||
|
@ -216,19 +216,19 @@ RSpec.describe 'AwesomePrint' do
|
|||
ENV['RAILS_ENV'] = 'development'
|
||||
expect(AwesomePrint.console?).to eq(true)
|
||||
expect(AwesomePrint.rails_console?).to eq(true)
|
||||
Object.instance_eval{ remove_const :Pry }
|
||||
Object.instance_eval { remove_const :Pry }
|
||||
end
|
||||
|
||||
it 'should return the actual object when *not* running under console' do
|
||||
expect(capture! { ap([ 1, 2, 3 ]) }).to eq([ 1, 2, 3 ])
|
||||
expect(capture! { ap([1, 2, 3]) }).to eq([1, 2, 3])
|
||||
expect(capture! { ap({ a: 1 }) }).to eq({ a: 1 })
|
||||
end
|
||||
|
||||
it 'should return nil when running under console' do
|
||||
class IRB; end
|
||||
expect(capture! { ap([ 1, 2, 3 ]) }).to eq(nil)
|
||||
expect(capture! { ap([1, 2, 3]) }).to eq(nil)
|
||||
expect(capture! { ap({ a: 1 }) }).to eq(nil)
|
||||
Object.instance_eval{ remove_const :IRB }
|
||||
Object.instance_eval { remove_const :IRB }
|
||||
end
|
||||
|
||||
it 'handles NoMethodError on IRB implicit #ai' do
|
||||
|
|
|
@ -2,7 +2,7 @@ require 'spec_helper'
|
|||
|
||||
RSpec.describe 'Objects' do
|
||||
after do
|
||||
Object.instance_eval{ remove_const :Hello } if defined?(Hello)
|
||||
Object.instance_eval { remove_const :Hello } if defined?(Hello)
|
||||
end
|
||||
|
||||
describe 'Formatting an object' do
|
||||
|
|
Loading…
Reference in a new issue