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 "bundler/setup"
|
||||
require 'rubygems'
|
||||
require 'bundler/setup'
|
||||
|
||||
require "bundler"
|
||||
require 'bundler'
|
||||
Bundler::GemHelper.install_tasks
|
||||
|
||||
task :default do
|
||||
|
@ -16,9 +16,9 @@ task :appraise do
|
|||
exec 'appraisal install && appraisal rake'
|
||||
end
|
||||
|
||||
desc "Run all awesome_print gem specs"
|
||||
desc 'Run all awesome_print gem specs'
|
||||
task :spec do
|
||||
# Run plain rspec command without RSpec::Core::RakeTask overrides.
|
||||
exec "rspec -c spec"
|
||||
exec 'rspec -c spec'
|
||||
end
|
||||
|
||||
|
|
|
@ -8,25 +8,25 @@ $:.push File.expand_path('../lib', __FILE__)
|
|||
require 'awesome_print/version'
|
||||
|
||||
Gem::Specification.new do |s|
|
||||
s.name = "awesome_print"
|
||||
s.name = 'awesome_print'
|
||||
s.version = AwesomePrint.version
|
||||
s.authors = "Michael Dvorkin"
|
||||
s.date = Time.now.strftime("%Y-%m-%d")
|
||||
s.email = "mike@dvorkin.net"
|
||||
s.homepage = "https://github.com/awesome-print/awesome_print"
|
||||
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.license = "MIT"
|
||||
s.rubyforge_project = "awesome_print"
|
||||
s.authors = 'Michael Dvorkin'
|
||||
s.date = Time.now.strftime('%Y-%m-%d')
|
||||
s.email = 'mike@dvorkin.net'
|
||||
s.homepage = 'https://github.com/awesome-print/awesome_print'
|
||||
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.license = 'MIT'
|
||||
s.rubyforge_project = 'awesome_print'
|
||||
|
||||
s.files = Dir["[A-Z]*[^~]"] + Dir["lib/**/*.rb"] + Dir["spec/*"] + [".gitignore"]
|
||||
s.test_files = Dir["spec/*"]
|
||||
s.files = Dir['[A-Z]*[^~]'] + Dir['lib/**/*.rb'] + Dir['spec/*'] + ['.gitignore']
|
||||
s.test_files = Dir['spec/*']
|
||||
s.executables = []
|
||||
s.require_paths = ["lib"]
|
||||
s.require_paths = ['lib']
|
||||
|
||||
s.add_development_dependency "rspec", ">= 3.0.0"
|
||||
s.add_development_dependency "appraisal"
|
||||
s.add_development_dependency "fakefs", ">= 0.2.1"
|
||||
s.add_development_dependency 'rspec', '>= 3.0.0'
|
||||
s.add_development_dependency 'appraisal'
|
||||
s.add_development_dependency 'fakefs', '>= 0.2.1'
|
||||
s.add_development_dependency 'sqlite3'
|
||||
s.add_development_dependency 'nokogiri', '>= 1.6.5'
|
||||
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
|
||||
# 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 Colorize
|
||||
|
|
|
@ -59,7 +59,7 @@ module AwesomePrint
|
|||
# Format ActiveRecord 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?
|
||||
|
||||
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)
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ module AwesomePrint
|
|||
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|
|
||||
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
|
||||
end
|
||||
"class #{object} < #{object.superclass} " << awesome_hash(data)
|
||||
|
|
|
@ -25,7 +25,7 @@ module AwesomePrint
|
|||
#------------------------------------------------------------------------------
|
||||
def awesome_nokogiri_xml_node(object)
|
||||
if object.is_a?(::Nokogiri::XML::NodeSet) && object.empty?
|
||||
return "[]"
|
||||
return '[]'
|
||||
end
|
||||
xml = object.to_xml(:indent => 2)
|
||||
#
|
||||
|
|
|
@ -52,7 +52,7 @@ module AwesomePrint
|
|||
end
|
||||
|
||||
def awesome_bigdecimal(n)
|
||||
o = n.to_s("F")
|
||||
o = n.to_s('F')
|
||||
type = :bigdecimal
|
||||
awesome_simple(o, type, @inspector)
|
||||
end
|
||||
|
|
|
@ -13,7 +13,7 @@ module AwesomePrint
|
|||
end
|
||||
|
||||
def format
|
||||
return "[]" if array == []
|
||||
return '[]' if array == []
|
||||
|
||||
if array.instance_variable_defined?(:@__awesome_methods__)
|
||||
methods_array(array)
|
||||
|
@ -31,7 +31,7 @@ module AwesomePrint
|
|||
data = limited(data, width) if should_be_limited?
|
||||
"[\n" << data.join(",\n") << "\n#{outdent}]"
|
||||
else
|
||||
"[ " << array.map{ |item| inspector.awesome(item) }.join(", ") << " ]"
|
||||
'[ ' << array.map{ |item| inspector.awesome(item) }.join(', ') << ' ]'
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require_relative "../colorize"
|
||||
require_relative '../colorize'
|
||||
|
||||
module AwesomePrint
|
||||
module Formatters
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
require_relative 'base_formatter'
|
||||
require "shellwords"
|
||||
require 'shellwords'
|
||||
|
||||
module AwesomePrint
|
||||
module Formatters
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
require_relative 'base_formatter'
|
||||
require "shellwords"
|
||||
require 'shellwords'
|
||||
|
||||
module AwesomePrint
|
||||
module Formatters
|
||||
|
|
|
@ -13,7 +13,7 @@ module AwesomePrint
|
|||
end
|
||||
|
||||
def format
|
||||
return "{}" if hash == {}
|
||||
return '{}' if hash == {}
|
||||
|
||||
keys = hash.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)
|
||||
k[0] = ''
|
||||
align(k, width - 1) << colorize(": ", :hash) << inspector.awesome(v)
|
||||
align(k, width - 1) << colorize(': ', :hash) << inspector.awesome(v)
|
||||
end
|
||||
|
||||
def pre_ruby19_syntax(k, v, width)
|
||||
align(k, width) << colorize(" => ", :hash) << inspector.awesome(v)
|
||||
align(k, width) << colorize(' => ', :hash) << inspector.awesome(v)
|
||||
end
|
||||
|
||||
def plain_single_line
|
||||
|
|
|
@ -42,7 +42,7 @@ module AwesomePrint
|
|||
end
|
||||
|
||||
indented do
|
||||
key << colorize(" = ", :hash) + inspector.awesome(object.instance_variable_get(var))
|
||||
key << colorize(' = ', :hash) + inspector.awesome(object.instance_variable_get(var))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ module AwesomePrint
|
|||
end
|
||||
|
||||
indented do
|
||||
key << colorize(" = ", :hash) + inspector.awesome(struct.send(var))
|
||||
key << colorize(' = ', :hash) + inspector.awesome(struct.send(var))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -6,4 +6,4 @@
|
|||
#
|
||||
# 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
|
||||
|
||||
# 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
|
||||
ActiveRecord::Migration.verbose = false
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'spec_helper'
|
||||
|
||||
RSpec.describe "AwesomePrint" do
|
||||
RSpec.describe 'AwesomePrint' do
|
||||
def stub_tty!(output = true, stream = STDOUT)
|
||||
if output
|
||||
stream.instance_eval { def tty?; true; end }
|
||||
|
@ -9,22 +9,22 @@ RSpec.describe "AwesomePrint" do
|
|||
end
|
||||
end
|
||||
|
||||
describe "colorization" do
|
||||
describe 'colorization' do
|
||||
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 ] ] ]"
|
||||
|
||||
before do
|
||||
ENV['TERM'] = "xterm-colors"
|
||||
ENV['TERM'] = 'xterm-colors'
|
||||
ENV.delete('ANSICON')
|
||||
@arr = [ 1, :two, "three", [ nil, [ true, false] ] ]
|
||||
@arr = [ 1, :two, 'three', [ nil, [ true, false] ] ]
|
||||
end
|
||||
|
||||
describe "default settings (no forced colors)" do
|
||||
describe 'default settings (no forced colors)' do
|
||||
before do
|
||||
AwesomePrint.force_colors! false
|
||||
end
|
||||
|
||||
it "colorizes tty processes by default" do
|
||||
it 'colorizes tty processes by default' do
|
||||
stub_tty!
|
||||
expect(@arr.ai(:multiline => false)).to eq(COLORIZED)
|
||||
end
|
||||
|
@ -32,24 +32,24 @@ RSpec.describe "AwesomePrint" do
|
|||
it "colorizes processes with ENV['ANSICON'] by default" do
|
||||
begin
|
||||
stub_tty!
|
||||
term, ENV['ANSICON'] = ENV['ANSICON'], "1"
|
||||
term, ENV['ANSICON'] = ENV['ANSICON'], '1'
|
||||
expect(@arr.ai(:multiline => false)).to eq(COLORIZED)
|
||||
ensure
|
||||
ENV['ANSICON'] = term
|
||||
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
|
||||
stub_tty!
|
||||
term, ENV['TERM'] = ENV['TERM'], "dumb"
|
||||
term, ENV['TERM'] = ENV['TERM'], 'dumb'
|
||||
expect(@arr.ai(:multiline => false)).to eq(PLAIN)
|
||||
ensure
|
||||
ENV['TERM'] = term
|
||||
end
|
||||
end
|
||||
|
||||
it "does not colorize subprocesses by default" do
|
||||
it 'does not colorize subprocesses by default' do
|
||||
begin
|
||||
stub_tty! false
|
||||
expect(@arr.ai(:multiline => false)).to eq(PLAIN)
|
||||
|
@ -59,12 +59,12 @@ RSpec.describe "AwesomePrint" do
|
|||
end
|
||||
end
|
||||
|
||||
describe "forced colors override" do
|
||||
describe 'forced colors override' do
|
||||
before do
|
||||
AwesomePrint.force_colors!
|
||||
end
|
||||
|
||||
it "still colorizes tty processes" do
|
||||
it 'still colorizes tty processes' do
|
||||
stub_tty!
|
||||
expect(@arr.ai(:multiline => false)).to eq(COLORIZED)
|
||||
end
|
||||
|
@ -72,24 +72,24 @@ RSpec.describe "AwesomePrint" do
|
|||
it "colorizes processes with ENV['ANSICON'] set to 0" do
|
||||
begin
|
||||
stub_tty!
|
||||
term, ENV['ANSICON'] = ENV['ANSICON'], "1"
|
||||
term, ENV['ANSICON'] = ENV['ANSICON'], '1'
|
||||
expect(@arr.ai(:multiline => false)).to eq(COLORIZED)
|
||||
ensure
|
||||
ENV['ANSICON'] = term
|
||||
end
|
||||
end
|
||||
|
||||
it "colorizes dumb terminals" do
|
||||
it 'colorizes dumb terminals' do
|
||||
begin
|
||||
stub_tty!
|
||||
term, ENV['TERM'] = ENV['TERM'], "dumb"
|
||||
term, ENV['TERM'] = ENV['TERM'], 'dumb'
|
||||
expect(@arr.ai(:multiline => false)).to eq(COLORIZED)
|
||||
ensure
|
||||
ENV['TERM'] = term
|
||||
end
|
||||
end
|
||||
|
||||
it "colorizes subprocess" do
|
||||
it 'colorizes subprocess' do
|
||||
begin
|
||||
stub_tty! false
|
||||
expect(@arr.ai(:multiline => false)).to eq(COLORIZED)
|
||||
|
|
|
@ -4,35 +4,35 @@ require 'spec_helper'
|
|||
require 'logger'
|
||||
require 'awesome_print/core_ext/logger'
|
||||
|
||||
RSpec.describe "AwesomePrint logging extensions" do
|
||||
RSpec.describe 'AwesomePrint logging extensions' do
|
||||
before(:all) do
|
||||
@logger = Logger.new('/dev/null') rescue Logger.new('nul')
|
||||
end
|
||||
|
||||
describe "ap method" do
|
||||
it "should awesome_inspect the given object" do
|
||||
describe 'ap method' do
|
||||
it 'should awesome_inspect the given object' do
|
||||
object = double
|
||||
expect(object).to receive(:ai)
|
||||
@logger.ap object
|
||||
end
|
||||
|
||||
describe "the log level" do
|
||||
describe 'the log level' do
|
||||
before do
|
||||
AwesomePrint.defaults = {}
|
||||
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)
|
||||
@logger.ap(nil)
|
||||
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 }
|
||||
expect(@logger).to receive(:info)
|
||||
@logger.ap(nil)
|
||||
end
|
||||
|
||||
it "should use the passed in level" do
|
||||
it 'should use the passed in level' do
|
||||
expect(@logger).to receive(:warn)
|
||||
@logger.ap(nil, :warn)
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
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|
|
||||
it "should have #{color} color" do
|
||||
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
|
||||
|
||||
it "should have black and pale colors" do
|
||||
expect("black".send(:black)).to eq("black".send(:grayish))
|
||||
expect("pale".send(:pale)).to eq("pale".send(:whiteish))
|
||||
expect("pale".send(:pale)).to eq("\e[0;37mpale\e[0m")
|
||||
expect("whiteish".send(:whiteish)).to eq("\e[0;37mwhiteish\e[0m")
|
||||
it 'should have black and pale colors' do
|
||||
expect('black'.send(:black)).to eq('black'.send(:grayish))
|
||||
expect('pale'.send(:pale)).to eq('pale'.send(:whiteish))
|
||||
expect('pale'.send(:pale)).to eq("\e[0;37mpale\e[0m")
|
||||
expect('whiteish'.send(:whiteish)).to eq("\e[0;37mwhiteish\e[0m")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'spec_helper'
|
||||
|
||||
RSpec.describe "AwesomePrint ActionView extensions", skip: ->{ !ExtVerifier.has_rails? }.call do
|
||||
RSpec.describe 'AwesomePrint ActionView extensions', skip: ->{ !ExtVerifier.has_rails? }.call do
|
||||
|
||||
before do
|
||||
@view = ActionView::Base.new
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
require 'spec_helper'
|
||||
require 'active_record_helper'
|
||||
|
||||
RSpec.describe "AwesomePrint/ActiveRecord", skip: ->{ !ExtVerifier.has_rails? }.call do
|
||||
describe "ActiveRecord instance, attributes only (default)" do
|
||||
RSpec.describe 'AwesomePrint/ActiveRecord', skip: ->{ !ExtVerifier.has_rails? }.call do
|
||||
describe 'ActiveRecord instance, attributes only (default)' do
|
||||
before do
|
||||
ActiveRecord::Base.default_timezone = :utc
|
||||
@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")
|
||||
@diana = User.new(:name => 'Diana', :rank => 1, :admin => false, :created_at => '1992-10-10 12:30:00')
|
||||
@laura = User.new(:name => 'Laura', :rank => 2, :admin => true, :created_at => '2003-05-26 14:15:00')
|
||||
@ap = AwesomePrint::Inspector.new(:plain => true, :sort_keys => true)
|
||||
end
|
||||
|
||||
it "display single record" do
|
||||
it 'display single record' do
|
||||
out = @ap.awesome(@diana)
|
||||
str = <<-EOS.strip
|
||||
#<User:placeholder_id> {
|
||||
|
@ -29,7 +29,7 @@ RSpec.describe "AwesomePrint/ActiveRecord", skip: ->{ !ExtVerifier.has_rails? }.
|
|||
expect(out).to be_similar_to(str)
|
||||
end
|
||||
|
||||
it "display multiple records" do
|
||||
it 'display multiple records' do
|
||||
out = @ap.awesome([ @diana, @laura ])
|
||||
str = <<-EOS.strip
|
||||
[
|
||||
|
@ -59,7 +59,7 @@ RSpec.describe "AwesomePrint/ActiveRecord", skip: ->{ !ExtVerifier.has_rails? }.
|
|||
expect(out).to be_similar_to(str)
|
||||
end
|
||||
|
||||
it "display multiple records on a relation" do
|
||||
it 'display multiple records on a relation' do
|
||||
@diana.save
|
||||
@laura.save
|
||||
out = @ap.awesome(User.all)
|
||||
|
@ -114,15 +114,15 @@ EOS
|
|||
end
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
describe "ActiveRecord instance (raw)" do
|
||||
describe 'ActiveRecord instance (raw)' do
|
||||
before do
|
||||
ActiveRecord::Base.default_timezone = :utc
|
||||
@diana = User.new(:name => "Diana", :rank => 1, :admin => false, :created_at => "1992-10-10 12:30:00")
|
||||
@laura = User.new(:name => "Laura", :rank => 2, :admin => true, :created_at => "2003-05-26 14:15:00")
|
||||
@diana = User.new(:name => 'Diana', :rank => 1, :admin => false, :created_at => '1992-10-10 12:30:00')
|
||||
@laura = User.new(:name => 'Laura', :rank => 2, :admin => true, :created_at => '2003-05-26 14:15:00')
|
||||
@ap = AwesomePrint::Inspector.new(:plain => true, :sort_keys => true, :raw => true)
|
||||
end
|
||||
|
||||
it "display single record" do
|
||||
it 'display single record' do
|
||||
out = @ap.awesome(@diana)
|
||||
|
||||
raw_object_string =
|
||||
|
@ -149,7 +149,7 @@ EOS
|
|||
expect(out).to be_similar_to(raw_object_string)
|
||||
end
|
||||
|
||||
it "display multiple records" do
|
||||
it 'display multiple records' do
|
||||
out = @ap.awesome([ @diana, @laura ])
|
||||
|
||||
raw_object_string =
|
||||
|
@ -179,12 +179,12 @@ EOS
|
|||
end
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
describe "ActiveRecord class" do
|
||||
describe 'ActiveRecord class' do
|
||||
before do
|
||||
@ap = AwesomePrint::Inspector.new(:plain => true)
|
||||
end
|
||||
|
||||
it "should print the class" do
|
||||
it 'should print the class' do
|
||||
expect(@ap.awesome(User)).to eq <<-EOS.strip
|
||||
class User < ActiveRecord::Base {
|
||||
:id => :integer,
|
||||
|
@ -196,7 +196,7 @@ class User < ActiveRecord::Base {
|
|||
EOS
|
||||
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)
|
||||
expect(out).to eq <<-EOS.strip
|
||||
class SubUser < User {
|
||||
|
@ -209,23 +209,23 @@ class SubUser < User {
|
|||
EOS
|
||||
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
|
||||
end
|
||||
end
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
describe "ActiveRecord methods formatting" do
|
||||
describe 'ActiveRecord methods formatting' do
|
||||
before do
|
||||
@ap = AwesomePrint::Inspector.new(:plain => true)
|
||||
end
|
||||
|
||||
it "should format class methods properly" do
|
||||
it 'should format class methods properly' do
|
||||
# spec 1
|
||||
out = @ap.awesome(User.methods.grep(/first/))
|
||||
|
||||
if ActiveRecord::VERSION::STRING >= "3.2"
|
||||
if RUBY_VERSION >= "1.9"
|
||||
if ActiveRecord::VERSION::STRING >= '3.2'
|
||||
if RUBY_VERSION >= '1.9'
|
||||
expect(out).to match(/\sfirst\(\*args,\s&block\)\s+Class \(ActiveRecord::Querying\)/)
|
||||
else
|
||||
expect(out).to match(/\sfirst\(\*arg1\)\s+Class \(ActiveRecord::Querying\)/)
|
||||
|
|
|
@ -1,26 +1,26 @@
|
|||
require 'spec_helper'
|
||||
|
||||
RSpec.describe "AwesomePrint::ActiveSupport", skip: ->{ !ExtVerifier.has_rails? }.call do
|
||||
RSpec.describe 'AwesomePrint::ActiveSupport', skip: ->{ !ExtVerifier.has_rails? }.call do
|
||||
before do
|
||||
@ap = AwesomePrint::Inspector.new
|
||||
end
|
||||
|
||||
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 = Time.utc(2007, 2, 10, 20, 30, 45).in_time_zone
|
||||
expect(@ap.send(:awesome, time)).to eq("\e[0;32mSat, 10 Feb 2007 15:30:45 EST -05:00\e[0m")
|
||||
end
|
||||
|
||||
it "should format HashWithIndifferentAccess as regular Hash" do
|
||||
hash = HashWithIndifferentAccess.new({ :hello => "world" })
|
||||
it 'should format HashWithIndifferentAccess as regular Hash' do
|
||||
hash = HashWithIndifferentAccess.new({ :hello => 'world' })
|
||||
expect(@ap.send(:awesome, hash)).to eq("{\n \"hello\"\e[0;37m => \e[0m\e[0;33m\"world\"\e[0m\n}")
|
||||
end
|
||||
|
||||
# ActiveSupport sticks in instance variables to the date object. Make sure
|
||||
# we ignore that and format Date instance as regular date.
|
||||
it "should formate Date object as date" do
|
||||
it 'should formate Date object as date' do
|
||||
date = Date.new(2003, 5, 26)
|
||||
expect(date.ai(:plain => true)).to eq("Mon, 26 May 2003")
|
||||
expect(date.ai(:plain => true)).to eq('Mon, 26 May 2003')
|
||||
expect(date.ai).to eq("\e[0;32mMon, 26 May 2003\e[0m")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'spec_helper'
|
||||
|
||||
RSpec.describe "AwesomePrint/MongoMapper", skip: ->{ !ExtVerifier.has_mongo_mapper? }.call do
|
||||
RSpec.describe 'AwesomePrint/MongoMapper', skip: ->{ !ExtVerifier.has_mongo_mapper? }.call do
|
||||
if ExtVerifier.has_mongo_mapper?
|
||||
before :all do
|
||||
class MongoUser
|
||||
|
@ -21,18 +21,18 @@ RSpec.describe "AwesomePrint/MongoMapper", skip: ->{ !ExtVerifier.has_mongo_mapp
|
|||
@ap = AwesomePrint::Inspector.new(:plain => true, :sort_keys => true)
|
||||
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 = AwesomePrint::Inspector.new(:plain => true, :sort_keys => true, :raw => true) }
|
||||
|
||||
it "should print class instance" do
|
||||
user = MongoUser.new(:first_name => "Al", :last_name => "Capone")
|
||||
it 'should print class instance' do
|
||||
user = MongoUser.new(:first_name => 'Al', :last_name => 'Capone')
|
||||
|
||||
out = @ap.send(:awesome, user)
|
||||
out.gsub!(/#\<Proc:.+?\>/, 'AWESOME_PRINT_PROC_STUB')
|
||||
out.gsub!(/BSON::ObjectId\('[\da-f]+?'\)/, "BSON::ObjectId('123456789')")
|
||||
|
||||
if MongoMapper::Version >= "0.13"
|
||||
if MongoMapper::Version >= '0.13'
|
||||
str = <<-EOS.strip
|
||||
#<MongoUser:placeholder_id
|
||||
@__mm_default_keys = [
|
||||
|
@ -127,7 +127,7 @@ RSpec.describe "AwesomePrint/MongoMapper", skip: ->{ !ExtVerifier.has_mongo_mapp
|
|||
expect(out).to be_similar_to(str)
|
||||
end
|
||||
|
||||
it "should print the class" do
|
||||
it 'should print the class' do
|
||||
expect(@ap.send(:awesome, MongoUser)).to eq <<-EOS.strip
|
||||
class MongoUser < Object {
|
||||
"_id" => :object_id,
|
||||
|
@ -137,7 +137,7 @@ class MongoUser < Object {
|
|||
EOS
|
||||
end
|
||||
|
||||
it "should print the class when type is undefined" do
|
||||
it 'should print the class when type is undefined' do
|
||||
class Chamelion
|
||||
include MongoMapper::Document
|
||||
key :last_attribute
|
||||
|
@ -152,7 +152,7 @@ class Chamelion < Object {
|
|||
end
|
||||
end
|
||||
|
||||
describe "with associations" do
|
||||
describe 'with associations' do
|
||||
|
||||
if ExtVerifier.has_mongo_mapper?
|
||||
before :all do
|
||||
|
@ -176,8 +176,8 @@ class Chamelion < Object {
|
|||
end
|
||||
end
|
||||
|
||||
describe "with show associations turned off (default)" do
|
||||
it "should render the class as normal" do
|
||||
describe 'with show associations turned off (default)' do
|
||||
it 'should render the class as normal' do
|
||||
expect(@ap.send(:awesome, Parent)).to eq <<-EOS.strip
|
||||
class Parent < Object {
|
||||
"_id" => :object_id,
|
||||
|
@ -186,7 +186,7 @@ class Parent < Object {
|
|||
EOS
|
||||
end
|
||||
|
||||
it "should render an instance as normal" do
|
||||
it 'should render an instance as normal' do
|
||||
parent = Parent.new(:name => 'test')
|
||||
out = @ap.send(:awesome, parent)
|
||||
str = <<-EOS.strip
|
||||
|
@ -199,12 +199,12 @@ class Parent < Object {
|
|||
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
|
||||
@ap = AwesomePrint::Inspector.new(:plain => true, :mongo_mapper => { :show_associations => true })
|
||||
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
|
||||
class Parent < Object {
|
||||
"_id" => :object_id,
|
||||
|
@ -215,7 +215,7 @@ class Parent < Object {
|
|||
EOS
|
||||
end
|
||||
|
||||
it "should render an instance with associations shown" do
|
||||
it 'should render an instance with associations shown' do
|
||||
parent = Parent.new(:name => 'test')
|
||||
out = @ap.send(:awesome, parent)
|
||||
str = <<-EOS.strip
|
||||
|
@ -230,7 +230,7 @@ class Parent < Object {
|
|||
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
|
||||
@ap = AwesomePrint::Inspector.new(:plain => true,
|
||||
:mongo_mapper => {
|
||||
|
@ -240,7 +240,7 @@ class Parent < Object {
|
|||
)
|
||||
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))
|
||||
out = @ap.send(:awesome, parent)
|
||||
str = <<-EOS.strip
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'spec_helper'
|
||||
|
||||
RSpec.describe "AwesomePrint/Mongoid", skip: ->{ !ExtVerifier.has_mongoid? }.call do
|
||||
RSpec.describe 'AwesomePrint/Mongoid', skip: ->{ !ExtVerifier.has_mongoid? }.call do
|
||||
|
||||
if ExtVerifier.has_mongoid?
|
||||
before :all do
|
||||
|
@ -22,8 +22,8 @@ RSpec.describe "AwesomePrint/Mongoid", skip: ->{ !ExtVerifier.has_mongoid? }.cal
|
|||
@ap = AwesomePrint::Inspector.new :plain => true, :sort_keys => true
|
||||
end
|
||||
|
||||
it "should print class instance" do
|
||||
user = MongoUser.new :first_name => "Al", :last_name => "Capone"
|
||||
it 'should print class instance' do
|
||||
user = MongoUser.new :first_name => 'Al', :last_name => 'Capone'
|
||||
out = @ap.send :awesome, user
|
||||
|
||||
object_id = user.id.inspect
|
||||
|
@ -37,7 +37,7 @@ RSpec.describe "AwesomePrint/Mongoid", skip: ->{ !ExtVerifier.has_mongoid? }.cal
|
|||
expect(out).to be_similar_to(str, {:skip_bson => true})
|
||||
end
|
||||
|
||||
it "should print the class" do
|
||||
it 'should print the class' do
|
||||
class_spec = if mongoid_3_0?
|
||||
<<-EOS.strip
|
||||
class MongoUser < Object {
|
||||
|
@ -68,7 +68,7 @@ class MongoUser < Object {
|
|||
expect(@ap.send(:awesome, MongoUser)).to eq class_spec
|
||||
end
|
||||
|
||||
it "should print the class when type is undefined" do
|
||||
it 'should print the class when type is undefined' do
|
||||
class Chamelion
|
||||
include Mongoid::Document
|
||||
field :last_attribute
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
require 'spec_helper'
|
||||
|
||||
RSpec.describe "AwesomePrint/NoBrainer", skip: ->{ !ExtVerifier.has_nobrainer? }.call do
|
||||
RSpec.describe 'AwesomePrint/NoBrainer', skip: ->{ !ExtVerifier.has_nobrainer? }.call do
|
||||
|
||||
if ExtVerifier.has_nobrainer?
|
||||
before :all do
|
||||
NoBrainer.configure do |config|
|
||||
config.app_name = "ap_test"
|
||||
config.app_name = 'ap_test'
|
||||
config.environment = :test
|
||||
end
|
||||
end
|
||||
|
@ -29,8 +29,8 @@ RSpec.describe "AwesomePrint/NoBrainer", skip: ->{ !ExtVerifier.has_nobrainer? }
|
|||
@ap = AwesomePrint::Inspector.new :plain => true
|
||||
end
|
||||
|
||||
it "should print class instance" do
|
||||
user = SomeModel.new :first_name => "Al", :last_name => "Capone"
|
||||
it 'should print class instance' do
|
||||
user = SomeModel.new :first_name => 'Al', :last_name => 'Capone'
|
||||
out = @ap.send :awesome, user
|
||||
|
||||
object_id = user.id.inspect
|
||||
|
@ -44,7 +44,7 @@ RSpec.describe "AwesomePrint/NoBrainer", skip: ->{ !ExtVerifier.has_nobrainer? }
|
|||
expect(out).to eq(str)
|
||||
end
|
||||
|
||||
it "should print the class" do
|
||||
it 'should print the class' do
|
||||
class_spec = <<-EOS.strip
|
||||
class SomeModel < Object {
|
||||
:id => :string,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require 'spec_helper'
|
||||
|
||||
RSpec.describe "AwesomePrint/Nokogiri" do
|
||||
it "should colorize tags" do
|
||||
RSpec.describe 'AwesomePrint/Nokogiri' do
|
||||
it 'should colorize tags' do
|
||||
xml = Nokogiri::XML('<html><body><h1></h1></body></html>')
|
||||
expect(xml.ai).to eq <<-EOS
|
||||
<?xml version=\"1.0\"?>\e[1;32m
|
||||
|
@ -13,7 +13,7 @@ RSpec.describe "AwesomePrint/Nokogiri" do
|
|||
EOS
|
||||
end
|
||||
|
||||
it "should colorize contents" do
|
||||
it 'should colorize contents' do
|
||||
xml = Nokogiri::XML('<html><body><h1>Hello</h1></body></html>')
|
||||
expect(xml.ai).to eq <<-EOS
|
||||
<?xml version=\"1.0\"?>\e[1;32m
|
||||
|
@ -25,7 +25,7 @@ RSpec.describe "AwesomePrint/Nokogiri" do
|
|||
EOS
|
||||
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>')
|
||||
expect(xml.ai).to eq <<-EOS
|
||||
<?xml version=\"1.0\"?>\e[1;32m
|
||||
|
@ -39,7 +39,7 @@ RSpec.describe "AwesomePrint/Nokogiri" do
|
|||
EOS
|
||||
end
|
||||
|
||||
it "handle empty NodeSet" do
|
||||
it 'handle empty NodeSet' do
|
||||
xml = Nokogiri::XML::NodeSet.new(Nokogiri::XML(''))
|
||||
expect(xml.ai).to eq('[]')
|
||||
end
|
||||
|
|
|
@ -5,13 +5,13 @@ RSpec.describe 'AwesomePrint Ostruct extension' do
|
|||
@ap = AwesomePrint::Inspector.new(:plain => true, :sort_keys => true)
|
||||
end
|
||||
|
||||
it "empty hash" do
|
||||
it 'empty hash' do
|
||||
struct = OpenStruct.new
|
||||
expect(@ap.send(:awesome, struct)).to eq("OpenStruct {}")
|
||||
expect(@ap.send(:awesome, struct)).to eq('OpenStruct {}')
|
||||
end
|
||||
|
||||
it "plain multiline" do
|
||||
struct = OpenStruct.new :name => "Foo", :address => "Bar"
|
||||
it 'plain multiline' do
|
||||
struct = OpenStruct.new :name => 'Foo', :address => 'Bar'
|
||||
expect(@ap.send(:awesome, struct)).to eq <<-EOS.strip
|
||||
OpenStruct {
|
||||
:address => "Bar",
|
||||
|
|
|
@ -23,8 +23,8 @@ RSpec.describe 'AwesomePrint/Ripple', skip: ->{ !ExtVerifier.has_ripple? }.call
|
|||
@ap = AwesomePrint::Inspector.new :plain => true, :sort_keys => true
|
||||
end
|
||||
|
||||
it "should print class instance" do
|
||||
user = RippleUser.new :_id => "12345", :first_name => "Al", :last_name => "Capone"
|
||||
it 'should print class instance' do
|
||||
user = RippleUser.new :_id => '12345', :first_name => 'Al', :last_name => 'Capone'
|
||||
out = @ap.send :awesome, user
|
||||
|
||||
expect(out).to be_similar_to <<-EOS.strip
|
||||
|
@ -36,7 +36,7 @@ RSpec.describe 'AwesomePrint/Ripple', skip: ->{ !ExtVerifier.has_ripple? }.call
|
|||
EOS
|
||||
end
|
||||
|
||||
it "should print the class" do
|
||||
it 'should print the class' do
|
||||
expect(@ap.send(:awesome, RippleUser)).to eq <<-EOS.strip
|
||||
class RippleUser < Object {
|
||||
:_id => :string,
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
require 'spec_helper'
|
||||
require "bigdecimal"
|
||||
require "rational"
|
||||
require "set"
|
||||
require 'bigdecimal'
|
||||
require 'rational'
|
||||
require 'set'
|
||||
|
||||
RSpec.describe "AwesomePrint" do
|
||||
describe "Array" do
|
||||
RSpec.describe 'AwesomePrint' do
|
||||
describe 'Array' do
|
||||
before do
|
||||
@arr = [ 1, :two, "three", [ nil, [ true, false] ] ]
|
||||
@arr = [ 1, :two, 'three', [ nil, [ true, false] ] ]
|
||||
end
|
||||
|
||||
it "empty array" do
|
||||
expect([].ai).to eq("[]")
|
||||
it 'empty array' do
|
||||
expect([].ai).to eq('[]')
|
||||
end
|
||||
|
||||
it "plain multiline" do
|
||||
it 'plain multiline' do
|
||||
expect(@arr.ai(:plain => true)).to eq <<-EOS.strip
|
||||
[
|
||||
[0] 1,
|
||||
|
@ -30,7 +30,7 @@ RSpec.describe "AwesomePrint" do
|
|||
EOS
|
||||
end
|
||||
|
||||
it "plain multiline without index" do
|
||||
it 'plain multiline without index' do
|
||||
expect(@arr.ai(:plain => true, :index => false)).to eq <<-EOS.strip
|
||||
[
|
||||
1,
|
||||
|
@ -47,7 +47,7 @@ EOS
|
|||
EOS
|
||||
end
|
||||
|
||||
it "plain multiline indented" do
|
||||
it 'plain multiline indented' do
|
||||
expect(@arr.ai(:plain => true, :indent => 2)).to eq <<-EOS.strip
|
||||
[
|
||||
[0] 1,
|
||||
|
@ -64,7 +64,7 @@ EOS
|
|||
EOS
|
||||
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
|
||||
[
|
||||
1,
|
||||
|
@ -81,11 +81,11 @@ EOS
|
|||
EOS
|
||||
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 ] ] ]')
|
||||
end
|
||||
|
||||
it "colored multiline (default)" do
|
||||
it 'colored multiline (default)' do
|
||||
expect(@arr.ai).to eq <<-EOS.strip
|
||||
[
|
||||
\e[1;37m[0] \e[0m\e[1;34m1\e[0m,
|
||||
|
@ -102,7 +102,7 @@ EOS
|
|||
EOS
|
||||
end
|
||||
|
||||
it "colored multiline indented" do
|
||||
it 'colored multiline indented' do
|
||||
expect(@arr.ai(:indent => 8)).to eq <<-EOS.strip
|
||||
[
|
||||
\e[1;37m[0] \e[0m\e[1;34m1\e[0m,
|
||||
|
@ -119,19 +119,19 @@ EOS
|
|||
EOS
|
||||
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 ] ] ]")
|
||||
end
|
||||
end
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
describe "Nested Array" do
|
||||
describe 'Nested Array' do
|
||||
before do
|
||||
@arr = [ 1, 2 ]
|
||||
@arr << @arr
|
||||
end
|
||||
|
||||
it "plain multiline" do
|
||||
it 'plain multiline' do
|
||||
expect(@arr.ai(:plain => true)).to eq <<-EOS.strip
|
||||
[
|
||||
[0] 1,
|
||||
|
@ -141,7 +141,7 @@ EOS
|
|||
EOS
|
||||
end
|
||||
|
||||
it "plain multiline without index" do
|
||||
it 'plain multiline without index' do
|
||||
expect(@arr.ai(:plain => true, :index => false)).to eq <<-EOS.strip
|
||||
[
|
||||
1,
|
||||
|
@ -151,18 +151,18 @@ EOS
|
|||
EOS
|
||||
end
|
||||
|
||||
it "plain single line" do
|
||||
expect(@arr.ai(:plain => true, :multiline => false)).to eq("[ 1, 2, [...] ]")
|
||||
it 'plain single line' do
|
||||
expect(@arr.ai(:plain => true, :multiline => false)).to eq('[ 1, 2, [...] ]')
|
||||
end
|
||||
end
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
describe "Limited Output Array" do
|
||||
describe 'Limited Output Array' do
|
||||
before(:each) do
|
||||
@arr = (1..1000).to_a
|
||||
end
|
||||
|
||||
it "plain limited output large" do
|
||||
it 'plain limited output large' do
|
||||
expect(@arr.ai(:plain => true, :limit => true)).to eq <<-EOS.strip
|
||||
[
|
||||
[ 0] 1,
|
||||
|
@ -176,7 +176,7 @@ EOS
|
|||
EOS
|
||||
end
|
||||
|
||||
it "plain limited output small" do
|
||||
it 'plain limited output small' do
|
||||
@arr = @arr[0..3]
|
||||
expect(@arr.ai(:plain => true, :limit => true)).to eq <<-EOS.strip
|
||||
[
|
||||
|
@ -188,7 +188,7 @@ EOS
|
|||
EOS
|
||||
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
|
||||
[
|
||||
[ 0] 1,
|
||||
|
@ -205,7 +205,7 @@ EOS
|
|||
EOS
|
||||
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
|
||||
[
|
||||
[ 0] 1,
|
||||
|
@ -225,12 +225,12 @@ EOS
|
|||
end
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
describe "Limited Output Hash" do
|
||||
describe 'Limited Output Hash' 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
|
||||
|
||||
it "plain limited output" do
|
||||
it 'plain limited output' do
|
||||
expect(@hash.ai(:sort_keys => true, :plain => true, :limit => true)).to eq <<-EOS.strip
|
||||
{
|
||||
"a" => :a,
|
||||
|
@ -246,16 +246,16 @@ EOS
|
|||
end
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
describe "Hash" do
|
||||
describe 'Hash' do
|
||||
before do
|
||||
@hash = { 1 => { :sym => { "str" => { [1, 2, 3] => { { :k => :v } => Hash } } } } }
|
||||
@hash = { 1 => { :sym => { 'str' => { [1, 2, 3] => { { :k => :v } => Hash } } } } }
|
||||
end
|
||||
|
||||
it "empty hash" do
|
||||
expect({}.ai).to eq("{}")
|
||||
it 'empty hash' do
|
||||
expect({}.ai).to eq('{}')
|
||||
end
|
||||
|
||||
it "plain multiline" do
|
||||
it 'plain multiline' do
|
||||
expect(@hash.ai(:plain => true)).to eq <<-EOS.strip
|
||||
{
|
||||
1 => {
|
||||
|
@ -271,7 +271,7 @@ EOS
|
|||
EOS
|
||||
end
|
||||
|
||||
it "new hash syntax" do
|
||||
it 'new hash syntax' do
|
||||
expect(@hash.ai(:plain => true, :ruby19_syntax => true)).to eq <<-EOS.strip
|
||||
{
|
||||
1 => {
|
||||
|
@ -287,7 +287,7 @@ EOS
|
|||
EOS
|
||||
end
|
||||
|
||||
it "plain multiline indented" do
|
||||
it 'plain multiline indented' do
|
||||
expect(@hash.ai(:plain => true, :indent => 1)).to eq <<-EOS.strip
|
||||
{
|
||||
1 => {
|
||||
|
@ -303,11 +303,11 @@ EOS
|
|||
EOS
|
||||
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 } } } } }')
|
||||
end
|
||||
|
||||
it "colored multiline (default)" do
|
||||
it 'colored multiline (default)' do
|
||||
expect(@hash.ai).to eq <<-EOS.strip
|
||||
{
|
||||
1\e[0;37m => \e[0m{
|
||||
|
@ -323,7 +323,7 @@ EOS
|
|||
EOS
|
||||
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
|
||||
{
|
||||
1\e[0;37m => \e[0m{
|
||||
|
@ -339,7 +339,7 @@ EOS
|
|||
EOS
|
||||
end
|
||||
|
||||
it "colored multiline indented" do
|
||||
it 'colored multiline indented' do
|
||||
expect(@hash.ai(:indent => 2)).to eq <<-EOS.strip
|
||||
{
|
||||
1\e[0;37m => \e[0m{
|
||||
|
@ -355,20 +355,20 @@ EOS
|
|||
EOS
|
||||
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 } } } } }")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
describe "Nested Hash" do
|
||||
describe 'Nested Hash' do
|
||||
before do
|
||||
@hash = {}
|
||||
@hash[:a] = @hash
|
||||
end
|
||||
|
||||
it "plain multiline" do
|
||||
it 'plain multiline' do
|
||||
expect(@hash.ai(:plain => true)).to eq <<-EOS.strip
|
||||
{
|
||||
:a => {...}
|
||||
|
@ -376,18 +376,18 @@ EOS
|
|||
EOS
|
||||
end
|
||||
|
||||
it "plain single line" do
|
||||
it 'plain single line' do
|
||||
expect(@hash.ai(:plain => true, :multiline => false)).to eq('{ :a => {...} }')
|
||||
end
|
||||
end
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
describe "Hash with several keys" do
|
||||
describe 'Hash with several keys' do
|
||||
before do
|
||||
@hash = {"b" => "b", :a => "a", :z => "z", "alpha" => "alpha"}
|
||||
@hash = {'b' => 'b', :a => 'a', :z => 'z', 'alpha' => 'alpha'}
|
||||
end
|
||||
|
||||
it "plain multiline" do
|
||||
it 'plain multiline' do
|
||||
out = @hash.ai(:plain => true)
|
||||
if RUBY_VERSION.to_f < 1.9 # Order of @hash keys is not guaranteed.
|
||||
expect(out).to match(/^\{[^\}]+\}/m)
|
||||
|
@ -407,7 +407,7 @@ EOS
|
|||
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
|
||||
{
|
||||
:a => "a",
|
||||
|
@ -421,13 +421,13 @@ EOS
|
|||
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
|
||||
# reliably compare the output string.
|
||||
#
|
||||
it "hash keys must be left aligned" do
|
||||
hash = { [0, 0, 255] => :yellow, :red => "rgb(255, 0, 0)", "magenta" => "rgb(255, 0, 255)" }
|
||||
it 'hash keys must be left aligned' do
|
||||
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)
|
||||
expect(out).to eq <<-EOS.strip
|
||||
{
|
||||
|
@ -438,7 +438,7 @@ EOS
|
|||
EOS
|
||||
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} ]
|
||||
out = arr.ai(:plain => true, :indent => -4, :sort_keys => true)
|
||||
expect(out).to eq <<-EOS.strip
|
||||
|
@ -457,7 +457,7 @@ EOS
|
|||
EOS
|
||||
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} }
|
||||
out = arr.ai(:plain => true, :indent => -4, :sort_keys => true)
|
||||
expect(out).to eq <<-EOS.strip
|
||||
|
@ -478,28 +478,28 @@ EOS
|
|||
end
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
describe "Class" do
|
||||
it "should show superclass (plain)" do
|
||||
describe 'Class' do
|
||||
it 'should show superclass (plain)' do
|
||||
expect(self.class.ai(:plain => true)).to eq("#{self.class} < #{self.class.superclass}")
|
||||
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)
|
||||
end
|
||||
end
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
describe "File" do
|
||||
it "should display a file (plain)" do
|
||||
File.open(__FILE__, "r") do |f|
|
||||
describe 'File' do
|
||||
it 'should display a file (plain)' do
|
||||
File.open(__FILE__, 'r') do |f|
|
||||
expect(f.ai(:plain => true)).to eq("#{f.inspect}\n" << `ls -alF #{f.path}`.chop)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
describe "Dir" do
|
||||
it "should display a direcory (plain)" do
|
||||
describe 'Dir' do
|
||||
it 'should display a direcory (plain)' do
|
||||
Dir.open(File.dirname(__FILE__)) do |d|
|
||||
expect(d.ai(:plain => true)).to eq("#{d.inspect}\n" << `ls -alF #{d.path}`.chop)
|
||||
end
|
||||
|
@ -507,13 +507,13 @@ EOS
|
|||
end
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
describe "BigDecimal and Rational" do
|
||||
it "should present BigDecimal object with arbitrary precision" do
|
||||
big = BigDecimal("201020102010201020102010201020102010.4")
|
||||
expect(big.ai(:plain => true)).to eq("201020102010201020102010201020102010.4")
|
||||
describe 'BigDecimal and Rational' do
|
||||
it 'should present BigDecimal object with arbitrary precision' do
|
||||
big = BigDecimal('201020102010201020102010201020102010.4')
|
||||
expect(big.ai(:plain => true)).to eq('201020102010201020102010201020102010.4')
|
||||
end
|
||||
|
||||
it "should present Rational object with arbitrary precision" do
|
||||
it 'should present Rational object with arbitrary precision' do
|
||||
rat = Rational(201020102010201020102010201020102010, 2)
|
||||
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://www.ruby-forum.com/topic/189397
|
||||
#
|
||||
if RUBY_VERSION < "1.9"
|
||||
expect(out).to eq("100510051005100510051005100510051005")
|
||||
if RUBY_VERSION < '1.9'
|
||||
expect(out).to eq('100510051005100510051005100510051005')
|
||||
else
|
||||
expect(out).to eq("100510051005100510051005100510051005/1")
|
||||
expect(out).to eq('100510051005100510051005100510051005/1')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
describe "Utility methods" do
|
||||
it "should merge options" do
|
||||
describe 'Utility methods' do
|
||||
it 'should merge options' do
|
||||
ap = AwesomePrint::Inspector.new
|
||||
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[:indent]).to eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
describe "Set" do
|
||||
describe 'Set' do
|
||||
before do
|
||||
@arr = [1, :two, "three" ]
|
||||
@arr = [1, :two, 'three' ]
|
||||
@set = Set.new(@arr)
|
||||
end
|
||||
|
||||
it "empty set" do
|
||||
it 'empty set' do
|
||||
expect(Set.new.ai).to eq([].ai)
|
||||
end
|
||||
|
||||
if RUBY_VERSION > "1.9"
|
||||
it "plain multiline" do
|
||||
if RUBY_VERSION > '1.9'
|
||||
it 'plain multiline' do
|
||||
expect(@set.ai(:plain => true)).to eq(@arr.ai(:plain => true))
|
||||
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))
|
||||
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))
|
||||
end
|
||||
|
||||
it "colored multiline (default)" do
|
||||
it 'colored multiline (default)' do
|
||||
expect(@set.ai).to eq(@arr.ai)
|
||||
end
|
||||
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))
|
||||
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))
|
||||
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))
|
||||
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)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
describe "Struct" do
|
||||
describe 'Struct' do
|
||||
before do
|
||||
@struct = unless defined?(Struct::SimpleStruct)
|
||||
Struct.new("SimpleStruct", :name, :address).new
|
||||
Struct.new('SimpleStruct', :name, :address).new
|
||||
else
|
||||
Struct::SimpleStruct.new
|
||||
end
|
||||
@struct.name = "Herman Munster"
|
||||
@struct.address = "1313 Mockingbird Lane"
|
||||
@struct.name = 'Herman Munster'
|
||||
@struct.address = '1313 Mockingbird Lane'
|
||||
end
|
||||
|
||||
it "empty struct" do
|
||||
expect(Struct.new("EmptyStruct").ai).to eq("\e[1;33mStruct::EmptyStruct < Struct\e[0m")
|
||||
it 'empty struct' do
|
||||
expect(Struct.new('EmptyStruct').ai).to eq("\e[1;33mStruct::EmptyStruct < Struct\e[0m")
|
||||
end
|
||||
|
||||
it "plain multiline" do
|
||||
it 'plain multiline' do
|
||||
s1 = <<-EOS.strip
|
||||
address = \"1313 Mockingbird Lane\",
|
||||
name = \"Herman Munster\"
|
||||
|
@ -614,7 +614,7 @@ EOS
|
|||
expect(@struct.ai(:plain => true)).to satisfy { |out| out.match(s1) || out.match(s2) }
|
||||
end
|
||||
|
||||
it "plain multiline indented" do
|
||||
it 'plain multiline indented' do
|
||||
s1 = <<-EOS.strip
|
||||
address = "1313 Mockingbird Lane",
|
||||
name = "Herman Munster"
|
||||
|
@ -626,13 +626,13 @@ EOS
|
|||
expect(@struct.ai(:plain => true, :indent => 1)).to satisfy { |out| out.match(s1) || out.match(s2) }
|
||||
end
|
||||
|
||||
it "plain single line" do
|
||||
s1 = "address = \"1313 Mockingbird Lane\", name = \"Herman Munster\""
|
||||
s2 = "name = \"Herman Munster\", address = \"1313 Mockingbird Lane\""
|
||||
it 'plain single line' do
|
||||
s1 = 'address = "1313 Mockingbird Lane", name = "Herman Munster"'
|
||||
s2 = 'name = "Herman Munster", address = "1313 Mockingbird Lane"'
|
||||
expect(@struct.ai(:plain => true, :multiline => false)).to satisfy { |out| out.match(s1) || out.match(s2) }
|
||||
end
|
||||
|
||||
it "colored multiline (default)" do
|
||||
it 'colored multiline (default)' do
|
||||
s1 = <<-EOS.strip
|
||||
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
|
||||
|
@ -646,15 +646,15 @@ EOS
|
|||
end
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
describe "Inherited from standard Ruby classes" do
|
||||
describe 'Inherited from standard Ruby classes' do
|
||||
after do
|
||||
Object.instance_eval{ remove_const :My } if defined?(My)
|
||||
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
|
||||
|
||||
my = My.new([ 1, :two, "three", [ nil, [ true, false ] ] ])
|
||||
my = My.new([ 1, :two, 'three', [ nil, [ true, false ] ] ])
|
||||
expect(my.ai(:plain => true)).to eq <<-EOS.strip
|
||||
[
|
||||
[0] 1,
|
||||
|
@ -671,10 +671,10 @@ EOS
|
|||
EOS
|
||||
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
|
||||
|
||||
my = My[ { 1 => { :sym => { "str" => { [1, 2, 3] => { { :k => :v } => Hash } } } } } ]
|
||||
my = My[ { 1 => { :sym => { 'str' => { [1, 2, 3] => { { :k => :v } => Hash } } } } } ]
|
||||
expect(my.ai(:plain => true)).to eq <<-EOS.strip
|
||||
{
|
||||
1 => {
|
||||
|
@ -690,14 +690,14 @@ EOS
|
|||
EOS
|
||||
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
|
||||
|
||||
my = File.new('/dev/null') rescue File.new('nul')
|
||||
expect(my.ai(:plain => true)).to eq("#{my.inspect}\n" << `ls -alF #{my.path}`.chop)
|
||||
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
|
||||
|
||||
require 'tmpdir'
|
||||
|
@ -705,7 +705,7 @@ EOS
|
|||
expect(my.ai(:plain => true)).to eq("#{my.inspect}\n" << `ls -alF #{my.path}`.chop)
|
||||
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
|
||||
def send(arg1, arg2, arg3); end
|
||||
end
|
||||
|
@ -714,7 +714,7 @@ EOS
|
|||
expect { my.methods.ai(:plain => true) }.not_to raise_error
|
||||
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
|
||||
def method
|
||||
'POST'
|
||||
|
@ -725,8 +725,8 @@ EOS
|
|||
expect { my.methods.ai(:plain => true) }.not_to raise_error
|
||||
end
|
||||
|
||||
describe "should handle a class that defines its own #to_hash method" do
|
||||
it "that takes arguments" do
|
||||
describe 'should handle a class that defines its own #to_hash method' do
|
||||
it 'that takes arguments' do
|
||||
class My
|
||||
def to_hash(a, b)
|
||||
end
|
||||
|
@ -736,7 +736,7 @@ EOS
|
|||
expect { my.ai(:plain => true) }.not_to raise_error
|
||||
end
|
||||
|
||||
it "that returns nil" do
|
||||
it 'that returns nil' do
|
||||
class My
|
||||
def to_hash()
|
||||
return nil
|
||||
|
|
|
@ -1,61 +1,61 @@
|
|||
require 'spec_helper'
|
||||
|
||||
RSpec.describe "Single method" do
|
||||
RSpec.describe 'Single method' do
|
||||
after do
|
||||
Object.instance_eval{ remove_const :Hello } if defined?(Hello)
|
||||
end
|
||||
|
||||
it "plain: should handle a method with no arguments" do
|
||||
it 'plain: should handle a method with no arguments' do
|
||||
method = ''.method(:upcase)
|
||||
expect(method.ai(:plain => true)).to eq('String#upcase()')
|
||||
end
|
||||
|
||||
it "color: should handle a method with no arguments" do
|
||||
it 'color: should handle a method with no arguments' do
|
||||
method = ''.method(:upcase)
|
||||
expect(method.ai).to eq("\e[1;33mString\e[0m#\e[0;35mupcase\e[0m\e[0;37m()\e[0m")
|
||||
end
|
||||
|
||||
it "plain: should handle a method with one argument" do
|
||||
it 'plain: should handle a method with one argument' do
|
||||
method = ''.method(:include?)
|
||||
expect(method.ai(:plain => true)).to eq('String#include?(arg1)')
|
||||
end
|
||||
|
||||
it "color: should handle a method with one argument" do
|
||||
it 'color: should handle a method with one argument' do
|
||||
method = ''.method(:include?)
|
||||
expect(method.ai).to eq("\e[1;33mString\e[0m#\e[0;35minclude?\e[0m\e[0;37m(arg1)\e[0m")
|
||||
end
|
||||
|
||||
it "plain: should handle a method with two arguments" do
|
||||
it 'plain: should handle a method with two arguments' do
|
||||
method = ''.method(:tr)
|
||||
expect(method.ai(:plain => true)).to eq('String#tr(arg1, arg2)')
|
||||
end
|
||||
|
||||
it "color: should handle a method with two arguments" do
|
||||
it 'color: should handle a method with two arguments' do
|
||||
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")
|
||||
end
|
||||
|
||||
it "plain: should handle a method with multiple arguments" do
|
||||
it 'plain: should handle a method with multiple arguments' do
|
||||
method = ''.method(:split)
|
||||
expect(method.ai(:plain => true)).to eq('String#split(*arg1)')
|
||||
end
|
||||
|
||||
it "color: should handle a method with multiple arguments" do
|
||||
it 'color: should handle a method with multiple arguments' do
|
||||
method = ''.method(:split)
|
||||
expect(method.ai).to eq("\e[1;33mString\e[0m#\e[0;35msplit\e[0m\e[0;37m(*arg1)\e[0m")
|
||||
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?)
|
||||
expect(method.ai(:plain => true)).to eq('String (Kernel)#is_a?(arg1)')
|
||||
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?)
|
||||
expect(method.ai).to eq("\e[1;33mString (Kernel)\e[0m#\e[0;35mis_a?\e[0m\e[0;37m(arg1)\e[0m")
|
||||
end
|
||||
|
||||
it "plain: should handle an unbound method" do
|
||||
it 'plain: should handle an unbound method' do
|
||||
class Hello
|
||||
def world; end
|
||||
end
|
||||
|
@ -63,7 +63,7 @@ RSpec.describe "Single method" do
|
|||
expect(method.ai(:plain => true)).to eq('Hello (unbound)#world()')
|
||||
end
|
||||
|
||||
it "color: should handle an unbound method" do
|
||||
it 'color: should handle an unbound method' do
|
||||
class Hello
|
||||
def world(a,b); end
|
||||
end
|
||||
|
@ -76,49 +76,49 @@ RSpec.describe "Single method" do
|
|||
end
|
||||
end
|
||||
|
||||
RSpec.describe "Object methods" do
|
||||
RSpec.describe 'Object methods' do
|
||||
after do
|
||||
Object.instance_eval{ remove_const :Hello } if defined?(Hello)
|
||||
end
|
||||
|
||||
describe "object.methods" do
|
||||
it "index: should handle object.methods" do
|
||||
describe 'object.methods' do
|
||||
it 'index: should handle object.methods' do
|
||||
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\)$/)
|
||||
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
|
||||
expect(out).to match(/^\s+is_a\?\(arg1\)\s+NilClass \(Kernel\)$/)
|
||||
end
|
||||
end
|
||||
|
||||
describe "object.public_methods" do
|
||||
it "index: should handle object.public_methods" do
|
||||
describe '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
|
||||
expect(out).to match(/^\s+\[\s*\d+\]\s+is_a\?\(arg1\)\s+NilClass \(Kernel\)$/)
|
||||
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
|
||||
expect(out).to match(/^\s+is_a\?\(arg1\)\s+NilClass \(Kernel\)$/)
|
||||
end
|
||||
end
|
||||
|
||||
describe "object.private_methods" do
|
||||
it "index: should handle object.private_methods" do
|
||||
describe 'object.private_methods' do
|
||||
it 'index: should handle object.private_methods' do
|
||||
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\)$/)
|
||||
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
|
||||
expect(out).to match(/^\s+sleep\(\*arg1\)\s+NilClass \(Kernel\)$/)
|
||||
end
|
||||
end
|
||||
|
||||
describe "object.protected_methods" do
|
||||
it "index: should handle object.protected_methods" do
|
||||
describe 'object.protected_methods' do
|
||||
it 'index: should handle object.protected_methods' do
|
||||
class Hello
|
||||
protected
|
||||
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]")
|
||||
end
|
||||
|
||||
it "no index: should handle object.protected_methods" do
|
||||
it 'no index: should handle object.protected_methods' do
|
||||
class Hello
|
||||
protected
|
||||
def m3(a,b); end
|
||||
|
@ -140,8 +140,8 @@ RSpec.describe "Object methods" do
|
|||
end
|
||||
end
|
||||
|
||||
describe "object.private_methods" do
|
||||
it "index: should handle object.private_methods" do
|
||||
describe 'object.private_methods' do
|
||||
it 'index: should handle object.private_methods' do
|
||||
class Hello
|
||||
private
|
||||
def m1; end
|
||||
|
@ -153,7 +153,7 @@ RSpec.describe "Object methods" do
|
|||
expect(out.last).to match(/^\s+\[\s*\d+\]\s+m2\(\)\s+Hello$/)
|
||||
end
|
||||
|
||||
it "no index: should handle object.private_methods" do
|
||||
it 'no index: should handle object.private_methods' do
|
||||
class Hello
|
||||
private
|
||||
def m3(a,b); end
|
||||
|
@ -167,8 +167,8 @@ RSpec.describe "Object methods" do
|
|||
end
|
||||
end
|
||||
|
||||
describe "object.singleton_methods" do
|
||||
it "index: should handle object.singleton_methods" do
|
||||
describe 'object.singleton_methods' do
|
||||
it 'index: should handle object.singleton_methods' do
|
||||
class Hello
|
||||
class << self
|
||||
def m1; end
|
||||
|
@ -180,7 +180,7 @@ RSpec.describe "Object methods" do
|
|||
expect(out.last).to match(/^\s+\[\s*\d+\]\s+m2\(\)\s+Hello$/)
|
||||
end
|
||||
|
||||
it "no index: should handle object.singleton_methods" do
|
||||
it 'no index: should handle object.singleton_methods' do
|
||||
class Hello
|
||||
def self.m3(a,b); end
|
||||
end
|
||||
|
@ -194,13 +194,13 @@ RSpec.describe "Object methods" do
|
|||
end
|
||||
end
|
||||
|
||||
RSpec.describe "Class methods" do
|
||||
RSpec.describe 'Class methods' do
|
||||
after do
|
||||
Object.instance_eval{ remove_const :Hello } if defined?(Hello)
|
||||
end
|
||||
|
||||
describe "class.instance_methods" do
|
||||
it "index: should handle unbound class.instance_methods" do
|
||||
describe 'class.instance_methods' do
|
||||
it 'index: should handle unbound class.instance_methods' do
|
||||
class Hello
|
||||
def m1; 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\)$/)
|
||||
end
|
||||
|
||||
it "no index: should handle unbound class.instance_methods" do
|
||||
it 'no index: should handle unbound class.instance_methods' do
|
||||
class Hello
|
||||
def m3(a,b); end
|
||||
end
|
||||
|
@ -223,8 +223,8 @@ RSpec.describe "Class methods" do
|
|||
end
|
||||
end
|
||||
|
||||
describe "class.public_instance_methods" do
|
||||
it "index: should handle class.public_instance_methods" do
|
||||
describe 'class.public_instance_methods' do
|
||||
it 'index: should handle class.public_instance_methods' do
|
||||
class Hello
|
||||
def m1; 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\)$/)
|
||||
end
|
||||
|
||||
it "no index: should handle class.public_instance_methods" do
|
||||
it 'no index: should handle class.public_instance_methods' do
|
||||
class Hello
|
||||
def m3(a,b); end
|
||||
end
|
||||
|
@ -247,8 +247,8 @@ RSpec.describe "Class methods" do
|
|||
end
|
||||
end
|
||||
|
||||
describe "class.protected_instance_methods" do
|
||||
it "index: should handle class.protected_instance_methods" do
|
||||
describe 'class.protected_instance_methods' do
|
||||
it 'index: should handle class.protected_instance_methods' do
|
||||
class Hello
|
||||
protected
|
||||
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\)$/)
|
||||
end
|
||||
|
||||
it "no index: should handle class.protected_instance_methods" do
|
||||
it 'no index: should handle class.protected_instance_methods' do
|
||||
class Hello
|
||||
protected
|
||||
def m3(a,b); end
|
||||
|
@ -273,8 +273,8 @@ RSpec.describe "Class methods" do
|
|||
end
|
||||
end
|
||||
|
||||
describe "class.private_instance_methods" do
|
||||
it "index: should handle class.private_instance_methods" do
|
||||
describe 'class.private_instance_methods' do
|
||||
it 'index: should handle class.private_instance_methods' do
|
||||
class Hello
|
||||
private
|
||||
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\)$/)
|
||||
end
|
||||
|
||||
it "no index: should handle class.private_instance_methods" do
|
||||
it 'no index: should handle class.private_instance_methods' do
|
||||
class Hello
|
||||
private
|
||||
def m3(a,b); end
|
||||
|
@ -301,7 +301,7 @@ RSpec.describe "Class methods" do
|
|||
end
|
||||
|
||||
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
|
||||
stub_dotfile!
|
||||
end
|
||||
|
@ -310,7 +310,7 @@ if RUBY_VERSION >= '1.9.2'
|
|||
Object.instance_eval{ remove_const :Hello } if defined?(Hello)
|
||||
end
|
||||
|
||||
it "()" do
|
||||
it '()' do
|
||||
class Hello
|
||||
def m1; end
|
||||
end
|
||||
|
@ -318,7 +318,7 @@ if RUBY_VERSION >= '1.9.2'
|
|||
expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(\)\s+Hello$/)
|
||||
end
|
||||
|
||||
it ":req" do
|
||||
it ':req' do
|
||||
class Hello
|
||||
def m1(a, b, c); 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$/)
|
||||
end
|
||||
|
||||
it ":opt" do
|
||||
it ':opt' do
|
||||
class Hello
|
||||
def m1(a, b = 1, c = 2); end # m1(a, *b, *c)
|
||||
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$/)
|
||||
end
|
||||
|
||||
it ":rest" do
|
||||
it ':rest' do
|
||||
class Hello
|
||||
def m1(*a); end # m1(*a)
|
||||
end
|
||||
|
@ -342,7 +342,7 @@ if RUBY_VERSION >= '1.9.2'
|
|||
expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(\*a\)\s+Hello$/)
|
||||
end
|
||||
|
||||
it ":block" do
|
||||
it ':block' do
|
||||
class Hello
|
||||
def m1(a, b = nil, &blk); end # m1(a, *b, &blk)
|
||||
end
|
||||
|
@ -352,13 +352,13 @@ if RUBY_VERSION >= '1.9.2'
|
|||
end
|
||||
end
|
||||
|
||||
RSpec.describe "Methods arrays" do
|
||||
RSpec.describe 'Methods arrays' do
|
||||
after do
|
||||
Object.instance_eval{ remove_const :Hello } if defined?(Hello)
|
||||
Object.instance_eval{ remove_const :World } if defined?(World)
|
||||
end
|
||||
|
||||
it "obj1.methods - obj2.methods should be awesome printed" do
|
||||
it 'obj1.methods - obj2.methods should be awesome printed' do
|
||||
stub_dotfile!
|
||||
class Hello
|
||||
def self.m1; end
|
||||
|
@ -367,7 +367,7 @@ RSpec.describe "Methods arrays" do
|
|||
expect(out).to eq("[\n [0] m1() Hello\n]")
|
||||
end
|
||||
|
||||
it "obj1.methods & obj2.methods should be awesome printed" do
|
||||
it 'obj1.methods & obj2.methods should be awesome printed' do
|
||||
stub_dotfile!
|
||||
class Hello
|
||||
def self.m1; end
|
||||
|
@ -380,7 +380,7 @@ RSpec.describe "Methods arrays" do
|
|||
expect(out).to eq("[\n [0] m1() Hello\n]")
|
||||
end
|
||||
|
||||
it "obj1.methods.grep(pattern) should be awesome printed" do
|
||||
it 'obj1.methods.grep(pattern) should be awesome printed' do
|
||||
stub_dotfile!
|
||||
class Hello
|
||||
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]")
|
||||
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
|
||||
def self.m_one; end
|
||||
def self.m_two; end
|
||||
|
@ -403,7 +403,7 @@ RSpec.describe "Methods arrays" do
|
|||
expect(out).to eq([:one, :two])
|
||||
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!
|
||||
class Hello
|
||||
def self.m0; end
|
||||
|
@ -417,7 +417,7 @@ RSpec.describe "Methods arrays" do
|
|||
end
|
||||
|
||||
# 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
|
||||
private
|
||||
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 ])
|
||||
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 ]
|
||||
expect { arr.ai(:plain => true) }.not_to raise_error
|
||||
if RUBY_VERSION < '1.9.2'
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
require 'spec_helper'
|
||||
|
||||
RSpec.describe "AwesomePrint" do
|
||||
RSpec.describe 'AwesomePrint' do
|
||||
|
||||
describe "Misc" do
|
||||
it "handle weird objects that return nil on inspect" do
|
||||
describe 'Misc' do
|
||||
it 'handle weird objects that return nil on inspect' do
|
||||
weird = Class.new do
|
||||
def inspect
|
||||
nil
|
||||
|
@ -12,24 +12,24 @@ RSpec.describe "AwesomePrint" do
|
|||
expect(weird.new.ai(:plain => true)).to eq('')
|
||||
end
|
||||
|
||||
it "handle frozen object.inspect" do
|
||||
it 'handle frozen object.inspect' do
|
||||
weird = Class.new do
|
||||
def inspect
|
||||
"ice".freeze
|
||||
'ice'.freeze
|
||||
end
|
||||
end
|
||||
expect(weird.new.ai(:plain => false)).to eq("ice")
|
||||
expect(weird.new.ai(:plain => false)).to eq('ice')
|
||||
end
|
||||
|
||||
# See https://github.com/awesome-print/awesome_print/issues/35
|
||||
it "handle array grep when pattern contains / chapacter" do
|
||||
hash = { "1/x" => 1, "2//x" => :"2" }
|
||||
it 'handle array grep when pattern contains / chapacter' do
|
||||
hash = { '1/x' => 1, '2//x' => :"2" }
|
||||
grepped = hash.keys.sort.grep(/^(\d+)\//) { $1 }
|
||||
expect(grepped.ai(:plain => true, :multiline => false)).to eq('[ "1", "2" ]')
|
||||
end
|
||||
|
||||
# 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
|
||||
arr = (0..6).to_a
|
||||
grepped = arr.grep(1..4, &:succ)
|
||||
|
@ -37,7 +37,7 @@ RSpec.describe "AwesomePrint" do
|
|||
end
|
||||
end
|
||||
|
||||
it "returns value passed as a parameter" do
|
||||
it 'returns value passed as a parameter' do
|
||||
object = rand
|
||||
allow(self).to receive(:puts)
|
||||
expect(ap object).to eq(object)
|
||||
|
@ -49,20 +49,20 @@ RSpec.describe "AwesomePrint" do
|
|||
expect { rand.ai }.not_to raise_error
|
||||
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).to eq(ENV.to_hash.ai)
|
||||
end
|
||||
|
||||
# See https://github.com/awesome-print/awesome_print/issues/134
|
||||
it "IPAddr workaround" do
|
||||
require "ipaddr"
|
||||
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>")
|
||||
it 'IPAddr workaround' do
|
||||
require 'ipaddr'
|
||||
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>')
|
||||
end
|
||||
|
||||
# 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
|
||||
# Raises NoMethodError: undefined method `id' when "other" is nil or ENV.
|
||||
def ==(other)
|
||||
|
@ -75,19 +75,19 @@ RSpec.describe "AwesomePrint" do
|
|||
end
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
describe "HTML output" do
|
||||
it "wraps ap output with plain <pre> tag" do
|
||||
describe 'HTML output' do
|
||||
it 'wraps ap output with plain <pre> tag' do
|
||||
markup = rand
|
||||
expect(markup.ai(:html => true, :plain => true)).to eq("<pre>#{markup}</pre>")
|
||||
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
|
||||
expect(markup.ai(:html => true)).to eq(%Q|<pre><kbd style="color:blue">#{markup}</kbd></pre>|)
|
||||
end
|
||||
|
||||
it "wraps multiline ap output with <pre> tag with colorized <kbd>" do
|
||||
markup = [ 1, :two, "three" ]
|
||||
it 'wraps multiline ap output with <pre> tag with colorized <kbd>' do
|
||||
markup = [ 1, :two, 'three' ]
|
||||
expect(markup.ai(:html => true)).to eq <<-EOS.strip_heredoc.strip
|
||||
<pre>[
|
||||
<kbd style="color:white">[0] </kbd><kbd style="color:blue">1</kbd>,
|
||||
|
@ -97,8 +97,8 @@ RSpec.describe "AwesomePrint" do
|
|||
EOS
|
||||
end
|
||||
|
||||
it "wraps hash ap output with only an outer <pre> tag" do
|
||||
markup = [ { "hello" => "world" } ]
|
||||
it 'wraps hash ap output with only an outer <pre> tag' do
|
||||
markup = [ { 'hello' => 'world' } ]
|
||||
expect(markup.ai(:html => true)).to eq <<-EOS.strip_heredoc.strip
|
||||
<pre>[
|
||||
<kbd style="color:white">[0] </kbd>{
|
||||
|
@ -108,27 +108,27 @@ RSpec.describe "AwesomePrint" do
|
|||
EOS
|
||||
end
|
||||
|
||||
it "encodes HTML entities (plain)" do
|
||||
it 'encodes HTML entities (plain)' do
|
||||
markup = ' &<hello>'
|
||||
expect(markup.ai(:html => true, :plain => true)).to eq('<pre>" &<hello>"</pre>')
|
||||
end
|
||||
|
||||
it "encodes HTML entities (color)" do
|
||||
it 'encodes HTML entities (color)' do
|
||||
markup = ' &<hello>'
|
||||
expect(markup.ai(:html => true)).to eq('<pre><kbd style="color:brown">" &<hello>"</kbd></pre>')
|
||||
end
|
||||
end
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
describe "AwesomePrint.defaults" do
|
||||
describe 'AwesomePrint.defaults' do
|
||||
after do
|
||||
AwesomePrint.defaults = nil
|
||||
end
|
||||
|
||||
# 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 }
|
||||
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)
|
||||
expect(out).to eq <<-EOS.strip_heredoc.strip
|
||||
{
|
||||
|
@ -141,9 +141,9 @@ RSpec.describe "AwesomePrint" do
|
|||
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.
|
||||
@awesome_method = "".method(:red)
|
||||
@awesome_method = ''.method(:red)
|
||||
|
||||
String.instance_eval do
|
||||
define_method :red do # Method arity is now 0 in Ruby 1.9+.
|
||||
|
@ -159,34 +159,34 @@ RSpec.describe "AwesomePrint" do
|
|||
end
|
||||
end
|
||||
|
||||
it "shoud not raise ArgumentError when formatting HTML" do
|
||||
out = "hello".ai(:color => { :string => :red }, :html => true)
|
||||
if RUBY_VERSION >= "1.9"
|
||||
it 'shoud not raise ArgumentError when formatting HTML' do
|
||||
out = 'hello'.ai(:color => { :string => :red }, :html => true)
|
||||
if RUBY_VERSION >= '1.9'
|
||||
expect(out).to eq(%Q|<pre>[red]<kbd style="color:red">"hello"</kbd>[/red]</pre>|)
|
||||
else
|
||||
expect(out).to eq(%Q|<pre>[red]"hello"[/red]</pre>|)
|
||||
end
|
||||
end
|
||||
|
||||
it "shoud not raise ArgumentError when formatting HTML (shade color)" do
|
||||
out = "hello".ai(:color => { :string => :redish }, :html => true)
|
||||
it 'shoud not raise ArgumentError when formatting HTML (shade color)' do
|
||||
out = 'hello'.ai(:color => { :string => :redish }, :html => true)
|
||||
expect(out).to eq(%Q|<pre><kbd style="color:darkred">"hello"</kbd></pre>|)
|
||||
end
|
||||
|
||||
it "shoud not raise ArgumentError when formatting non-HTML" do
|
||||
out = "hello".ai(:color => { :string => :red }, :html => false)
|
||||
it 'shoud not raise ArgumentError when formatting non-HTML' do
|
||||
out = 'hello'.ai(:color => { :string => :red }, :html => false)
|
||||
expect(out).to eq(%Q|[red]"hello"[/red]|)
|
||||
end
|
||||
|
||||
it "shoud not raise ArgumentError when formatting non-HTML (shade color)" do
|
||||
out = "hello".ai(:color => { :string => :redish }, :html => false)
|
||||
it 'shoud not raise ArgumentError when formatting non-HTML (shade color)' do
|
||||
out = 'hello'.ai(:color => { :string => :redish }, :html => false)
|
||||
expect(out).to eq(%Q|\e[0;31m"hello"\e[0m|)
|
||||
end
|
||||
end
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
describe "Console" do
|
||||
it "should detect IRB" do
|
||||
describe 'Console' do
|
||||
it 'should detect IRB' do
|
||||
class IRB; end
|
||||
ENV.delete('RAILS_ENV')
|
||||
expect(AwesomePrint.console?).to eq(true)
|
||||
|
@ -194,7 +194,7 @@ RSpec.describe "AwesomePrint" do
|
|||
Object.instance_eval{ remove_const :IRB }
|
||||
end
|
||||
|
||||
it "should detect Pry" do
|
||||
it 'should detect Pry' do
|
||||
class Pry; end
|
||||
ENV.delete('RAILS_ENV')
|
||||
expect(AwesomePrint.console?).to eq(true)
|
||||
|
@ -202,7 +202,7 @@ RSpec.describe "AwesomePrint" do
|
|||
Object.instance_eval{ remove_const :Pry }
|
||||
end
|
||||
|
||||
it "should detect Rails::Console" do
|
||||
it 'should detect Rails::Console' do
|
||||
class IRB; end
|
||||
module Rails; class Console; end; end
|
||||
expect(AwesomePrint.console?).to eq(true)
|
||||
|
@ -213,25 +213,25 @@ RSpec.describe "AwesomePrint" do
|
|||
|
||||
it "should detect ENV['RAILS_ENV']" do
|
||||
class Pry; end
|
||||
ENV["RAILS_ENV"] = "development"
|
||||
ENV['RAILS_ENV'] = 'development'
|
||||
expect(AwesomePrint.console?).to eq(true)
|
||||
expect(AwesomePrint.rails_console?).to eq(true)
|
||||
Object.instance_eval{ remove_const :Pry }
|
||||
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({ :a => 1 }) }).to eq({ :a => 1 })
|
||||
end
|
||||
|
||||
it "should return nil when running under console" do
|
||||
it 'should return nil when running under console' do
|
||||
class IRB; end
|
||||
expect(capture! { ap([ 1, 2, 3 ]) }).to eq(nil)
|
||||
expect(capture! { ap({ :a => 1 }) }).to eq(nil)
|
||||
Object.instance_eval{ remove_const :IRB }
|
||||
end
|
||||
|
||||
it "handles NoMethodError on IRB implicit #ai" do
|
||||
it 'handles NoMethodError on IRB implicit #ai' do
|
||||
module IRB; class Irb; end; end
|
||||
irb_context = double('irb_context', last_value: BasicObject.new)
|
||||
IRB.define_singleton_method :version, -> { 'test_version' }
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
require 'spec_helper'
|
||||
|
||||
RSpec.describe "Objects" do
|
||||
RSpec.describe 'Objects' do
|
||||
after do
|
||||
Object.instance_eval{ remove_const :Hello } if defined?(Hello)
|
||||
end
|
||||
|
||||
describe "Formatting an object" do
|
||||
it "attributes" do
|
||||
describe 'Formatting an object' do
|
||||
it 'attributes' do
|
||||
class Hello
|
||||
attr_reader :abra
|
||||
attr_writer :ca
|
||||
|
@ -30,7 +30,7 @@ EOS
|
|||
expect(hello.ai(:plain => true, :raw => false)).to eq(hello.inspect)
|
||||
end
|
||||
|
||||
it "instance variables" do
|
||||
it 'instance variables' do
|
||||
class Hello
|
||||
def initialize
|
||||
@abra, @ca, @dabra = 1, 2, 3
|
||||
|
@ -50,7 +50,7 @@ EOS
|
|||
expect(hello.ai(:plain => true, :raw => false)).to eq(hello.inspect)
|
||||
end
|
||||
|
||||
it "attributes and instance variables" do
|
||||
it 'attributes and instance variables' do
|
||||
class Hello
|
||||
attr_reader :abra
|
||||
attr_writer :ca
|
||||
|
@ -78,7 +78,7 @@ EOS
|
|||
expect(hello.ai(:plain => true, :raw => false)).to eq(hello.inspect)
|
||||
end
|
||||
|
||||
it "without the plain options print the colorized values" do
|
||||
it 'without the plain options print the colorized values' do
|
||||
class Hello
|
||||
attr_reader :abra
|
||||
attr_writer :ca
|
||||
|
@ -102,7 +102,7 @@ EOS
|
|||
expect(hello.ai(:plain => true, :raw => false)).to eq(hello.inspect)
|
||||
end
|
||||
|
||||
it "with multine as false show inline values" do
|
||||
it 'with multine as false show inline values' do
|
||||
class Hello
|
||||
attr_reader :abra
|
||||
attr_writer :ca
|
||||
|
|
Loading…
Reference in a new issue