mirror of
https://github.com/awesome-print/awesome_print
synced 2023-03-27 23:22:34 -04:00
Fix string inconsistency
Only using double quoted strings when needing interpolation. 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
473374e78d
commit
ce934093b3
35 changed files with 355 additions and 355 deletions
10
Rakefile
10
Rakefile
|
@ -1,7 +1,7 @@
|
||||||
require "rubygems"
|
require 'rubygems'
|
||||||
require "bundler/setup"
|
require 'bundler/setup'
|
||||||
|
|
||||||
require "bundler"
|
require 'bundler'
|
||||||
Bundler::GemHelper.install_tasks
|
Bundler::GemHelper.install_tasks
|
||||||
|
|
||||||
task :default do
|
task :default do
|
||||||
|
@ -16,9 +16,9 @@ task :appraise do
|
||||||
exec 'appraisal install && appraisal rake'
|
exec 'appraisal install && appraisal rake'
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "Run all awesome_print gem specs"
|
desc 'Run all awesome_print gem specs'
|
||||||
task :spec do
|
task :spec do
|
||||||
# Run plain rspec command without RSpec::Core::RakeTask overrides.
|
# Run plain rspec command without RSpec::Core::RakeTask overrides.
|
||||||
exec "rspec -c spec"
|
exec 'rspec -c spec'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -8,25 +8,25 @@ $:.push File.expand_path('../lib', __FILE__)
|
||||||
require 'awesome_print/version'
|
require 'awesome_print/version'
|
||||||
|
|
||||||
Gem::Specification.new do |s|
|
Gem::Specification.new do |s|
|
||||||
s.name = "awesome_print"
|
s.name = 'awesome_print'
|
||||||
s.version = AwesomePrint.version
|
s.version = AwesomePrint.version
|
||||||
s.authors = "Michael Dvorkin"
|
s.authors = 'Michael Dvorkin'
|
||||||
s.date = Time.now.strftime("%Y-%m-%d")
|
s.date = Time.now.strftime('%Y-%m-%d')
|
||||||
s.email = "mike@dvorkin.net"
|
s.email = 'mike@dvorkin.net'
|
||||||
s.homepage = "https://github.com/awesome-print/awesome_print"
|
s.homepage = 'https://github.com/awesome-print/awesome_print'
|
||||||
s.summary = "Pretty print Ruby objects with proper indentation and colors"
|
s.summary = 'Pretty print Ruby objects with proper indentation and colors'
|
||||||
s.description = "Great Ruby dubugging companion: pretty print Ruby objects to visualize their structure. Supports custom object formatting via plugins"
|
s.description = 'Great Ruby dubugging companion: pretty print Ruby objects to visualize their structure. Supports custom object formatting via plugins'
|
||||||
s.license = "MIT"
|
s.license = 'MIT'
|
||||||
s.rubyforge_project = "awesome_print"
|
s.rubyforge_project = 'awesome_print'
|
||||||
|
|
||||||
s.files = Dir["[A-Z]*[^~]"] + Dir["lib/**/*.rb"] + Dir["spec/*"] + [".gitignore"]
|
s.files = Dir['[A-Z]*[^~]'] + Dir['lib/**/*.rb'] + Dir['spec/*'] + ['.gitignore']
|
||||||
s.test_files = Dir["spec/*"]
|
s.test_files = Dir['spec/*']
|
||||||
s.executables = []
|
s.executables = []
|
||||||
s.require_paths = ["lib"]
|
s.require_paths = ['lib']
|
||||||
|
|
||||||
s.add_development_dependency "rspec", ">= 3.0.0"
|
s.add_development_dependency 'rspec', '>= 3.0.0'
|
||||||
s.add_development_dependency "appraisal"
|
s.add_development_dependency 'appraisal'
|
||||||
s.add_development_dependency "fakefs", ">= 0.2.1"
|
s.add_development_dependency 'fakefs', '>= 0.2.1'
|
||||||
s.add_development_dependency 'sqlite3'
|
s.add_development_dependency 'sqlite3'
|
||||||
s.add_development_dependency 'nokogiri', '>= 1.6.5'
|
s.add_development_dependency 'nokogiri', '>= 1.6.5'
|
||||||
s.add_development_dependency 'simplecov'
|
s.add_development_dependency 'simplecov'
|
||||||
|
|
2
init.rb
2
init.rb
|
@ -1 +1 @@
|
||||||
require File.join(File.dirname(__FILE__), "lib", "awesome_print")
|
require File.join(File.dirname(__FILE__), 'lib', 'awesome_print')
|
||||||
|
|
|
@ -7,4 +7,4 @@
|
||||||
# Keeping this for backwards compatibility to allow
|
# Keeping this for backwards compatibility to allow
|
||||||
# require "ap"
|
# require "ap"
|
||||||
#
|
#
|
||||||
require File.dirname(__FILE__) + "/awesome_print"
|
require File.dirname(__FILE__) + '/awesome_print'
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
autoload :CGI, "cgi"
|
autoload :CGI, 'cgi'
|
||||||
|
|
||||||
module AwesomePrint
|
module AwesomePrint
|
||||||
module Colorize
|
module Colorize
|
||||||
|
|
|
@ -59,7 +59,7 @@ module AwesomePrint
|
||||||
# Format ActiveRecord class object.
|
# Format ActiveRecord class object.
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
def awesome_active_record_class(object)
|
def awesome_active_record_class(object)
|
||||||
return object.inspect if !defined?(::ActiveSupport::OrderedHash) || !object.respond_to?(:columns) || object.to_s == "ActiveRecord::Base"
|
return object.inspect if !defined?(::ActiveSupport::OrderedHash) || !object.respond_to?(:columns) || object.to_s == 'ActiveRecord::Base'
|
||||||
return awesome_class(object) if object.respond_to?(:abstract_class?) && object.abstract_class?
|
return awesome_class(object) if object.respond_to?(:abstract_class?) && object.abstract_class?
|
||||||
|
|
||||||
data = object.columns.inject(::ActiveSupport::OrderedHash.new) do |hash, c|
|
data = object.columns.inject(::ActiveSupport::OrderedHash.new) do |hash, c|
|
||||||
|
|
|
@ -38,7 +38,7 @@ module AwesomePrint
|
||||||
return object.inspect if !defined?(::ActiveSupport::OrderedHash) || !object.respond_to?(:keys)
|
return object.inspect if !defined?(::ActiveSupport::OrderedHash) || !object.respond_to?(:keys)
|
||||||
|
|
||||||
data = object.keys.sort.inject(::ActiveSupport::OrderedHash.new) do |hash, c|
|
data = object.keys.sort.inject(::ActiveSupport::OrderedHash.new) do |hash, c|
|
||||||
hash[c.first] = (c.last.type || "undefined").to_s.underscore.intern
|
hash[c.first] = (c.last.type || 'undefined').to_s.underscore.intern
|
||||||
hash
|
hash
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ module AwesomePrint
|
||||||
return object.inspect if !defined?(::ActiveSupport::OrderedHash) || !object.respond_to?(:fields)
|
return object.inspect if !defined?(::ActiveSupport::OrderedHash) || !object.respond_to?(:fields)
|
||||||
|
|
||||||
data = object.fields.sort_by { |key| key }.inject(::ActiveSupport::OrderedHash.new) do |hash, c|
|
data = object.fields.sort_by { |key| key }.inject(::ActiveSupport::OrderedHash.new) do |hash, c|
|
||||||
hash[c[1].name.to_sym] = (c[1].type || "undefined").to_s.underscore.intern
|
hash[c[1].name.to_sym] = (c[1].type || 'undefined').to_s.underscore.intern
|
||||||
hash
|
hash
|
||||||
end
|
end
|
||||||
"class #{object} < #{object.superclass} " << awesome_hash(data)
|
"class #{object} < #{object.superclass} " << awesome_hash(data)
|
||||||
|
|
|
@ -25,7 +25,7 @@ module AwesomePrint
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
def awesome_nokogiri_xml_node(object)
|
def awesome_nokogiri_xml_node(object)
|
||||||
if object.is_a?(::Nokogiri::XML::NodeSet) && object.empty?
|
if object.is_a?(::Nokogiri::XML::NodeSet) && object.empty?
|
||||||
return "[]"
|
return '[]'
|
||||||
end
|
end
|
||||||
xml = object.to_xml(:indent => 2)
|
xml = object.to_xml(:indent => 2)
|
||||||
#
|
#
|
||||||
|
|
|
@ -52,7 +52,7 @@ module AwesomePrint
|
||||||
end
|
end
|
||||||
|
|
||||||
def awesome_bigdecimal(n)
|
def awesome_bigdecimal(n)
|
||||||
o = n.to_s("F")
|
o = n.to_s('F')
|
||||||
type = :bigdecimal
|
type = :bigdecimal
|
||||||
awesome_simple(o, type, @inspector)
|
awesome_simple(o, type, @inspector)
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,7 +13,7 @@ module AwesomePrint
|
||||||
end
|
end
|
||||||
|
|
||||||
def format
|
def format
|
||||||
return "[]" if array == []
|
return '[]' if array == []
|
||||||
|
|
||||||
if array.instance_variable_defined?(:@__awesome_methods__)
|
if array.instance_variable_defined?(:@__awesome_methods__)
|
||||||
methods_array(array)
|
methods_array(array)
|
||||||
|
@ -31,7 +31,7 @@ module AwesomePrint
|
||||||
data = limited(data, width) if should_be_limited?
|
data = limited(data, width) if should_be_limited?
|
||||||
"[\n" << data.join(",\n") << "\n#{outdent}]"
|
"[\n" << data.join(",\n") << "\n#{outdent}]"
|
||||||
else
|
else
|
||||||
"[ " << array.map{ |item| inspector.awesome(item) }.join(", ") << " ]"
|
'[ ' << array.map{ |item| inspector.awesome(item) }.join(', ') << ' ]'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
require_relative "../colorize"
|
require_relative '../colorize'
|
||||||
|
|
||||||
module AwesomePrint
|
module AwesomePrint
|
||||||
module Formatters
|
module Formatters
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
require_relative 'base_formatter'
|
require_relative 'base_formatter'
|
||||||
require "shellwords"
|
require 'shellwords'
|
||||||
|
|
||||||
module AwesomePrint
|
module AwesomePrint
|
||||||
module Formatters
|
module Formatters
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
require_relative 'base_formatter'
|
require_relative 'base_formatter'
|
||||||
require "shellwords"
|
require 'shellwords'
|
||||||
|
|
||||||
module AwesomePrint
|
module AwesomePrint
|
||||||
module Formatters
|
module Formatters
|
||||||
|
|
|
@ -13,7 +13,7 @@ module AwesomePrint
|
||||||
end
|
end
|
||||||
|
|
||||||
def format
|
def format
|
||||||
return "{}" if hash == {}
|
return '{}' if hash == {}
|
||||||
|
|
||||||
keys = hash.keys
|
keys = hash.keys
|
||||||
keys = keys.sort { |a, b| a.to_s <=> b.to_s } if options[:sort_keys]
|
keys = keys.sort { |a, b| a.to_s <=> b.to_s } if options[:sort_keys]
|
||||||
|
@ -52,11 +52,11 @@ module AwesomePrint
|
||||||
|
|
||||||
def ruby19_syntax(k, v, width)
|
def ruby19_syntax(k, v, width)
|
||||||
k[0] = ''
|
k[0] = ''
|
||||||
align(k, width - 1) << colorize(": ", :hash) << inspector.awesome(v)
|
align(k, width - 1) << colorize(': ', :hash) << inspector.awesome(v)
|
||||||
end
|
end
|
||||||
|
|
||||||
def pre_ruby19_syntax(k, v, width)
|
def pre_ruby19_syntax(k, v, width)
|
||||||
align(k, width) << colorize(" => ", :hash) << inspector.awesome(v)
|
align(k, width) << colorize(' => ', :hash) << inspector.awesome(v)
|
||||||
end
|
end
|
||||||
|
|
||||||
def plain_single_line
|
def plain_single_line
|
||||||
|
|
|
@ -42,7 +42,7 @@ module AwesomePrint
|
||||||
end
|
end
|
||||||
|
|
||||||
indented do
|
indented do
|
||||||
key << colorize(" = ", :hash) + inspector.awesome(object.instance_variable_get(var))
|
key << colorize(' = ', :hash) + inspector.awesome(object.instance_variable_get(var))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ module AwesomePrint
|
||||||
end
|
end
|
||||||
|
|
||||||
indented do
|
indented do
|
||||||
key << colorize(" = ", :hash) + inspector.awesome(struct.send(var))
|
key << colorize(' = ', :hash) + inspector.awesome(struct.send(var))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -6,4 +6,4 @@
|
||||||
#
|
#
|
||||||
# Load awesome_print when installed as Rails 2.3.x plugin.
|
# Load awesome_print when installed as Rails 2.3.x plugin.
|
||||||
#
|
#
|
||||||
require File.join(File.dirname(__FILE__), "..", "init") unless defined?(AwesomePrint)
|
require File.join(File.dirname(__FILE__), '..', 'init') unless defined?(AwesomePrint)
|
||||||
|
|
|
@ -7,7 +7,7 @@ if ExtVerifier.has_rails?
|
||||||
end
|
end
|
||||||
|
|
||||||
# Establish connection to in-memory SQLite DB
|
# Establish connection to in-memory SQLite DB
|
||||||
ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
|
ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:'
|
||||||
|
|
||||||
# Create the users table
|
# Create the users table
|
||||||
ActiveRecord::Migration.verbose = false
|
ActiveRecord::Migration.verbose = false
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
RSpec.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 }
|
||||||
|
@ -9,22 +9,22 @@ RSpec.describe "AwesomePrint" do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "colorization" do
|
describe 'colorization' do
|
||||||
PLAIN = '[ 1, :two, "three", [ nil, [ true, false ] ] ]'
|
PLAIN = '[ 1, :two, "three", [ nil, [ true, false ] ] ]'
|
||||||
COLORIZED = "[ \e[1;34m1\e[0m, \e[0;36m:two\e[0m, \e[0;33m\"three\"\e[0m, [ \e[1;31mnil\e[0m, [ \e[1;32mtrue\e[0m, \e[1;31mfalse\e[0m ] ] ]"
|
COLORIZED = "[ \e[1;34m1\e[0m, \e[0;36m:two\e[0m, \e[0;33m\"three\"\e[0m, [ \e[1;31mnil\e[0m, [ \e[1;32mtrue\e[0m, \e[1;31mfalse\e[0m ] ] ]"
|
||||||
|
|
||||||
before do
|
before do
|
||||||
ENV['TERM'] = "xterm-colors"
|
ENV['TERM'] = 'xterm-colors'
|
||||||
ENV.delete('ANSICON')
|
ENV.delete('ANSICON')
|
||||||
@arr = [ 1, :two, "three", [ nil, [ true, false] ] ]
|
@arr = [ 1, :two, 'three', [ nil, [ true, false] ] ]
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "default settings (no forced colors)" do
|
describe 'default settings (no forced colors)' do
|
||||||
before do
|
before do
|
||||||
AwesomePrint.force_colors! false
|
AwesomePrint.force_colors! false
|
||||||
end
|
end
|
||||||
|
|
||||||
it "colorizes tty processes by default" do
|
it 'colorizes tty processes by default' do
|
||||||
stub_tty!
|
stub_tty!
|
||||||
expect(@arr.ai(:multiline => false)).to eq(COLORIZED)
|
expect(@arr.ai(:multiline => false)).to eq(COLORIZED)
|
||||||
end
|
end
|
||||||
|
@ -32,24 +32,24 @@ RSpec.describe "AwesomePrint" do
|
||||||
it "colorizes processes with ENV['ANSICON'] by default" do
|
it "colorizes processes with ENV['ANSICON'] by default" do
|
||||||
begin
|
begin
|
||||||
stub_tty!
|
stub_tty!
|
||||||
term, ENV['ANSICON'] = ENV['ANSICON'], "1"
|
term, ENV['ANSICON'] = ENV['ANSICON'], '1'
|
||||||
expect(@arr.ai(:multiline => false)).to eq(COLORIZED)
|
expect(@arr.ai(:multiline => false)).to eq(COLORIZED)
|
||||||
ensure
|
ensure
|
||||||
ENV['ANSICON'] = term
|
ENV['ANSICON'] = term
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not colorize tty processes running in dumb terminals by default" do
|
it 'does not colorize tty processes running in dumb terminals by default' do
|
||||||
begin
|
begin
|
||||||
stub_tty!
|
stub_tty!
|
||||||
term, ENV['TERM'] = ENV['TERM'], "dumb"
|
term, ENV['TERM'] = ENV['TERM'], 'dumb'
|
||||||
expect(@arr.ai(:multiline => false)).to eq(PLAIN)
|
expect(@arr.ai(:multiline => false)).to eq(PLAIN)
|
||||||
ensure
|
ensure
|
||||||
ENV['TERM'] = term
|
ENV['TERM'] = term
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not colorize subprocesses by default" do
|
it 'does not colorize subprocesses by default' do
|
||||||
begin
|
begin
|
||||||
stub_tty! false
|
stub_tty! false
|
||||||
expect(@arr.ai(:multiline => false)).to eq(PLAIN)
|
expect(@arr.ai(:multiline => false)).to eq(PLAIN)
|
||||||
|
@ -59,12 +59,12 @@ RSpec.describe "AwesomePrint" do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "forced colors override" do
|
describe 'forced colors override' do
|
||||||
before do
|
before do
|
||||||
AwesomePrint.force_colors!
|
AwesomePrint.force_colors!
|
||||||
end
|
end
|
||||||
|
|
||||||
it "still colorizes tty processes" do
|
it 'still colorizes tty processes' do
|
||||||
stub_tty!
|
stub_tty!
|
||||||
expect(@arr.ai(:multiline => false)).to eq(COLORIZED)
|
expect(@arr.ai(:multiline => false)).to eq(COLORIZED)
|
||||||
end
|
end
|
||||||
|
@ -72,24 +72,24 @@ RSpec.describe "AwesomePrint" do
|
||||||
it "colorizes processes with ENV['ANSICON'] set to 0" do
|
it "colorizes processes with ENV['ANSICON'] set to 0" do
|
||||||
begin
|
begin
|
||||||
stub_tty!
|
stub_tty!
|
||||||
term, ENV['ANSICON'] = ENV['ANSICON'], "1"
|
term, ENV['ANSICON'] = ENV['ANSICON'], '1'
|
||||||
expect(@arr.ai(:multiline => false)).to eq(COLORIZED)
|
expect(@arr.ai(:multiline => false)).to eq(COLORIZED)
|
||||||
ensure
|
ensure
|
||||||
ENV['ANSICON'] = term
|
ENV['ANSICON'] = term
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "colorizes dumb terminals" do
|
it 'colorizes dumb terminals' do
|
||||||
begin
|
begin
|
||||||
stub_tty!
|
stub_tty!
|
||||||
term, ENV['TERM'] = ENV['TERM'], "dumb"
|
term, ENV['TERM'] = ENV['TERM'], 'dumb'
|
||||||
expect(@arr.ai(:multiline => false)).to eq(COLORIZED)
|
expect(@arr.ai(:multiline => false)).to eq(COLORIZED)
|
||||||
ensure
|
ensure
|
||||||
ENV['TERM'] = term
|
ENV['TERM'] = term
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "colorizes subprocess" do
|
it 'colorizes subprocess' do
|
||||||
begin
|
begin
|
||||||
stub_tty! false
|
stub_tty! false
|
||||||
expect(@arr.ai(:multiline => false)).to eq(COLORIZED)
|
expect(@arr.ai(:multiline => false)).to eq(COLORIZED)
|
||||||
|
|
|
@ -4,35 +4,35 @@ require 'spec_helper'
|
||||||
require 'logger'
|
require 'logger'
|
||||||
require 'awesome_print/core_ext/logger'
|
require 'awesome_print/core_ext/logger'
|
||||||
|
|
||||||
RSpec.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
|
||||||
|
|
||||||
describe "ap method" do
|
describe 'ap method' do
|
||||||
it "should awesome_inspect the given object" do
|
it 'should awesome_inspect the given object' do
|
||||||
object = double
|
object = double
|
||||||
expect(object).to receive(:ai)
|
expect(object).to receive(:ai)
|
||||||
@logger.ap object
|
@logger.ap object
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "the log level" do
|
describe 'the log level' do
|
||||||
before do
|
before do
|
||||||
AwesomePrint.defaults = {}
|
AwesomePrint.defaults = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should fallback to the default :debug log level" do
|
it 'should fallback to the default :debug log level' do
|
||||||
expect(@logger).to receive(:debug)
|
expect(@logger).to receive(:debug)
|
||||||
@logger.ap(nil)
|
@logger.ap(nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should use the global user default if no level passed" do
|
it 'should use the global user default if no level passed' do
|
||||||
AwesomePrint.defaults = { :log_level => :info }
|
AwesomePrint.defaults = { :log_level => :info }
|
||||||
expect(@logger).to receive(:info)
|
expect(@logger).to receive(:info)
|
||||||
@logger.ap(nil)
|
@logger.ap(nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should use the passed in level" do
|
it 'should use the passed in level' do
|
||||||
expect(@logger).to receive(:warn)
|
expect(@logger).to receive(:warn)
|
||||||
@logger.ap(nil, :warn)
|
@logger.ap(nil, :warn)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
RSpec.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")
|
||||||
|
@ -11,10 +11,10 @@ RSpec.describe "String extensions" do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should have black and pale colors" do
|
it 'should have black and pale colors' do
|
||||||
expect("black".send(:black)).to eq("black".send(:grayish))
|
expect('black'.send(:black)).to eq('black'.send(:grayish))
|
||||||
expect("pale".send(:pale)).to eq("pale".send(:whiteish))
|
expect('pale'.send(:pale)).to eq('pale'.send(:whiteish))
|
||||||
expect("pale".send(:pale)).to eq("\e[0;37mpale\e[0m")
|
expect('pale'.send(:pale)).to eq("\e[0;37mpale\e[0m")
|
||||||
expect("whiteish".send(:whiteish)).to eq("\e[0;37mwhiteish\e[0m")
|
expect('whiteish'.send(:whiteish)).to eq("\e[0;37mwhiteish\e[0m")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
require 'spec_helper'
|
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
|
before do
|
||||||
@view = ActionView::Base.new
|
@view = ActionView::Base.new
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
require 'active_record_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
|
describe 'ActiveRecord instance, attributes only (default)' 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)
|
@ap = AwesomePrint::Inspector.new(:plain => true, :sort_keys => true)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "display single record" do
|
it 'display single record' do
|
||||||
out = @ap.awesome(@diana)
|
out = @ap.awesome(@diana)
|
||||||
str = <<-EOS.strip
|
str = <<-EOS.strip
|
||||||
#<User:placeholder_id> {
|
#<User:placeholder_id> {
|
||||||
|
@ -29,7 +29,7 @@ RSpec.describe "AwesomePrint/ActiveRecord", skip: ->{ !ExtVerifier.has_rails? }.
|
||||||
expect(out).to be_similar_to(str)
|
expect(out).to be_similar_to(str)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "display multiple records" do
|
it 'display multiple records' do
|
||||||
out = @ap.awesome([ @diana, @laura ])
|
out = @ap.awesome([ @diana, @laura ])
|
||||||
str = <<-EOS.strip
|
str = <<-EOS.strip
|
||||||
[
|
[
|
||||||
|
@ -59,7 +59,7 @@ RSpec.describe "AwesomePrint/ActiveRecord", skip: ->{ !ExtVerifier.has_rails? }.
|
||||||
expect(out).to be_similar_to(str)
|
expect(out).to be_similar_to(str)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "display multiple records on a relation" do
|
it 'display multiple records on a relation' do
|
||||||
@diana.save
|
@diana.save
|
||||||
@laura.save
|
@laura.save
|
||||||
out = @ap.awesome(User.all)
|
out = @ap.awesome(User.all)
|
||||||
|
@ -114,15 +114,15 @@ EOS
|
||||||
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.awesome(@diana)
|
out = @ap.awesome(@diana)
|
||||||
|
|
||||||
raw_object_string =
|
raw_object_string =
|
||||||
|
@ -149,7 +149,7 @@ EOS
|
||||||
expect(out).to be_similar_to(raw_object_string)
|
expect(out).to be_similar_to(raw_object_string)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "display multiple records" do
|
it 'display multiple records' do
|
||||||
out = @ap.awesome([ @diana, @laura ])
|
out = @ap.awesome([ @diana, @laura ])
|
||||||
|
|
||||||
raw_object_string =
|
raw_object_string =
|
||||||
|
@ -179,12 +179,12 @@ EOS
|
||||||
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.awesome(User)).to eq <<-EOS.strip
|
expect(@ap.awesome(User)).to eq <<-EOS.strip
|
||||||
class User < ActiveRecord::Base {
|
class User < ActiveRecord::Base {
|
||||||
:id => :integer,
|
:id => :integer,
|
||||||
|
@ -196,7 +196,7 @@ class User < ActiveRecord::Base {
|
||||||
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.awesome(SubUser)
|
out = @ap.awesome(SubUser)
|
||||||
expect(out).to eq <<-EOS.strip
|
expect(out).to eq <<-EOS.strip
|
||||||
class SubUser < User {
|
class SubUser < User {
|
||||||
|
@ -209,23 +209,23 @@ class SubUser < User {
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should print ActiveRecord::Base objects (ex. ancestors)" do
|
it 'should print ActiveRecord::Base objects (ex. ancestors)' do
|
||||||
expect { @ap.awesome(User.ancestors) }.not_to raise_error
|
expect { @ap.awesome(User.ancestors) }.not_to raise_error
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
describe "ActiveRecord methods formatting" do
|
describe 'ActiveRecord methods formatting' do
|
||||||
before do
|
before do
|
||||||
@ap = AwesomePrint::Inspector.new(:plain => true)
|
@ap = AwesomePrint::Inspector.new(:plain => true)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should format class methods properly" do
|
it 'should format class methods properly' do
|
||||||
# spec 1
|
# spec 1
|
||||||
out = @ap.awesome(User.methods.grep(/first/))
|
out = @ap.awesome(User.methods.grep(/first/))
|
||||||
|
|
||||||
if ActiveRecord::VERSION::STRING >= "3.2"
|
if ActiveRecord::VERSION::STRING >= '3.2'
|
||||||
if RUBY_VERSION >= "1.9"
|
if RUBY_VERSION >= '1.9'
|
||||||
expect(out).to match(/\sfirst\(\*args,\s&block\)\s+Class \(ActiveRecord::Querying\)/)
|
expect(out).to match(/\sfirst\(\*args,\s&block\)\s+Class \(ActiveRecord::Querying\)/)
|
||||||
else
|
else
|
||||||
expect(out).to match(/\sfirst\(\*arg1\)\s+Class \(ActiveRecord::Querying\)/)
|
expect(out).to match(/\sfirst\(\*arg1\)\s+Class \(ActiveRecord::Querying\)/)
|
||||||
|
|
|
@ -1,26 +1,26 @@
|
||||||
require 'spec_helper'
|
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
|
before do
|
||||||
@ap = AwesomePrint::Inspector.new
|
@ap = AwesomePrint::Inspector.new
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should format ActiveSupport::TimeWithZone as regular Time" do
|
it 'should format ActiveSupport::TimeWithZone as regular Time' do
|
||||||
Time.zone = 'Eastern Time (US & Canada)'
|
Time.zone = 'Eastern Time (US & Canada)'
|
||||||
time = Time.utc(2007, 2, 10, 20, 30, 45).in_time_zone
|
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")
|
expect(@ap.send(:awesome, time)).to eq("\e[0;32mSat, 10 Feb 2007 15:30:45 EST -05:00\e[0m")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should format HashWithIndifferentAccess as regular Hash" do
|
it 'should format HashWithIndifferentAccess as regular Hash' do
|
||||||
hash = HashWithIndifferentAccess.new({ :hello => "world" })
|
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}")
|
expect(@ap.send(:awesome, hash)).to eq("{\n \"hello\"\e[0;37m => \e[0m\e[0;33m\"world\"\e[0m\n}")
|
||||||
end
|
end
|
||||||
|
|
||||||
# ActiveSupport sticks in instance variables to the date object. Make sure
|
# ActiveSupport sticks in instance variables to the date object. Make sure
|
||||||
# we ignore that and format Date instance as regular date.
|
# we ignore that and format Date instance as regular date.
|
||||||
it "should formate Date object as date" do
|
it 'should formate Date object as date' do
|
||||||
date = Date.new(2003, 5, 26)
|
date = Date.new(2003, 5, 26)
|
||||||
expect(date.ai(:plain => true)).to eq("Mon, 26 May 2003")
|
expect(date.ai(:plain => true)).to eq('Mon, 26 May 2003')
|
||||||
expect(date.ai).to eq("\e[0;32mMon, 26 May 2003\e[0m")
|
expect(date.ai).to eq("\e[0;32mMon, 26 May 2003\e[0m")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
require 'spec_helper'
|
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?
|
if ExtVerifier.has_mongo_mapper?
|
||||||
before :all do
|
before :all do
|
||||||
class MongoUser
|
class MongoUser
|
||||||
|
@ -21,18 +21,18 @@ RSpec.describe "AwesomePrint/MongoMapper", skip: ->{ !ExtVerifier.has_mongo_mapp
|
||||||
@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:placeholder_id
|
#<MongoUser:placeholder_id
|
||||||
@__mm_default_keys = [
|
@__mm_default_keys = [
|
||||||
|
@ -127,7 +127,7 @@ RSpec.describe "AwesomePrint/MongoMapper", skip: ->{ !ExtVerifier.has_mongo_mapp
|
||||||
expect(out).to be_similar_to(str)
|
expect(out).to be_similar_to(str)
|
||||||
end
|
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,
|
||||||
|
@ -137,7 +137,7 @@ class MongoUser < Object {
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should print the class when type is undefined" do
|
it 'should print the class when type is undefined' do
|
||||||
class Chamelion
|
class Chamelion
|
||||||
include MongoMapper::Document
|
include MongoMapper::Document
|
||||||
key :last_attribute
|
key :last_attribute
|
||||||
|
@ -152,7 +152,7 @@ class Chamelion < Object {
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "with associations" do
|
describe 'with associations' do
|
||||||
|
|
||||||
if ExtVerifier.has_mongo_mapper?
|
if ExtVerifier.has_mongo_mapper?
|
||||||
before :all do
|
before :all do
|
||||||
|
@ -176,8 +176,8 @@ class Chamelion < Object {
|
||||||
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,
|
||||||
|
@ -186,7 +186,7 @@ class Parent < Object {
|
||||||
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
|
||||||
|
@ -199,12 +199,12 @@ class Parent < Object {
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "with show associations turned on and inline embedded turned off" do
|
describe 'with show associations turned on and inline embedded turned off' do
|
||||||
before :each do
|
before :each do
|
||||||
@ap = AwesomePrint::Inspector.new(:plain => true, :mongo_mapper => { :show_associations => true })
|
@ap = AwesomePrint::Inspector.new(:plain => true, :mongo_mapper => { :show_associations => true })
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should render the class with associations shown" do
|
it 'should render the class with associations shown' 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,
|
||||||
|
@ -215,7 +215,7 @@ class Parent < Object {
|
||||||
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
|
||||||
|
@ -230,7 +230,7 @@ class Parent < Object {
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "with show associations turned on and inline embedded turned on" do
|
describe 'with show associations turned on and inline embedded turned on' do
|
||||||
before :each do
|
before :each do
|
||||||
@ap = AwesomePrint::Inspector.new(:plain => true,
|
@ap = AwesomePrint::Inspector.new(:plain => true,
|
||||||
:mongo_mapper => {
|
:mongo_mapper => {
|
||||||
|
@ -240,7 +240,7 @@ class Parent < Object {
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should render an instance with associations shown and embeds there" do
|
it 'should render an instance with associations shown and embeds there' do
|
||||||
parent = Parent.new(:name => 'test', :child => Child.new(:data => 5))
|
parent = Parent.new(:name => 'test', :child => Child.new(:data => 5))
|
||||||
out = @ap.send(:awesome, parent)
|
out = @ap.send(:awesome, parent)
|
||||||
str = <<-EOS.strip
|
str = <<-EOS.strip
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
require 'spec_helper'
|
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?
|
if ExtVerifier.has_mongoid?
|
||||||
before :all do
|
before :all do
|
||||||
|
@ -22,8 +22,8 @@ RSpec.describe "AwesomePrint/Mongoid", skip: ->{ !ExtVerifier.has_mongoid? }.cal
|
||||||
@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
|
||||||
|
@ -37,7 +37,7 @@ RSpec.describe "AwesomePrint/Mongoid", skip: ->{ !ExtVerifier.has_mongoid? }.cal
|
||||||
expect(out).to be_similar_to(str, {:skip_bson => true})
|
expect(out).to be_similar_to(str, {:skip_bson => true})
|
||||||
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 {
|
||||||
|
@ -68,7 +68,7 @@ class MongoUser < Object {
|
||||||
expect(@ap.send(:awesome, MongoUser)).to eq class_spec
|
expect(@ap.send(:awesome, MongoUser)).to eq class_spec
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should print the class when type is undefined" do
|
it 'should print the class when type is undefined' do
|
||||||
class Chamelion
|
class Chamelion
|
||||||
include Mongoid::Document
|
include Mongoid::Document
|
||||||
field :last_attribute
|
field :last_attribute
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
require 'spec_helper'
|
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?
|
if ExtVerifier.has_nobrainer?
|
||||||
before :all do
|
before :all do
|
||||||
NoBrainer.configure do |config|
|
NoBrainer.configure do |config|
|
||||||
config.app_name = "ap_test"
|
config.app_name = 'ap_test'
|
||||||
config.environment = :test
|
config.environment = :test
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -29,8 +29,8 @@ RSpec.describe "AwesomePrint/NoBrainer", skip: ->{ !ExtVerifier.has_nobrainer? }
|
||||||
@ap = AwesomePrint::Inspector.new :plain => true
|
@ap = AwesomePrint::Inspector.new :plain => true
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should print class instance" do
|
it 'should print class instance' do
|
||||||
user = SomeModel.new :first_name => "Al", :last_name => "Capone"
|
user = SomeModel.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
|
||||||
|
@ -44,7 +44,7 @@ RSpec.describe "AwesomePrint/NoBrainer", skip: ->{ !ExtVerifier.has_nobrainer? }
|
||||||
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 = <<-EOS.strip
|
class_spec = <<-EOS.strip
|
||||||
class SomeModel < Object {
|
class SomeModel < Object {
|
||||||
:id => :string,
|
:id => :string,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
RSpec.describe "AwesomePrint/Nokogiri" do
|
RSpec.describe 'AwesomePrint/Nokogiri' do
|
||||||
it "should colorize tags" do
|
it 'should colorize tags' do
|
||||||
xml = Nokogiri::XML('<html><body><h1></h1></body></html>')
|
xml = Nokogiri::XML('<html><body><h1></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
|
||||||
|
@ -13,7 +13,7 @@ RSpec.describe "AwesomePrint/Nokogiri" do
|
||||||
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
|
||||||
|
@ -25,7 +25,7 @@ RSpec.describe "AwesomePrint/Nokogiri" do
|
||||||
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
|
||||||
|
@ -39,7 +39,7 @@ RSpec.describe "AwesomePrint/Nokogiri" do
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
it "handle empty NodeSet" do
|
it 'handle empty NodeSet' do
|
||||||
xml = Nokogiri::XML::NodeSet.new(Nokogiri::XML(''))
|
xml = Nokogiri::XML::NodeSet.new(Nokogiri::XML(''))
|
||||||
expect(xml.ai).to eq('[]')
|
expect(xml.ai).to eq('[]')
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,13 +5,13 @@ RSpec.describe 'AwesomePrint Ostruct extension' do
|
||||||
@ap = AwesomePrint::Inspector.new(:plain => true, :sort_keys => true)
|
@ap = AwesomePrint::Inspector.new(:plain => true, :sort_keys => true)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "empty hash" do
|
it 'empty hash' do
|
||||||
struct = OpenStruct.new
|
struct = OpenStruct.new
|
||||||
expect(@ap.send(:awesome, struct)).to eq("OpenStruct {}")
|
expect(@ap.send(:awesome, struct)).to eq('OpenStruct {}')
|
||||||
end
|
end
|
||||||
|
|
||||||
it "plain multiline" do
|
it 'plain multiline' do
|
||||||
struct = OpenStruct.new :name => "Foo", :address => "Bar"
|
struct = OpenStruct.new :name => 'Foo', :address => 'Bar'
|
||||||
expect(@ap.send(:awesome, struct)).to eq <<-EOS.strip
|
expect(@ap.send(:awesome, struct)).to eq <<-EOS.strip
|
||||||
OpenStruct {
|
OpenStruct {
|
||||||
:address => "Bar",
|
:address => "Bar",
|
||||||
|
|
|
@ -23,8 +23,8 @@ RSpec.describe 'AwesomePrint/Ripple', skip: ->{ !ExtVerifier.has_ripple? }.call
|
||||||
@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).to be_similar_to <<-EOS.strip
|
expect(out).to be_similar_to <<-EOS.strip
|
||||||
|
@ -36,7 +36,7 @@ RSpec.describe 'AwesomePrint/Ripple', skip: ->{ !ExtVerifier.has_ripple? }.call
|
||||||
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,
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
require "bigdecimal"
|
require 'bigdecimal'
|
||||||
require "rational"
|
require 'rational'
|
||||||
require "set"
|
require 'set'
|
||||||
|
|
||||||
RSpec.describe "AwesomePrint" do
|
RSpec.describe 'AwesomePrint' do
|
||||||
describe "Array" do
|
describe 'Array' do
|
||||||
before do
|
before do
|
||||||
@arr = [ 1, :two, "three", [ nil, [ true, false] ] ]
|
@arr = [ 1, :two, 'three', [ nil, [ true, false] ] ]
|
||||||
end
|
end
|
||||||
|
|
||||||
it "empty array" do
|
it 'empty array' do
|
||||||
expect([].ai).to eq("[]")
|
expect([].ai).to eq('[]')
|
||||||
end
|
end
|
||||||
|
|
||||||
it "plain multiline" do
|
it 'plain multiline' do
|
||||||
expect(@arr.ai(:plain => true)).to eq <<-EOS.strip
|
expect(@arr.ai(:plain => true)).to eq <<-EOS.strip
|
||||||
[
|
[
|
||||||
[0] 1,
|
[0] 1,
|
||||||
|
@ -30,7 +30,7 @@ RSpec.describe "AwesomePrint" do
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
it "plain multiline without index" do
|
it 'plain multiline without index' do
|
||||||
expect(@arr.ai(:plain => true, :index => false)).to eq <<-EOS.strip
|
expect(@arr.ai(:plain => true, :index => false)).to eq <<-EOS.strip
|
||||||
[
|
[
|
||||||
1,
|
1,
|
||||||
|
@ -47,7 +47,7 @@ EOS
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
it "plain multiline indented" do
|
it 'plain multiline indented' do
|
||||||
expect(@arr.ai(:plain => true, :indent => 2)).to eq <<-EOS.strip
|
expect(@arr.ai(:plain => true, :indent => 2)).to eq <<-EOS.strip
|
||||||
[
|
[
|
||||||
[0] 1,
|
[0] 1,
|
||||||
|
@ -64,7 +64,7 @@ EOS
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
it "plain multiline indented without index" do
|
it 'plain multiline indented without index' do
|
||||||
expect(@arr.ai(:plain => true, :indent => 2, :index => false)).to eq <<-EOS.strip
|
expect(@arr.ai(:plain => true, :indent => 2, :index => false)).to eq <<-EOS.strip
|
||||||
[
|
[
|
||||||
1,
|
1,
|
||||||
|
@ -81,11 +81,11 @@ EOS
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
it "plain single line" do
|
it 'plain single line' do
|
||||||
expect(@arr.ai(:plain => true, :multiline => false)).to eq('[ 1, :two, "three", [ nil, [ true, false ] ] ]')
|
expect(@arr.ai(:plain => true, :multiline => false)).to eq('[ 1, :two, "three", [ nil, [ true, false ] ] ]')
|
||||||
end
|
end
|
||||||
|
|
||||||
it "colored multiline (default)" do
|
it 'colored multiline (default)' do
|
||||||
expect(@arr.ai).to eq <<-EOS.strip
|
expect(@arr.ai).to eq <<-EOS.strip
|
||||||
[
|
[
|
||||||
\e[1;37m[0] \e[0m\e[1;34m1\e[0m,
|
\e[1;37m[0] \e[0m\e[1;34m1\e[0m,
|
||||||
|
@ -102,7 +102,7 @@ EOS
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
it "colored multiline indented" do
|
it 'colored multiline indented' do
|
||||||
expect(@arr.ai(:indent => 8)).to eq <<-EOS.strip
|
expect(@arr.ai(:indent => 8)).to eq <<-EOS.strip
|
||||||
[
|
[
|
||||||
\e[1;37m[0] \e[0m\e[1;34m1\e[0m,
|
\e[1;37m[0] \e[0m\e[1;34m1\e[0m,
|
||||||
|
@ -119,19 +119,19 @@ EOS
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
it "colored single line" do
|
it 'colored single line' do
|
||||||
expect(@arr.ai(:multiline => false)).to eq("[ \e[1;34m1\e[0m, \e[0;36m:two\e[0m, \e[0;33m\"three\"\e[0m, [ \e[1;31mnil\e[0m, [ \e[1;32mtrue\e[0m, \e[1;31mfalse\e[0m ] ] ]")
|
expect(@arr.ai(:multiline => false)).to eq("[ \e[1;34m1\e[0m, \e[0;36m:two\e[0m, \e[0;33m\"three\"\e[0m, [ \e[1;31mnil\e[0m, [ \e[1;32mtrue\e[0m, \e[1;31mfalse\e[0m ] ] ]")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
describe "Nested Array" do
|
describe 'Nested Array' do
|
||||||
before do
|
before do
|
||||||
@arr = [ 1, 2 ]
|
@arr = [ 1, 2 ]
|
||||||
@arr << @arr
|
@arr << @arr
|
||||||
end
|
end
|
||||||
|
|
||||||
it "plain multiline" do
|
it 'plain multiline' do
|
||||||
expect(@arr.ai(:plain => true)).to eq <<-EOS.strip
|
expect(@arr.ai(:plain => true)).to eq <<-EOS.strip
|
||||||
[
|
[
|
||||||
[0] 1,
|
[0] 1,
|
||||||
|
@ -141,7 +141,7 @@ EOS
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
it "plain multiline without index" do
|
it 'plain multiline without index' do
|
||||||
expect(@arr.ai(:plain => true, :index => false)).to eq <<-EOS.strip
|
expect(@arr.ai(:plain => true, :index => false)).to eq <<-EOS.strip
|
||||||
[
|
[
|
||||||
1,
|
1,
|
||||||
|
@ -151,18 +151,18 @@ EOS
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
it "plain single line" do
|
it 'plain single line' do
|
||||||
expect(@arr.ai(:plain => true, :multiline => false)).to eq("[ 1, 2, [...] ]")
|
expect(@arr.ai(:plain => true, :multiline => false)).to eq('[ 1, 2, [...] ]')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
describe "Limited Output Array" do
|
describe 'Limited Output Array' do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
@arr = (1..1000).to_a
|
@arr = (1..1000).to_a
|
||||||
end
|
end
|
||||||
|
|
||||||
it "plain limited output large" do
|
it 'plain limited output large' do
|
||||||
expect(@arr.ai(:plain => true, :limit => true)).to eq <<-EOS.strip
|
expect(@arr.ai(:plain => true, :limit => true)).to eq <<-EOS.strip
|
||||||
[
|
[
|
||||||
[ 0] 1,
|
[ 0] 1,
|
||||||
|
@ -176,7 +176,7 @@ EOS
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
it "plain limited output small" do
|
it 'plain limited output small' do
|
||||||
@arr = @arr[0..3]
|
@arr = @arr[0..3]
|
||||||
expect(@arr.ai(:plain => true, :limit => true)).to eq <<-EOS.strip
|
expect(@arr.ai(:plain => true, :limit => true)).to eq <<-EOS.strip
|
||||||
[
|
[
|
||||||
|
@ -188,7 +188,7 @@ EOS
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
it "plain limited output with 10 lines" do
|
it 'plain limited output with 10 lines' do
|
||||||
expect(@arr.ai(:plain => true, :limit => 10)).to eq <<-EOS.strip
|
expect(@arr.ai(:plain => true, :limit => 10)).to eq <<-EOS.strip
|
||||||
[
|
[
|
||||||
[ 0] 1,
|
[ 0] 1,
|
||||||
|
@ -205,7 +205,7 @@ EOS
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
it "plain limited output with 11 lines" do
|
it 'plain limited output with 11 lines' do
|
||||||
expect(@arr.ai(:plain => true, :limit => 11)).to eq <<-EOS.strip
|
expect(@arr.ai(:plain => true, :limit => 11)).to eq <<-EOS.strip
|
||||||
[
|
[
|
||||||
[ 0] 1,
|
[ 0] 1,
|
||||||
|
@ -225,12 +225,12 @@ EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
describe "Limited Output Hash" do
|
describe 'Limited Output Hash' do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
@hash = ("a".."z").inject({}) { |h, v| h.merge({ v => v.to_sym }) }
|
@hash = ('a'..'z').inject({}) { |h, v| h.merge({ v => v.to_sym }) }
|
||||||
end
|
end
|
||||||
|
|
||||||
it "plain limited output" do
|
it 'plain limited output' do
|
||||||
expect(@hash.ai(:sort_keys => true, :plain => true, :limit => true)).to eq <<-EOS.strip
|
expect(@hash.ai(:sort_keys => true, :plain => true, :limit => true)).to eq <<-EOS.strip
|
||||||
{
|
{
|
||||||
"a" => :a,
|
"a" => :a,
|
||||||
|
@ -246,16 +246,16 @@ EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
describe "Hash" do
|
describe 'Hash' do
|
||||||
before do
|
before do
|
||||||
@hash = { 1 => { :sym => { "str" => { [1, 2, 3] => { { :k => :v } => Hash } } } } }
|
@hash = { 1 => { :sym => { 'str' => { [1, 2, 3] => { { :k => :v } => Hash } } } } }
|
||||||
end
|
end
|
||||||
|
|
||||||
it "empty hash" do
|
it 'empty hash' do
|
||||||
expect({}.ai).to eq("{}")
|
expect({}.ai).to eq('{}')
|
||||||
end
|
end
|
||||||
|
|
||||||
it "plain multiline" do
|
it 'plain multiline' do
|
||||||
expect(@hash.ai(:plain => true)).to eq <<-EOS.strip
|
expect(@hash.ai(:plain => true)).to eq <<-EOS.strip
|
||||||
{
|
{
|
||||||
1 => {
|
1 => {
|
||||||
|
@ -271,7 +271,7 @@ EOS
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
it "new hash syntax" do
|
it 'new hash syntax' do
|
||||||
expect(@hash.ai(:plain => true, :ruby19_syntax => true)).to eq <<-EOS.strip
|
expect(@hash.ai(:plain => true, :ruby19_syntax => true)).to eq <<-EOS.strip
|
||||||
{
|
{
|
||||||
1 => {
|
1 => {
|
||||||
|
@ -287,7 +287,7 @@ EOS
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
it "plain multiline indented" do
|
it 'plain multiline indented' do
|
||||||
expect(@hash.ai(:plain => true, :indent => 1)).to eq <<-EOS.strip
|
expect(@hash.ai(:plain => true, :indent => 1)).to eq <<-EOS.strip
|
||||||
{
|
{
|
||||||
1 => {
|
1 => {
|
||||||
|
@ -303,11 +303,11 @@ EOS
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
it "plain single line" do
|
it 'plain single line' do
|
||||||
expect(@hash.ai(:plain => true, :multiline => false)).to eq('{ 1 => { :sym => { "str" => { [ 1, 2, 3 ] => { { :k => :v } => Hash < Object } } } } }')
|
expect(@hash.ai(:plain => true, :multiline => false)).to eq('{ 1 => { :sym => { "str" => { [ 1, 2, 3 ] => { { :k => :v } => Hash < Object } } } } }')
|
||||||
end
|
end
|
||||||
|
|
||||||
it "colored multiline (default)" do
|
it 'colored multiline (default)' do
|
||||||
expect(@hash.ai).to eq <<-EOS.strip
|
expect(@hash.ai).to eq <<-EOS.strip
|
||||||
{
|
{
|
||||||
1\e[0;37m => \e[0m{
|
1\e[0;37m => \e[0m{
|
||||||
|
@ -323,7 +323,7 @@ EOS
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
it "colored with new hash syntax" do
|
it 'colored with new hash syntax' do
|
||||||
expect(@hash.ai(:ruby19_syntax => true)).to eq <<-EOS.strip
|
expect(@hash.ai(:ruby19_syntax => true)).to eq <<-EOS.strip
|
||||||
{
|
{
|
||||||
1\e[0;37m => \e[0m{
|
1\e[0;37m => \e[0m{
|
||||||
|
@ -339,7 +339,7 @@ EOS
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
it "colored multiline indented" do
|
it 'colored multiline indented' do
|
||||||
expect(@hash.ai(:indent => 2)).to eq <<-EOS.strip
|
expect(@hash.ai(:indent => 2)).to eq <<-EOS.strip
|
||||||
{
|
{
|
||||||
1\e[0;37m => \e[0m{
|
1\e[0;37m => \e[0m{
|
||||||
|
@ -355,20 +355,20 @@ EOS
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
it "colored single line" do
|
it 'colored single line' do
|
||||||
expect(@hash.ai(:multiline => false)).to eq("{ 1\e[0;37m => \e[0m{ :sym\e[0;37m => \e[0m{ \"str\"\e[0;37m => \e[0m{ [ 1, 2, 3 ]\e[0;37m => \e[0m{ { :k => :v }\e[0;37m => \e[0m\e[1;33mHash < Object\e[0m } } } } }")
|
expect(@hash.ai(:multiline => false)).to eq("{ 1\e[0;37m => \e[0m{ :sym\e[0;37m => \e[0m{ \"str\"\e[0;37m => \e[0m{ [ 1, 2, 3 ]\e[0;37m => \e[0m{ { :k => :v }\e[0;37m => \e[0m\e[1;33mHash < Object\e[0m } } } } }")
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
describe "Nested Hash" do
|
describe 'Nested Hash' do
|
||||||
before do
|
before do
|
||||||
@hash = {}
|
@hash = {}
|
||||||
@hash[:a] = @hash
|
@hash[:a] = @hash
|
||||||
end
|
end
|
||||||
|
|
||||||
it "plain multiline" do
|
it 'plain multiline' do
|
||||||
expect(@hash.ai(:plain => true)).to eq <<-EOS.strip
|
expect(@hash.ai(:plain => true)).to eq <<-EOS.strip
|
||||||
{
|
{
|
||||||
:a => {...}
|
:a => {...}
|
||||||
|
@ -376,18 +376,18 @@ EOS
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
it "plain single line" do
|
it 'plain single line' do
|
||||||
expect(@hash.ai(:plain => true, :multiline => false)).to eq('{ :a => {...} }')
|
expect(@hash.ai(:plain => true, :multiline => false)).to eq('{ :a => {...} }')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
describe "Hash with several keys" do
|
describe 'Hash with several keys' do
|
||||||
before do
|
before do
|
||||||
@hash = {"b" => "b", :a => "a", :z => "z", "alpha" => "alpha"}
|
@hash = {'b' => 'b', :a => 'a', :z => 'z', 'alpha' => 'alpha'}
|
||||||
end
|
end
|
||||||
|
|
||||||
it "plain multiline" do
|
it 'plain multiline' do
|
||||||
out = @hash.ai(:plain => true)
|
out = @hash.ai(:plain => true)
|
||||||
if RUBY_VERSION.to_f < 1.9 # Order of @hash keys is not guaranteed.
|
if RUBY_VERSION.to_f < 1.9 # Order of @hash keys is not guaranteed.
|
||||||
expect(out).to match(/^\{[^\}]+\}/m)
|
expect(out).to match(/^\{[^\}]+\}/m)
|
||||||
|
@ -407,7 +407,7 @@ EOS
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "plain multiline with sorted keys" do
|
it 'plain multiline with sorted keys' do
|
||||||
expect(@hash.ai(:plain => true, :sort_keys => true)).to eq <<-EOS.strip
|
expect(@hash.ai(:plain => true, :sort_keys => true)).to eq <<-EOS.strip
|
||||||
{
|
{
|
||||||
:a => "a",
|
:a => "a",
|
||||||
|
@ -421,13 +421,13 @@ EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
describe "Negative options[:indent]" do
|
describe 'Negative options[:indent]' do
|
||||||
#
|
#
|
||||||
# With Ruby < 1.9 the order of hash keys is not defined so we can't
|
# With Ruby < 1.9 the order of hash keys is not defined so we can't
|
||||||
# reliably compare the output string.
|
# reliably compare the output string.
|
||||||
#
|
#
|
||||||
it "hash keys must be left aligned" do
|
it 'hash keys must be left aligned' do
|
||||||
hash = { [0, 0, 255] => :yellow, :red => "rgb(255, 0, 0)", "magenta" => "rgb(255, 0, 255)" }
|
hash = { [0, 0, 255] => :yellow, :red => 'rgb(255, 0, 0)', 'magenta' => 'rgb(255, 0, 255)' }
|
||||||
out = hash.ai(:plain => true, :indent => -4, :sort_keys => true)
|
out = hash.ai(:plain => true, :indent => -4, :sort_keys => true)
|
||||||
expect(out).to eq <<-EOS.strip
|
expect(out).to eq <<-EOS.strip
|
||||||
{
|
{
|
||||||
|
@ -438,7 +438,7 @@ EOS
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
it "nested hash keys should be indented (array of hashes)" do
|
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)
|
out = arr.ai(:plain => true, :indent => -4, :sort_keys => true)
|
||||||
expect(out).to eq <<-EOS.strip
|
expect(out).to eq <<-EOS.strip
|
||||||
|
@ -457,7 +457,7 @@ EOS
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
it "nested hash keys should be indented (hash of hashes)" do
|
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)
|
out = arr.ai(:plain => true, :indent => -4, :sort_keys => true)
|
||||||
expect(out).to eq <<-EOS.strip
|
expect(out).to eq <<-EOS.strip
|
||||||
|
@ -478,28 +478,28 @@ EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
describe "Class" do
|
describe 'Class' do
|
||||||
it "should show superclass (plain)" do
|
it 'should show superclass (plain)' do
|
||||||
expect(self.class.ai(:plain => true)).to eq("#{self.class} < #{self.class.superclass}")
|
expect(self.class.ai(:plain => true)).to eq("#{self.class} < #{self.class.superclass}")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should show superclass (color)" do
|
it 'should show superclass (color)' do
|
||||||
expect(self.class.ai).to eq("#{self.class} < #{self.class.superclass}".yellow)
|
expect(self.class.ai).to eq("#{self.class} < #{self.class.superclass}".yellow)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
describe "File" do
|
describe 'File' do
|
||||||
it "should display a file (plain)" do
|
it 'should display a file (plain)' do
|
||||||
File.open(__FILE__, "r") do |f|
|
File.open(__FILE__, 'r') do |f|
|
||||||
expect(f.ai(:plain => true)).to eq("#{f.inspect}\n" << `ls -alF #{f.path}`.chop)
|
expect(f.ai(:plain => true)).to eq("#{f.inspect}\n" << `ls -alF #{f.path}`.chop)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
describe "Dir" do
|
describe 'Dir' do
|
||||||
it "should display a direcory (plain)" do
|
it 'should display a direcory (plain)' do
|
||||||
Dir.open(File.dirname(__FILE__)) do |d|
|
Dir.open(File.dirname(__FILE__)) do |d|
|
||||||
expect(d.ai(:plain => true)).to eq("#{d.inspect}\n" << `ls -alF #{d.path}`.chop)
|
expect(d.ai(:plain => true)).to eq("#{d.inspect}\n" << `ls -alF #{d.path}`.chop)
|
||||||
end
|
end
|
||||||
|
@ -507,13 +507,13 @@ EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
describe "BigDecimal and Rational" do
|
describe 'BigDecimal and Rational' do
|
||||||
it "should present BigDecimal object with arbitrary precision" do
|
it 'should present BigDecimal object with arbitrary precision' do
|
||||||
big = BigDecimal("201020102010201020102010201020102010.4")
|
big = BigDecimal('201020102010201020102010201020102010.4')
|
||||||
expect(big.ai(:plain => true)).to eq("201020102010201020102010201020102010.4")
|
expect(big.ai(:plain => true)).to eq('201020102010201020102010201020102010.4')
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should present Rational object with arbitrary precision" do
|
it 'should present Rational object with arbitrary precision' do
|
||||||
rat = Rational(201020102010201020102010201020102010, 2)
|
rat = Rational(201020102010201020102010201020102010, 2)
|
||||||
out = rat.ai(:plain => true)
|
out = rat.ai(:plain => true)
|
||||||
#
|
#
|
||||||
|
@ -521,88 +521,88 @@ EOS
|
||||||
# http://techtime.getharvest.com/blog/harvest-is-now-on-ruby-1-dot-9-3 and
|
# http://techtime.getharvest.com/blog/harvest-is-now-on-ruby-1-dot-9-3 and
|
||||||
# http://www.ruby-forum.com/topic/189397
|
# http://www.ruby-forum.com/topic/189397
|
||||||
#
|
#
|
||||||
if RUBY_VERSION < "1.9"
|
if RUBY_VERSION < '1.9'
|
||||||
expect(out).to eq("100510051005100510051005100510051005")
|
expect(out).to eq('100510051005100510051005100510051005')
|
||||||
else
|
else
|
||||||
expect(out).to eq("100510051005100510051005100510051005/1")
|
expect(out).to eq('100510051005100510051005100510051005/1')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
describe "Utility methods" do
|
describe 'Utility methods' do
|
||||||
it "should merge options" do
|
it 'should merge options' do
|
||||||
ap = AwesomePrint::Inspector.new
|
ap = AwesomePrint::Inspector.new
|
||||||
ap.send(:merge_options!, { :color => { :array => :black }, :indent => 0 })
|
ap.send(:merge_options!, { :color => { :array => :black }, :indent => 0 })
|
||||||
options = ap.instance_variable_get("@options")
|
options = ap.instance_variable_get('@options')
|
||||||
expect(options[:color][:array]).to eq(:black)
|
expect(options[:color][:array]).to eq(:black)
|
||||||
expect(options[:indent]).to eq(0)
|
expect(options[:indent]).to eq(0)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
describe "Set" do
|
describe 'Set' do
|
||||||
before do
|
before do
|
||||||
@arr = [1, :two, "three" ]
|
@arr = [1, :two, 'three' ]
|
||||||
@set = Set.new(@arr)
|
@set = Set.new(@arr)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "empty set" do
|
it 'empty set' do
|
||||||
expect(Set.new.ai).to eq([].ai)
|
expect(Set.new.ai).to eq([].ai)
|
||||||
end
|
end
|
||||||
|
|
||||||
if RUBY_VERSION > "1.9"
|
if RUBY_VERSION > '1.9'
|
||||||
it "plain multiline" do
|
it 'plain multiline' do
|
||||||
expect(@set.ai(:plain => true)).to eq(@arr.ai(:plain => true))
|
expect(@set.ai(:plain => true)).to eq(@arr.ai(:plain => true))
|
||||||
end
|
end
|
||||||
|
|
||||||
it "plain multiline indented" do
|
it 'plain multiline indented' do
|
||||||
expect(@set.ai(:plain => true, :indent => 1)).to eq(@arr.ai(:plain => true, :indent => 1))
|
expect(@set.ai(:plain => true, :indent => 1)).to eq(@arr.ai(:plain => true, :indent => 1))
|
||||||
end
|
end
|
||||||
|
|
||||||
it "plain single line" do
|
it 'plain single line' do
|
||||||
expect(@set.ai(:plain => true, :multiline => false)).to eq(@arr.ai(:plain => true, :multiline => false))
|
expect(@set.ai(:plain => true, :multiline => false)).to eq(@arr.ai(:plain => true, :multiline => false))
|
||||||
end
|
end
|
||||||
|
|
||||||
it "colored multiline (default)" do
|
it 'colored multiline (default)' do
|
||||||
expect(@set.ai).to eq(@arr.ai)
|
expect(@set.ai).to eq(@arr.ai)
|
||||||
end
|
end
|
||||||
else # Prior to Ruby 1.9 the order of set values is unpredicatble.
|
else # Prior to Ruby 1.9 the order of set values is unpredicatble.
|
||||||
it "plain multiline" do
|
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
|
end
|
||||||
|
|
||||||
it "plain multiline indented" do
|
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
|
end
|
||||||
|
|
||||||
it "plain single line" do
|
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
|
end
|
||||||
|
|
||||||
it "colored multiline (default)" do
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
describe "Struct" do
|
describe 'Struct' do
|
||||||
before do
|
before do
|
||||||
@struct = unless defined?(Struct::SimpleStruct)
|
@struct = unless defined?(Struct::SimpleStruct)
|
||||||
Struct.new("SimpleStruct", :name, :address).new
|
Struct.new('SimpleStruct', :name, :address).new
|
||||||
else
|
else
|
||||||
Struct::SimpleStruct.new
|
Struct::SimpleStruct.new
|
||||||
end
|
end
|
||||||
@struct.name = "Herman Munster"
|
@struct.name = 'Herman Munster'
|
||||||
@struct.address = "1313 Mockingbird Lane"
|
@struct.address = '1313 Mockingbird Lane'
|
||||||
end
|
end
|
||||||
|
|
||||||
it "empty struct" do
|
it 'empty struct' do
|
||||||
expect(Struct.new("EmptyStruct").ai).to eq("\e[1;33mStruct::EmptyStruct < Struct\e[0m")
|
expect(Struct.new('EmptyStruct').ai).to eq("\e[1;33mStruct::EmptyStruct < Struct\e[0m")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "plain multiline" do
|
it 'plain multiline' do
|
||||||
s1 = <<-EOS.strip
|
s1 = <<-EOS.strip
|
||||||
address = \"1313 Mockingbird Lane\",
|
address = \"1313 Mockingbird Lane\",
|
||||||
name = \"Herman Munster\"
|
name = \"Herman Munster\"
|
||||||
|
@ -614,7 +614,7 @@ EOS
|
||||||
expect(@struct.ai(:plain => true)).to satisfy { |out| out.match(s1) || out.match(s2) }
|
expect(@struct.ai(:plain => true)).to satisfy { |out| out.match(s1) || out.match(s2) }
|
||||||
end
|
end
|
||||||
|
|
||||||
it "plain multiline indented" do
|
it 'plain multiline indented' do
|
||||||
s1 = <<-EOS.strip
|
s1 = <<-EOS.strip
|
||||||
address = "1313 Mockingbird Lane",
|
address = "1313 Mockingbird Lane",
|
||||||
name = "Herman Munster"
|
name = "Herman Munster"
|
||||||
|
@ -626,13 +626,13 @@ EOS
|
||||||
expect(@struct.ai(:plain => true, :indent => 1)).to satisfy { |out| out.match(s1) || out.match(s2) }
|
expect(@struct.ai(:plain => true, :indent => 1)).to satisfy { |out| out.match(s1) || out.match(s2) }
|
||||||
end
|
end
|
||||||
|
|
||||||
it "plain single line" do
|
it 'plain single line' do
|
||||||
s1 = "address = \"1313 Mockingbird Lane\", name = \"Herman Munster\""
|
s1 = 'address = "1313 Mockingbird Lane", name = "Herman Munster"'
|
||||||
s2 = "name = \"Herman Munster\", address = \"1313 Mockingbird Lane\""
|
s2 = 'name = "Herman Munster", address = "1313 Mockingbird Lane"'
|
||||||
expect(@struct.ai(:plain => true, :multiline => false)).to satisfy { |out| out.match(s1) || out.match(s2) }
|
expect(@struct.ai(:plain => true, :multiline => false)).to satisfy { |out| out.match(s1) || out.match(s2) }
|
||||||
end
|
end
|
||||||
|
|
||||||
it "colored multiline (default)" do
|
it 'colored multiline (default)' do
|
||||||
s1 = <<-EOS.strip
|
s1 = <<-EOS.strip
|
||||||
address\e[0;37m = \e[0m\e[0;33m\"1313 Mockingbird Lane\"\e[0m,
|
address\e[0;37m = \e[0m\e[0;33m\"1313 Mockingbird Lane\"\e[0m,
|
||||||
name\e[0;37m = \e[0m\e[0;33m\"Herman Munster\"\e[0m
|
name\e[0;37m = \e[0m\e[0;33m\"Herman Munster\"\e[0m
|
||||||
|
@ -646,15 +646,15 @@ EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
describe "Inherited from standard Ruby classes" do
|
describe 'Inherited from standard Ruby classes' do
|
||||||
after do
|
after do
|
||||||
Object.instance_eval{ remove_const :My } if defined?(My)
|
Object.instance_eval{ remove_const :My } if defined?(My)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "inherited from Array should be displayed as Array" do
|
it 'inherited from Array should be displayed as Array' do
|
||||||
class My < Array; end
|
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
|
expect(my.ai(:plain => true)).to eq <<-EOS.strip
|
||||||
[
|
[
|
||||||
[0] 1,
|
[0] 1,
|
||||||
|
@ -671,10 +671,10 @@ EOS
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
it "inherited from Hash should be displayed as Hash" do
|
it 'inherited from Hash should be displayed as Hash' do
|
||||||
class My < Hash; end
|
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
|
expect(my.ai(:plain => true)).to eq <<-EOS.strip
|
||||||
{
|
{
|
||||||
1 => {
|
1 => {
|
||||||
|
@ -690,14 +690,14 @@ EOS
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
it "inherited from File should be displayed as File" do
|
it 'inherited from File should be displayed as File' do
|
||||||
class My < File; end
|
class My < File; end
|
||||||
|
|
||||||
my = File.new('/dev/null') rescue File.new('nul')
|
my = File.new('/dev/null') rescue File.new('nul')
|
||||||
expect(my.ai(:plain => true)).to eq("#{my.inspect}\n" << `ls -alF #{my.path}`.chop)
|
expect(my.ai(:plain => true)).to eq("#{my.inspect}\n" << `ls -alF #{my.path}`.chop)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "inherited from Dir should be displayed as Dir" do
|
it 'inherited from Dir should be displayed as Dir' do
|
||||||
class My < Dir; end
|
class My < Dir; end
|
||||||
|
|
||||||
require 'tmpdir'
|
require 'tmpdir'
|
||||||
|
@ -705,7 +705,7 @@ EOS
|
||||||
expect(my.ai(:plain => true)).to eq("#{my.inspect}\n" << `ls -alF #{my.path}`.chop)
|
expect(my.ai(:plain => true)).to eq("#{my.inspect}\n" << `ls -alF #{my.path}`.chop)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should handle a class that defines its own #send method" do
|
it 'should handle a class that defines its own #send method' do
|
||||||
class My
|
class My
|
||||||
def send(arg1, arg2, arg3); end
|
def send(arg1, arg2, arg3); end
|
||||||
end
|
end
|
||||||
|
@ -714,7 +714,7 @@ EOS
|
||||||
expect { my.methods.ai(:plain => true) }.not_to raise_error
|
expect { my.methods.ai(:plain => true) }.not_to raise_error
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should handle a class defines its own #method method (ex. request.method)" do
|
it 'should handle a class defines its own #method method (ex. request.method)' do
|
||||||
class My
|
class My
|
||||||
def method
|
def method
|
||||||
'POST'
|
'POST'
|
||||||
|
@ -725,8 +725,8 @@ EOS
|
||||||
expect { my.methods.ai(:plain => true) }.not_to raise_error
|
expect { my.methods.ai(:plain => true) }.not_to raise_error
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "should handle a class that defines its own #to_hash method" do
|
describe 'should handle a class that defines its own #to_hash method' do
|
||||||
it "that takes arguments" do
|
it 'that takes arguments' do
|
||||||
class My
|
class My
|
||||||
def to_hash(a, b)
|
def to_hash(a, b)
|
||||||
end
|
end
|
||||||
|
@ -736,7 +736,7 @@ EOS
|
||||||
expect { my.ai(:plain => true) }.not_to raise_error
|
expect { my.ai(:plain => true) }.not_to raise_error
|
||||||
end
|
end
|
||||||
|
|
||||||
it "that returns nil" do
|
it 'that returns nil' do
|
||||||
class My
|
class My
|
||||||
def to_hash()
|
def to_hash()
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -1,61 +1,61 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
RSpec.describe "Single method" do
|
RSpec.describe 'Single method' do
|
||||||
after do
|
after do
|
||||||
Object.instance_eval{ remove_const :Hello } if defined?(Hello)
|
Object.instance_eval{ remove_const :Hello } if defined?(Hello)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "plain: should handle a method with no arguments" do
|
it 'plain: should handle a method with no arguments' do
|
||||||
method = ''.method(:upcase)
|
method = ''.method(:upcase)
|
||||||
expect(method.ai(:plain => true)).to eq('String#upcase()')
|
expect(method.ai(:plain => true)).to eq('String#upcase()')
|
||||||
end
|
end
|
||||||
|
|
||||||
it "color: should handle a method with no arguments" do
|
it 'color: should handle a method with no arguments' do
|
||||||
method = ''.method(:upcase)
|
method = ''.method(:upcase)
|
||||||
expect(method.ai).to eq("\e[1;33mString\e[0m#\e[0;35mupcase\e[0m\e[0;37m()\e[0m")
|
expect(method.ai).to eq("\e[1;33mString\e[0m#\e[0;35mupcase\e[0m\e[0;37m()\e[0m")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "plain: should handle a method with one argument" do
|
it 'plain: should handle a method with one argument' do
|
||||||
method = ''.method(:include?)
|
method = ''.method(:include?)
|
||||||
expect(method.ai(:plain => true)).to eq('String#include?(arg1)')
|
expect(method.ai(:plain => true)).to eq('String#include?(arg1)')
|
||||||
end
|
end
|
||||||
|
|
||||||
it "color: should handle a method with one argument" do
|
it 'color: should handle a method with one argument' do
|
||||||
method = ''.method(:include?)
|
method = ''.method(:include?)
|
||||||
expect(method.ai).to eq("\e[1;33mString\e[0m#\e[0;35minclude?\e[0m\e[0;37m(arg1)\e[0m")
|
expect(method.ai).to eq("\e[1;33mString\e[0m#\e[0;35minclude?\e[0m\e[0;37m(arg1)\e[0m")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "plain: should handle a method with two arguments" do
|
it 'plain: should handle a method with two arguments' do
|
||||||
method = ''.method(:tr)
|
method = ''.method(:tr)
|
||||||
expect(method.ai(:plain => true)).to eq('String#tr(arg1, arg2)')
|
expect(method.ai(:plain => true)).to eq('String#tr(arg1, arg2)')
|
||||||
end
|
end
|
||||||
|
|
||||||
it "color: should handle a method with two arguments" do
|
it 'color: should handle a method with two arguments' do
|
||||||
method = ''.method(:tr)
|
method = ''.method(:tr)
|
||||||
expect(method.ai).to eq("\e[1;33mString\e[0m#\e[0;35mtr\e[0m\e[0;37m(arg1, arg2)\e[0m")
|
expect(method.ai).to eq("\e[1;33mString\e[0m#\e[0;35mtr\e[0m\e[0;37m(arg1, arg2)\e[0m")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "plain: should handle a method with multiple arguments" do
|
it 'plain: should handle a method with multiple arguments' do
|
||||||
method = ''.method(:split)
|
method = ''.method(:split)
|
||||||
expect(method.ai(:plain => true)).to eq('String#split(*arg1)')
|
expect(method.ai(:plain => true)).to eq('String#split(*arg1)')
|
||||||
end
|
end
|
||||||
|
|
||||||
it "color: should handle a method with multiple arguments" do
|
it 'color: should handle a method with multiple arguments' do
|
||||||
method = ''.method(:split)
|
method = ''.method(:split)
|
||||||
expect(method.ai).to eq("\e[1;33mString\e[0m#\e[0;35msplit\e[0m\e[0;37m(*arg1)\e[0m")
|
expect(method.ai).to eq("\e[1;33mString\e[0m#\e[0;35msplit\e[0m\e[0;37m(*arg1)\e[0m")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "plain: should handle a method defined in mixin" do
|
it 'plain: should handle a method defined in mixin' do
|
||||||
method = ''.method(:is_a?)
|
method = ''.method(:is_a?)
|
||||||
expect(method.ai(:plain => true)).to eq('String (Kernel)#is_a?(arg1)')
|
expect(method.ai(:plain => true)).to eq('String (Kernel)#is_a?(arg1)')
|
||||||
end
|
end
|
||||||
|
|
||||||
it "color: should handle a method defined in mixin" do
|
it 'color: should handle a method defined in mixin' do
|
||||||
method = ''.method(:is_a?)
|
method = ''.method(:is_a?)
|
||||||
expect(method.ai).to eq("\e[1;33mString (Kernel)\e[0m#\e[0;35mis_a?\e[0m\e[0;37m(arg1)\e[0m")
|
expect(method.ai).to eq("\e[1;33mString (Kernel)\e[0m#\e[0;35mis_a?\e[0m\e[0;37m(arg1)\e[0m")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "plain: should handle an unbound method" do
|
it 'plain: should handle an unbound method' do
|
||||||
class Hello
|
class Hello
|
||||||
def world; end
|
def world; end
|
||||||
end
|
end
|
||||||
|
@ -63,7 +63,7 @@ RSpec.describe "Single method" do
|
||||||
expect(method.ai(:plain => true)).to eq('Hello (unbound)#world()')
|
expect(method.ai(:plain => true)).to eq('Hello (unbound)#world()')
|
||||||
end
|
end
|
||||||
|
|
||||||
it "color: should handle an unbound method" do
|
it 'color: should handle an unbound method' do
|
||||||
class Hello
|
class Hello
|
||||||
def world(a,b); end
|
def world(a,b); end
|
||||||
end
|
end
|
||||||
|
@ -76,49 +76,49 @@ RSpec.describe "Single method" do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
RSpec.describe "Object methods" do
|
RSpec.describe 'Object methods' do
|
||||||
after do
|
after do
|
||||||
Object.instance_eval{ remove_const :Hello } if defined?(Hello)
|
Object.instance_eval{ remove_const :Hello } if defined?(Hello)
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "object.methods" do
|
describe 'object.methods' do
|
||||||
it "index: should handle object.methods" do
|
it 'index: should handle object.methods' do
|
||||||
out = nil.methods.ai(:plain => true).split("\n").grep(/is_a\?/).first
|
out = nil.methods.ai(:plain => true).split("\n").grep(/is_a\?/).first
|
||||||
expect(out).to match(/^\s+\[\s*\d+\]\s+is_a\?\(arg1\)\s+NilClass \(Kernel\)$/)
|
expect(out).to match(/^\s+\[\s*\d+\]\s+is_a\?\(arg1\)\s+NilClass \(Kernel\)$/)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "no index: should handle object.methods" do
|
it 'no index: should handle object.methods' do
|
||||||
out = nil.methods.ai(:plain => true, :index => false).split("\n").grep(/is_a\?/).first
|
out = nil.methods.ai(:plain => true, :index => false).split("\n").grep(/is_a\?/).first
|
||||||
expect(out).to match(/^\s+is_a\?\(arg1\)\s+NilClass \(Kernel\)$/)
|
expect(out).to match(/^\s+is_a\?\(arg1\)\s+NilClass \(Kernel\)$/)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "object.public_methods" do
|
describe 'object.public_methods' do
|
||||||
it "index: should handle object.public_methods" do
|
it 'index: should handle object.public_methods' do
|
||||||
out = nil.public_methods.ai(:plain => true).split("\n").grep(/is_a\?/).first
|
out = nil.public_methods.ai(:plain => true).split("\n").grep(/is_a\?/).first
|
||||||
expect(out).to match(/^\s+\[\s*\d+\]\s+is_a\?\(arg1\)\s+NilClass \(Kernel\)$/)
|
expect(out).to match(/^\s+\[\s*\d+\]\s+is_a\?\(arg1\)\s+NilClass \(Kernel\)$/)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "no index: should handle object.public_methods" do
|
it 'no index: should handle object.public_methods' do
|
||||||
out = nil.public_methods.ai(:plain => true, :index => false).split("\n").grep(/is_a\?/).first
|
out = nil.public_methods.ai(:plain => true, :index => false).split("\n").grep(/is_a\?/).first
|
||||||
expect(out).to match(/^\s+is_a\?\(arg1\)\s+NilClass \(Kernel\)$/)
|
expect(out).to match(/^\s+is_a\?\(arg1\)\s+NilClass \(Kernel\)$/)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "object.private_methods" do
|
describe 'object.private_methods' do
|
||||||
it "index: should handle object.private_methods" do
|
it 'index: should handle object.private_methods' do
|
||||||
out = nil.private_methods.ai(:plain => true).split("\n").grep(/sleep/).first
|
out = nil.private_methods.ai(:plain => true).split("\n").grep(/sleep/).first
|
||||||
expect(out).to match(/^\s+\[\s*\d+\]\s+sleep\(\*arg1\)\s+NilClass \(Kernel\)$/)
|
expect(out).to match(/^\s+\[\s*\d+\]\s+sleep\(\*arg1\)\s+NilClass \(Kernel\)$/)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "no index: should handle object.private_methods" do
|
it 'no index: should handle object.private_methods' do
|
||||||
out = nil.private_methods.ai(:plain => true, :index => false).split("\n").grep(/sleep/).first
|
out = nil.private_methods.ai(:plain => true, :index => false).split("\n").grep(/sleep/).first
|
||||||
expect(out).to match(/^\s+sleep\(\*arg1\)\s+NilClass \(Kernel\)$/)
|
expect(out).to match(/^\s+sleep\(\*arg1\)\s+NilClass \(Kernel\)$/)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "object.protected_methods" do
|
describe 'object.protected_methods' do
|
||||||
it "index: should handle object.protected_methods" do
|
it 'index: should handle object.protected_methods' do
|
||||||
class Hello
|
class Hello
|
||||||
protected
|
protected
|
||||||
def m1; end
|
def m1; end
|
||||||
|
@ -127,7 +127,7 @@ RSpec.describe "Object methods" do
|
||||||
expect(Hello.new.protected_methods.ai(:plain => true)).to eq("[\n [0] m1() Hello\n [1] m2() Hello\n]")
|
expect(Hello.new.protected_methods.ai(:plain => true)).to eq("[\n [0] m1() Hello\n [1] m2() Hello\n]")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "no index: should handle object.protected_methods" do
|
it 'no index: should handle object.protected_methods' do
|
||||||
class Hello
|
class Hello
|
||||||
protected
|
protected
|
||||||
def m3(a,b); end
|
def m3(a,b); end
|
||||||
|
@ -140,8 +140,8 @@ RSpec.describe "Object methods" do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "object.private_methods" do
|
describe 'object.private_methods' do
|
||||||
it "index: should handle object.private_methods" do
|
it 'index: should handle object.private_methods' do
|
||||||
class Hello
|
class Hello
|
||||||
private
|
private
|
||||||
def m1; end
|
def m1; end
|
||||||
|
@ -153,7 +153,7 @@ RSpec.describe "Object methods" do
|
||||||
expect(out.last).to match(/^\s+\[\s*\d+\]\s+m2\(\)\s+Hello$/)
|
expect(out.last).to match(/^\s+\[\s*\d+\]\s+m2\(\)\s+Hello$/)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "no index: should handle object.private_methods" do
|
it 'no index: should handle object.private_methods' do
|
||||||
class Hello
|
class Hello
|
||||||
private
|
private
|
||||||
def m3(a,b); end
|
def m3(a,b); end
|
||||||
|
@ -167,8 +167,8 @@ RSpec.describe "Object methods" do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "object.singleton_methods" do
|
describe 'object.singleton_methods' do
|
||||||
it "index: should handle object.singleton_methods" do
|
it 'index: should handle object.singleton_methods' do
|
||||||
class Hello
|
class Hello
|
||||||
class << self
|
class << self
|
||||||
def m1; end
|
def m1; end
|
||||||
|
@ -180,7 +180,7 @@ RSpec.describe "Object methods" do
|
||||||
expect(out.last).to match(/^\s+\[\s*\d+\]\s+m2\(\)\s+Hello$/)
|
expect(out.last).to match(/^\s+\[\s*\d+\]\s+m2\(\)\s+Hello$/)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "no index: should handle object.singleton_methods" do
|
it 'no index: should handle object.singleton_methods' do
|
||||||
class Hello
|
class Hello
|
||||||
def self.m3(a,b); end
|
def self.m3(a,b); end
|
||||||
end
|
end
|
||||||
|
@ -194,13 +194,13 @@ RSpec.describe "Object methods" do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
RSpec.describe "Class methods" do
|
RSpec.describe 'Class methods' do
|
||||||
after do
|
after do
|
||||||
Object.instance_eval{ remove_const :Hello } if defined?(Hello)
|
Object.instance_eval{ remove_const :Hello } if defined?(Hello)
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "class.instance_methods" do
|
describe 'class.instance_methods' do
|
||||||
it "index: should handle unbound class.instance_methods" do
|
it 'index: should handle unbound class.instance_methods' do
|
||||||
class Hello
|
class Hello
|
||||||
def m1; end
|
def m1; end
|
||||||
def m2; end
|
def m2; end
|
||||||
|
@ -210,7 +210,7 @@ RSpec.describe "Class methods" do
|
||||||
expect(out.last).to match(/^\s+\[\s*\d+\]\s+m2\(\)\s+Hello\s\(unbound\)$/)
|
expect(out.last).to match(/^\s+\[\s*\d+\]\s+m2\(\)\s+Hello\s\(unbound\)$/)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "no index: should handle unbound class.instance_methods" do
|
it 'no index: should handle unbound class.instance_methods' do
|
||||||
class Hello
|
class Hello
|
||||||
def m3(a,b); end
|
def m3(a,b); end
|
||||||
end
|
end
|
||||||
|
@ -223,8 +223,8 @@ RSpec.describe "Class methods" do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "class.public_instance_methods" do
|
describe 'class.public_instance_methods' do
|
||||||
it "index: should handle class.public_instance_methods" do
|
it 'index: should handle class.public_instance_methods' do
|
||||||
class Hello
|
class Hello
|
||||||
def m1; end
|
def m1; end
|
||||||
def m2; end
|
def m2; end
|
||||||
|
@ -234,7 +234,7 @@ RSpec.describe "Class methods" do
|
||||||
expect(out.last).to match(/^\s+\[\s*\d+\]\s+m2\(\)\s+Hello\s\(unbound\)$/)
|
expect(out.last).to match(/^\s+\[\s*\d+\]\s+m2\(\)\s+Hello\s\(unbound\)$/)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "no index: should handle class.public_instance_methods" do
|
it 'no index: should handle class.public_instance_methods' do
|
||||||
class Hello
|
class Hello
|
||||||
def m3(a,b); end
|
def m3(a,b); end
|
||||||
end
|
end
|
||||||
|
@ -247,8 +247,8 @@ RSpec.describe "Class methods" do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "class.protected_instance_methods" do
|
describe 'class.protected_instance_methods' do
|
||||||
it "index: should handle class.protected_instance_methods" do
|
it 'index: should handle class.protected_instance_methods' do
|
||||||
class Hello
|
class Hello
|
||||||
protected
|
protected
|
||||||
def m1; end
|
def m1; end
|
||||||
|
@ -259,7 +259,7 @@ RSpec.describe "Class methods" do
|
||||||
expect(out.last).to match(/^\s+\[\s*\d+\]\s+m2\(\)\s+Hello\s\(unbound\)$/)
|
expect(out.last).to match(/^\s+\[\s*\d+\]\s+m2\(\)\s+Hello\s\(unbound\)$/)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "no index: should handle class.protected_instance_methods" do
|
it 'no index: should handle class.protected_instance_methods' do
|
||||||
class Hello
|
class Hello
|
||||||
protected
|
protected
|
||||||
def m3(a,b); end
|
def m3(a,b); end
|
||||||
|
@ -273,8 +273,8 @@ RSpec.describe "Class methods" do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "class.private_instance_methods" do
|
describe 'class.private_instance_methods' do
|
||||||
it "index: should handle class.private_instance_methods" do
|
it 'index: should handle class.private_instance_methods' do
|
||||||
class Hello
|
class Hello
|
||||||
private
|
private
|
||||||
def m1; end
|
def m1; end
|
||||||
|
@ -285,7 +285,7 @@ RSpec.describe "Class methods" do
|
||||||
expect(out.last).to match(/^\s+\[\s*\d+\]\s+m2\(\)\s+Hello\s\(unbound\)$/)
|
expect(out.last).to match(/^\s+\[\s*\d+\]\s+m2\(\)\s+Hello\s\(unbound\)$/)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "no index: should handle class.private_instance_methods" do
|
it 'no index: should handle class.private_instance_methods' do
|
||||||
class Hello
|
class Hello
|
||||||
private
|
private
|
||||||
def m3(a,b); end
|
def m3(a,b); end
|
||||||
|
@ -301,7 +301,7 @@ RSpec.describe "Class methods" do
|
||||||
end
|
end
|
||||||
|
|
||||||
if RUBY_VERSION >= '1.9.2'
|
if RUBY_VERSION >= '1.9.2'
|
||||||
RSpec.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
|
||||||
|
@ -310,7 +310,7 @@ if RUBY_VERSION >= '1.9.2'
|
||||||
Object.instance_eval{ remove_const :Hello } if defined?(Hello)
|
Object.instance_eval{ remove_const :Hello } if defined?(Hello)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "()" do
|
it '()' do
|
||||||
class Hello
|
class Hello
|
||||||
def m1; end
|
def m1; end
|
||||||
end
|
end
|
||||||
|
@ -318,7 +318,7 @@ if RUBY_VERSION >= '1.9.2'
|
||||||
expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(\)\s+Hello$/)
|
expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(\)\s+Hello$/)
|
||||||
end
|
end
|
||||||
|
|
||||||
it ":req" do
|
it ':req' do
|
||||||
class Hello
|
class Hello
|
||||||
def m1(a, b, c); end
|
def m1(a, b, c); end
|
||||||
end
|
end
|
||||||
|
@ -326,7 +326,7 @@ if RUBY_VERSION >= '1.9.2'
|
||||||
expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(a, b, c\)\s+Hello$/)
|
expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(a, b, c\)\s+Hello$/)
|
||||||
end
|
end
|
||||||
|
|
||||||
it ":opt" do
|
it ':opt' do
|
||||||
class Hello
|
class Hello
|
||||||
def m1(a, b = 1, c = 2); end # m1(a, *b, *c)
|
def m1(a, b = 1, c = 2); end # m1(a, *b, *c)
|
||||||
end
|
end
|
||||||
|
@ -334,7 +334,7 @@ if RUBY_VERSION >= '1.9.2'
|
||||||
expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(a, \*b, \*c\)\s+Hello$/)
|
expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(a, \*b, \*c\)\s+Hello$/)
|
||||||
end
|
end
|
||||||
|
|
||||||
it ":rest" do
|
it ':rest' do
|
||||||
class Hello
|
class Hello
|
||||||
def m1(*a); end # m1(*a)
|
def m1(*a); end # m1(*a)
|
||||||
end
|
end
|
||||||
|
@ -342,7 +342,7 @@ if RUBY_VERSION >= '1.9.2'
|
||||||
expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(\*a\)\s+Hello$/)
|
expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(\*a\)\s+Hello$/)
|
||||||
end
|
end
|
||||||
|
|
||||||
it ":block" do
|
it ':block' do
|
||||||
class Hello
|
class Hello
|
||||||
def m1(a, b = nil, &blk); end # m1(a, *b, &blk)
|
def m1(a, b = nil, &blk); end # m1(a, *b, &blk)
|
||||||
end
|
end
|
||||||
|
@ -352,13 +352,13 @@ if RUBY_VERSION >= '1.9.2'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
RSpec.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)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "obj1.methods - obj2.methods should be awesome printed" do
|
it 'obj1.methods - obj2.methods should be awesome printed' do
|
||||||
stub_dotfile!
|
stub_dotfile!
|
||||||
class Hello
|
class Hello
|
||||||
def self.m1; end
|
def self.m1; end
|
||||||
|
@ -367,7 +367,7 @@ RSpec.describe "Methods arrays" do
|
||||||
expect(out).to eq("[\n [0] m1() Hello\n]")
|
expect(out).to eq("[\n [0] m1() Hello\n]")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "obj1.methods & obj2.methods should be awesome printed" do
|
it 'obj1.methods & obj2.methods should be awesome printed' do
|
||||||
stub_dotfile!
|
stub_dotfile!
|
||||||
class Hello
|
class Hello
|
||||||
def self.m1; end
|
def self.m1; end
|
||||||
|
@ -380,7 +380,7 @@ RSpec.describe "Methods arrays" do
|
||||||
expect(out).to eq("[\n [0] m1() Hello\n]")
|
expect(out).to eq("[\n [0] m1() Hello\n]")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "obj1.methods.grep(pattern) should be awesome printed" do
|
it 'obj1.methods.grep(pattern) should be awesome printed' do
|
||||||
stub_dotfile!
|
stub_dotfile!
|
||||||
class Hello
|
class Hello
|
||||||
def self.m1; end
|
def self.m1; end
|
||||||
|
@ -393,7 +393,7 @@ RSpec.describe "Methods arrays" do
|
||||||
expect(out).to eq("[\n [0] m1() Hello\n [1] m2() Hello\n [2] m3() Hello\n]")
|
expect(out).to eq("[\n [0] m1() Hello\n [1] m2() Hello\n [2] m3() Hello\n]")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "obj1.methods.grep(pattern, &block) should pass the matching string within the block" do
|
it 'obj1.methods.grep(pattern, &block) should pass the matching string within the block' do
|
||||||
class Hello
|
class Hello
|
||||||
def self.m_one; end
|
def self.m_one; end
|
||||||
def self.m_two; end
|
def self.m_two; end
|
||||||
|
@ -403,7 +403,7 @@ RSpec.describe "Methods arrays" do
|
||||||
expect(out).to eq([:one, :two])
|
expect(out).to eq([:one, :two])
|
||||||
end
|
end
|
||||||
|
|
||||||
it "obj1.methods.grep(pattern, &block) should be awesome printed" do
|
it 'obj1.methods.grep(pattern, &block) should be awesome printed' do
|
||||||
stub_dotfile!
|
stub_dotfile!
|
||||||
class Hello
|
class Hello
|
||||||
def self.m0; end
|
def self.m0; end
|
||||||
|
@ -417,7 +417,7 @@ RSpec.describe "Methods arrays" do
|
||||||
end
|
end
|
||||||
|
|
||||||
# See https://github.com/awesome-print/awesome_print/issues/30 for details.
|
# See https://github.com/awesome-print/awesome_print/issues/30 for details.
|
||||||
it "grepping methods and converting them to_sym should work as expected" do
|
it 'grepping methods and converting them to_sym should work as expected' do
|
||||||
class Hello
|
class Hello
|
||||||
private
|
private
|
||||||
def him; end
|
def him; end
|
||||||
|
@ -435,7 +435,7 @@ RSpec.describe "Methods arrays" do
|
||||||
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
|
end
|
||||||
|
|
||||||
it "appending garbage to methods array should not raise error" do
|
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
|
expect { arr.ai(:plain => true) }.not_to raise_error
|
||||||
if RUBY_VERSION < '1.9.2'
|
if RUBY_VERSION < '1.9.2'
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
RSpec.describe "AwesomePrint" do
|
RSpec.describe 'AwesomePrint' do
|
||||||
|
|
||||||
describe "Misc" do
|
describe 'Misc' do
|
||||||
it "handle weird objects that return nil on inspect" do
|
it 'handle weird objects that return nil on inspect' do
|
||||||
weird = Class.new do
|
weird = Class.new do
|
||||||
def inspect
|
def inspect
|
||||||
nil
|
nil
|
||||||
|
@ -12,24 +12,24 @@ RSpec.describe "AwesomePrint" do
|
||||||
expect(weird.new.ai(:plain => true)).to eq('')
|
expect(weird.new.ai(:plain => true)).to eq('')
|
||||||
end
|
end
|
||||||
|
|
||||||
it "handle frozen object.inspect" do
|
it 'handle frozen object.inspect' do
|
||||||
weird = Class.new do
|
weird = Class.new do
|
||||||
def inspect
|
def inspect
|
||||||
"ice".freeze
|
'ice'.freeze
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
expect(weird.new.ai(:plain => false)).to eq("ice")
|
expect(weird.new.ai(:plain => false)).to eq('ice')
|
||||||
end
|
end
|
||||||
|
|
||||||
# See https://github.com/awesome-print/awesome_print/issues/35
|
# See https://github.com/awesome-print/awesome_print/issues/35
|
||||||
it "handle array grep when pattern contains / chapacter" do
|
it 'handle array grep when pattern contains / chapacter' do
|
||||||
hash = { "1/x" => 1, "2//x" => :"2" }
|
hash = { '1/x' => 1, '2//x' => :"2" }
|
||||||
grepped = hash.keys.sort.grep(/^(\d+)\//) { $1 }
|
grepped = hash.keys.sort.grep(/^(\d+)\//) { $1 }
|
||||||
expect(grepped.ai(:plain => true, :multiline => false)).to eq('[ "1", "2" ]')
|
expect(grepped.ai(:plain => true, :multiline => false)).to eq('[ "1", "2" ]')
|
||||||
end
|
end
|
||||||
|
|
||||||
# See https://github.com/awesome-print/awesome_print/issues/85
|
# See https://github.com/awesome-print/awesome_print/issues/85
|
||||||
if RUBY_VERSION >= "1.8.7"
|
if RUBY_VERSION >= '1.8.7'
|
||||||
it "handle array grep when a method is defined in C and thus doesn't have a binding" do
|
it "handle array grep when a method is defined in C and thus doesn't have a binding" do
|
||||||
arr = (0..6).to_a
|
arr = (0..6).to_a
|
||||||
grepped = arr.grep(1..4, &:succ)
|
grepped = arr.grep(1..4, &:succ)
|
||||||
|
@ -37,7 +37,7 @@ RSpec.describe "AwesomePrint" do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns value passed as a parameter" do
|
it 'returns value passed as a parameter' do
|
||||||
object = rand
|
object = rand
|
||||||
allow(self).to receive(:puts)
|
allow(self).to receive(:puts)
|
||||||
expect(ap object).to eq(object)
|
expect(ap object).to eq(object)
|
||||||
|
@ -49,20 +49,20 @@ RSpec.describe "AwesomePrint" do
|
||||||
expect { rand.ai }.not_to raise_error
|
expect { rand.ai }.not_to raise_error
|
||||||
end
|
end
|
||||||
|
|
||||||
it "format ENV as hash" do
|
it 'format ENV as hash' do
|
||||||
expect(ENV.ai(:plain => true)).to eq(ENV.to_hash.ai(:plain => true))
|
expect(ENV.ai(:plain => true)).to eq(ENV.to_hash.ai(:plain => true))
|
||||||
expect(ENV.ai).to eq(ENV.to_hash.ai)
|
expect(ENV.ai).to eq(ENV.to_hash.ai)
|
||||||
end
|
end
|
||||||
|
|
||||||
# See https://github.com/awesome-print/awesome_print/issues/134
|
# See https://github.com/awesome-print/awesome_print/issues/134
|
||||||
it "IPAddr workaround" do
|
it 'IPAddr workaround' do
|
||||||
require "ipaddr"
|
require 'ipaddr'
|
||||||
ipaddr = IPAddr.new("3ffe:505:2::1")
|
ipaddr = IPAddr.new('3ffe:505:2::1')
|
||||||
expect(ipaddr.ai).to eq("#<IPAddr: IPv6:3ffe:0505:0002:0000:0000:0000:0000:0001/ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff>")
|
expect(ipaddr.ai).to eq('#<IPAddr: IPv6:3ffe:0505:0002:0000:0000:0000:0000:0001/ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff>')
|
||||||
end
|
end
|
||||||
|
|
||||||
# See https://github.com/awesome-print/awesome_print/issues/139
|
# See https://github.com/awesome-print/awesome_print/issues/139
|
||||||
it "Object that overrides == and expects the :id method" do
|
it 'Object that overrides == and expects the :id method' do
|
||||||
weird = Class.new do
|
weird = Class.new do
|
||||||
# Raises NoMethodError: undefined method `id' when "other" is nil or ENV.
|
# Raises NoMethodError: undefined method `id' when "other" is nil or ENV.
|
||||||
def ==(other)
|
def ==(other)
|
||||||
|
@ -75,19 +75,19 @@ RSpec.describe "AwesomePrint" do
|
||||||
end
|
end
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
describe "HTML output" do
|
describe 'HTML output' do
|
||||||
it "wraps ap output with plain <pre> tag" do
|
it 'wraps ap output with plain <pre> tag' do
|
||||||
markup = rand
|
markup = rand
|
||||||
expect(markup.ai(:html => true, :plain => true)).to eq("<pre>#{markup}</pre>")
|
expect(markup.ai(:html => true, :plain => true)).to eq("<pre>#{markup}</pre>")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "wraps ap output with <pre> tag with colorized <kbd>" do
|
it 'wraps ap output with <pre> tag with colorized <kbd>' do
|
||||||
markup = rand
|
markup = rand
|
||||||
expect(markup.ai(:html => true)).to eq(%Q|<pre><kbd style="color:blue">#{markup}</kbd></pre>|)
|
expect(markup.ai(:html => true)).to eq(%Q|<pre><kbd style="color:blue">#{markup}</kbd></pre>|)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "wraps multiline ap output with <pre> tag with colorized <kbd>" do
|
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
|
expect(markup.ai(:html => true)).to eq <<-EOS.strip_heredoc.strip
|
||||||
<pre>[
|
<pre>[
|
||||||
<kbd style="color:white">[0] </kbd><kbd style="color:blue">1</kbd>,
|
<kbd style="color:white">[0] </kbd><kbd style="color:blue">1</kbd>,
|
||||||
|
@ -97,8 +97,8 @@ RSpec.describe "AwesomePrint" do
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
it "wraps hash ap output with only an outer <pre> tag" do
|
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
|
expect(markup.ai(:html => true)).to eq <<-EOS.strip_heredoc.strip
|
||||||
<pre>[
|
<pre>[
|
||||||
<kbd style="color:white">[0] </kbd>{
|
<kbd style="color:white">[0] </kbd>{
|
||||||
|
@ -108,27 +108,27 @@ RSpec.describe "AwesomePrint" do
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
it "encodes HTML entities (plain)" do
|
it 'encodes HTML entities (plain)' do
|
||||||
markup = ' &<hello>'
|
markup = ' &<hello>'
|
||||||
expect(markup.ai(:html => true, :plain => true)).to eq('<pre>" &<hello>"</pre>')
|
expect(markup.ai(:html => true, :plain => true)).to eq('<pre>" &<hello>"</pre>')
|
||||||
end
|
end
|
||||||
|
|
||||||
it "encodes HTML entities (color)" do
|
it 'encodes HTML entities (color)' do
|
||||||
markup = ' &<hello>'
|
markup = ' &<hello>'
|
||||||
expect(markup.ai(:html => true)).to eq('<pre><kbd style="color:brown">" &<hello>"</kbd></pre>')
|
expect(markup.ai(:html => true)).to eq('<pre><kbd style="color:brown">" &<hello>"</kbd></pre>')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
describe "AwesomePrint.defaults" do
|
describe 'AwesomePrint.defaults' do
|
||||||
after do
|
after do
|
||||||
AwesomePrint.defaults = nil
|
AwesomePrint.defaults = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
# See https://github.com/awesome-print/awesome_print/issues/98
|
# See https://github.com/awesome-print/awesome_print/issues/98
|
||||||
it "should properly merge the defaults" do
|
it 'should properly merge the defaults' do
|
||||||
AwesomePrint.defaults = { :indent => -2, :sort_keys => true }
|
AwesomePrint.defaults = { :indent => -2, :sort_keys => true }
|
||||||
hash = { [0, 0, 255] => :yellow, :red => "rgb(255, 0, 0)", "magenta" => "rgb(255, 0, 255)" }
|
hash = { [0, 0, 255] => :yellow, :red => 'rgb(255, 0, 0)', 'magenta' => 'rgb(255, 0, 255)' }
|
||||||
out = hash.ai(:plain => true)
|
out = hash.ai(:plain => true)
|
||||||
expect(out).to eq <<-EOS.strip_heredoc.strip
|
expect(out).to eq <<-EOS.strip_heredoc.strip
|
||||||
{
|
{
|
||||||
|
@ -141,9 +141,9 @@ RSpec.describe "AwesomePrint" do
|
||||||
end
|
end
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
describe "Coexistence with the colorize gem" do
|
describe 'Coexistence with the colorize gem' do
|
||||||
before do # Redefine String#red just like colorize gem does it.
|
before do # Redefine String#red just like colorize gem does it.
|
||||||
@awesome_method = "".method(:red)
|
@awesome_method = ''.method(:red)
|
||||||
|
|
||||||
String.instance_eval do
|
String.instance_eval do
|
||||||
define_method :red do # Method arity is now 0 in Ruby 1.9+.
|
define_method :red do # Method arity is now 0 in Ruby 1.9+.
|
||||||
|
@ -159,34 +159,34 @@ RSpec.describe "AwesomePrint" do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "shoud not raise ArgumentError when formatting HTML" do
|
it 'shoud not raise ArgumentError when formatting HTML' do
|
||||||
out = "hello".ai(:color => { :string => :red }, :html => true)
|
out = 'hello'.ai(:color => { :string => :red }, :html => true)
|
||||||
if RUBY_VERSION >= "1.9"
|
if RUBY_VERSION >= '1.9'
|
||||||
expect(out).to eq(%Q|<pre>[red]<kbd style="color:red">"hello"</kbd>[/red]</pre>|)
|
expect(out).to eq(%Q|<pre>[red]<kbd style="color:red">"hello"</kbd>[/red]</pre>|)
|
||||||
else
|
else
|
||||||
expect(out).to eq(%Q|<pre>[red]"hello"[/red]</pre>|)
|
expect(out).to eq(%Q|<pre>[red]"hello"[/red]</pre>|)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "shoud not raise ArgumentError when formatting HTML (shade color)" do
|
it 'shoud not raise ArgumentError when formatting HTML (shade color)' do
|
||||||
out = "hello".ai(:color => { :string => :redish }, :html => true)
|
out = 'hello'.ai(:color => { :string => :redish }, :html => true)
|
||||||
expect(out).to eq(%Q|<pre><kbd style="color:darkred">"hello"</kbd></pre>|)
|
expect(out).to eq(%Q|<pre><kbd style="color:darkred">"hello"</kbd></pre>|)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "shoud not raise ArgumentError when formatting non-HTML" do
|
it 'shoud not raise ArgumentError when formatting non-HTML' do
|
||||||
out = "hello".ai(:color => { :string => :red }, :html => false)
|
out = 'hello'.ai(:color => { :string => :red }, :html => false)
|
||||||
expect(out).to eq(%Q|[red]"hello"[/red]|)
|
expect(out).to eq(%Q|[red]"hello"[/red]|)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "shoud not raise ArgumentError when formatting non-HTML (shade color)" do
|
it 'shoud not raise ArgumentError when formatting non-HTML (shade color)' do
|
||||||
out = "hello".ai(:color => { :string => :redish }, :html => false)
|
out = 'hello'.ai(:color => { :string => :redish }, :html => false)
|
||||||
expect(out).to eq(%Q|\e[0;31m"hello"\e[0m|)
|
expect(out).to eq(%Q|\e[0;31m"hello"\e[0m|)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
describe "Console" do
|
describe 'Console' do
|
||||||
it "should detect IRB" do
|
it 'should detect IRB' do
|
||||||
class IRB; end
|
class IRB; end
|
||||||
ENV.delete('RAILS_ENV')
|
ENV.delete('RAILS_ENV')
|
||||||
expect(AwesomePrint.console?).to eq(true)
|
expect(AwesomePrint.console?).to eq(true)
|
||||||
|
@ -194,7 +194,7 @@ RSpec.describe "AwesomePrint" do
|
||||||
Object.instance_eval{ remove_const :IRB }
|
Object.instance_eval{ remove_const :IRB }
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should detect Pry" do
|
it 'should detect Pry' do
|
||||||
class Pry; end
|
class Pry; end
|
||||||
ENV.delete('RAILS_ENV')
|
ENV.delete('RAILS_ENV')
|
||||||
expect(AwesomePrint.console?).to eq(true)
|
expect(AwesomePrint.console?).to eq(true)
|
||||||
|
@ -202,7 +202,7 @@ RSpec.describe "AwesomePrint" do
|
||||||
Object.instance_eval{ remove_const :Pry }
|
Object.instance_eval{ remove_const :Pry }
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should detect Rails::Console" do
|
it 'should detect Rails::Console' do
|
||||||
class IRB; end
|
class IRB; end
|
||||||
module Rails; class Console; end; end
|
module Rails; class Console; end; end
|
||||||
expect(AwesomePrint.console?).to eq(true)
|
expect(AwesomePrint.console?).to eq(true)
|
||||||
|
@ -213,25 +213,25 @@ RSpec.describe "AwesomePrint" do
|
||||||
|
|
||||||
it "should detect ENV['RAILS_ENV']" do
|
it "should detect ENV['RAILS_ENV']" do
|
||||||
class Pry; end
|
class Pry; end
|
||||||
ENV["RAILS_ENV"] = "development"
|
ENV['RAILS_ENV'] = 'development'
|
||||||
expect(AwesomePrint.console?).to eq(true)
|
expect(AwesomePrint.console?).to eq(true)
|
||||||
expect(AwesomePrint.rails_console?).to eq(true)
|
expect(AwesomePrint.rails_console?).to eq(true)
|
||||||
Object.instance_eval{ remove_const :Pry }
|
Object.instance_eval{ remove_const :Pry }
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should return the actual object when *not* running under console" do
|
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 })
|
expect(capture! { ap({ :a => 1 }) }).to eq({ :a => 1 })
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should return nil when running under console" do
|
it 'should return nil when running under console' do
|
||||||
class IRB; end
|
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)
|
expect(capture! { ap({ :a => 1 }) }).to eq(nil)
|
||||||
Object.instance_eval{ remove_const :IRB }
|
Object.instance_eval{ remove_const :IRB }
|
||||||
end
|
end
|
||||||
|
|
||||||
it "handles NoMethodError on IRB implicit #ai" do
|
it 'handles NoMethodError on IRB implicit #ai' do
|
||||||
module IRB; class Irb; end; end
|
module IRB; class Irb; end; end
|
||||||
irb_context = double('irb_context', last_value: BasicObject.new)
|
irb_context = double('irb_context', last_value: BasicObject.new)
|
||||||
IRB.define_singleton_method :version, -> { 'test_version' }
|
IRB.define_singleton_method :version, -> { 'test_version' }
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
RSpec.describe "Objects" do
|
RSpec.describe 'Objects' do
|
||||||
after do
|
after do
|
||||||
Object.instance_eval{ remove_const :Hello } if defined?(Hello)
|
Object.instance_eval{ remove_const :Hello } if defined?(Hello)
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "Formatting an object" do
|
describe 'Formatting an object' do
|
||||||
it "attributes" do
|
it 'attributes' do
|
||||||
class Hello
|
class Hello
|
||||||
attr_reader :abra
|
attr_reader :abra
|
||||||
attr_writer :ca
|
attr_writer :ca
|
||||||
|
@ -30,7 +30,7 @@ EOS
|
||||||
expect(hello.ai(:plain => true, :raw => false)).to eq(hello.inspect)
|
expect(hello.ai(:plain => true, :raw => false)).to eq(hello.inspect)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "instance variables" do
|
it 'instance variables' do
|
||||||
class Hello
|
class Hello
|
||||||
def initialize
|
def initialize
|
||||||
@abra, @ca, @dabra = 1, 2, 3
|
@abra, @ca, @dabra = 1, 2, 3
|
||||||
|
@ -50,7 +50,7 @@ EOS
|
||||||
expect(hello.ai(:plain => true, :raw => false)).to eq(hello.inspect)
|
expect(hello.ai(:plain => true, :raw => false)).to eq(hello.inspect)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "attributes and instance variables" do
|
it 'attributes and instance variables' do
|
||||||
class Hello
|
class Hello
|
||||||
attr_reader :abra
|
attr_reader :abra
|
||||||
attr_writer :ca
|
attr_writer :ca
|
||||||
|
@ -78,7 +78,7 @@ EOS
|
||||||
expect(hello.ai(:plain => true, :raw => false)).to eq(hello.inspect)
|
expect(hello.ai(:plain => true, :raw => false)).to eq(hello.inspect)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "without the plain options print the colorized values" do
|
it 'without the plain options print the colorized values' do
|
||||||
class Hello
|
class Hello
|
||||||
attr_reader :abra
|
attr_reader :abra
|
||||||
attr_writer :ca
|
attr_writer :ca
|
||||||
|
@ -102,7 +102,7 @@ EOS
|
||||||
expect(hello.ai(:plain => true, :raw => false)).to eq(hello.inspect)
|
expect(hello.ai(:plain => true, :raw => false)).to eq(hello.inspect)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "with multine as false show inline values" do
|
it 'with multine as false show inline values' do
|
||||||
class Hello
|
class Hello
|
||||||
attr_reader :abra
|
attr_reader :abra
|
||||||
attr_writer :ca
|
attr_writer :ca
|
||||||
|
|
Loading…
Reference in a new issue