mirror of
https://github.com/awesome-print/awesome_print
synced 2023-03-27 23:22:34 -04:00
Merge pull request #266 from gerrywastaken/fix/bad-defaults-in-random-spec-order
Fix/bad defaults in random spec order
This commit is contained in:
commit
49d50bdbc4
16 changed files with 41 additions and 72 deletions
|
@ -5,13 +5,17 @@
|
|||
#------------------------------------------------------------------------------
|
||||
module AwesomePrint
|
||||
module ActionView
|
||||
|
||||
# Use HTML colors and add default "debug_dump" class to the resulting HTML.
|
||||
def ap_debug(object, options = {})
|
||||
object.ai(options.merge(:html => true)).sub(/^<pre([\s>])/, '<pre class="debug_dump"\\1')
|
||||
object.ai(
|
||||
options.merge(html: true)
|
||||
).sub(
|
||||
/^<pre([\s>])/,
|
||||
'<pre class="debug_dump"\\1'
|
||||
)
|
||||
end
|
||||
|
||||
alias_method :ap, :ap_debug
|
||||
alias ap ap_debug
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -137,11 +137,18 @@ module AwesomePrint
|
|||
@options.merge!(options)
|
||||
end
|
||||
|
||||
# This method needs to be mocked during testing so that it always loads
|
||||
# predictable values
|
||||
#---------------------------------------------------------------------------
|
||||
def load_dotfile
|
||||
dotfile = File.join(ENV['HOME'], '.aprc')
|
||||
load dotfile if File.readable?(dotfile)
|
||||
end
|
||||
|
||||
# Load ~/.aprc file with custom defaults that override default options.
|
||||
#---------------------------------------------------------------------------
|
||||
def merge_custom_defaults!
|
||||
dotfile = File.join(ENV['HOME'], '.aprc')
|
||||
load dotfile if File.readable?(dotfile)
|
||||
load_dotfile
|
||||
merge_options!(AwesomePrint.defaults) if AwesomePrint.defaults.is_a?(Hash)
|
||||
rescue => e
|
||||
$stderr.puts "Could not load #{dotfile}: #{e}"
|
||||
|
|
|
@ -9,10 +9,6 @@ RSpec.describe "AwesomePrint" do
|
|||
end
|
||||
end
|
||||
|
||||
before do
|
||||
stub_dotfile!
|
||||
end
|
||||
|
||||
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 ] ] ]"
|
||||
|
|
|
@ -2,12 +2,6 @@ require 'spec_helper'
|
|||
require 'active_record_helper'
|
||||
|
||||
RSpec.describe "AwesomePrint/ActiveRecord", skip: ->{ !ExtVerifier.has_rails? }.call do
|
||||
|
||||
before do
|
||||
stub_dotfile!
|
||||
end
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
describe "ActiveRecord instance, attributes only (default)" do
|
||||
before do
|
||||
ActiveRecord::Base.default_timezone = :utc
|
||||
|
|
|
@ -2,7 +2,6 @@ require 'spec_helper'
|
|||
|
||||
RSpec.describe "AwesomePrint::ActiveSupport", skip: ->{ !ExtVerifier.has_rails? }.call do
|
||||
before do
|
||||
stub_dotfile!
|
||||
@ap = AwesomePrint::Inspector.new
|
||||
end
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
require 'spec_helper'
|
||||
|
||||
RSpec.describe "AwesomePrint/MongoMapper", skip: ->{ !ExtVerifier.has_mongo_mapper? }.call do
|
||||
|
||||
if ExtVerifier.has_mongo_mapper?
|
||||
before :all do
|
||||
class MongoUser
|
||||
|
@ -19,7 +18,6 @@ RSpec.describe "AwesomePrint/MongoMapper", skip: ->{ !ExtVerifier.has_mongo_mapp
|
|||
end
|
||||
|
||||
before do
|
||||
stub_dotfile!
|
||||
@ap = AwesomePrint::Inspector.new(:plain => true, :sort_keys => true)
|
||||
end
|
||||
|
||||
|
|
|
@ -19,7 +19,6 @@ RSpec.describe "AwesomePrint/Mongoid", skip: ->{ !ExtVerifier.has_mongoid? }.cal
|
|||
end
|
||||
|
||||
before do
|
||||
stub_dotfile!
|
||||
@ap = AwesomePrint::Inspector.new :plain => true, :sort_keys => true
|
||||
end
|
||||
|
||||
|
|
|
@ -26,7 +26,6 @@ RSpec.describe "AwesomePrint/NoBrainer", skip: ->{ !ExtVerifier.has_nobrainer? }
|
|||
end
|
||||
|
||||
before do
|
||||
stub_dotfile!
|
||||
@ap = AwesomePrint::Inspector.new :plain => true
|
||||
end
|
||||
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
require 'spec_helper'
|
||||
|
||||
RSpec.describe "AwesomePrint/Nokogiri" do
|
||||
before do
|
||||
stub_dotfile!
|
||||
end
|
||||
|
||||
it "should colorize tags" do
|
||||
xml = Nokogiri::XML('<html><body><h1></h1></body></html>')
|
||||
expect(xml.ai).to eq <<-EOS
|
||||
|
|
|
@ -2,7 +2,6 @@ require 'spec_helper'
|
|||
|
||||
RSpec.describe 'AwesomePrint Ostruct extension' do
|
||||
before do
|
||||
stub_dotfile!
|
||||
@ap = AwesomePrint::Inspector.new(:plain => true, :sort_keys => true)
|
||||
end
|
||||
|
||||
|
|
|
@ -20,7 +20,6 @@ RSpec.describe 'AwesomePrint/Ripple', skip: ->{ !ExtVerifier.has_ripple? }.call
|
|||
end
|
||||
|
||||
before do
|
||||
stub_dotfile!
|
||||
@ap = AwesomePrint::Inspector.new :plain => true, :sort_keys => true
|
||||
end
|
||||
|
||||
|
|
|
@ -4,10 +4,6 @@ require "rational"
|
|||
require "set"
|
||||
|
||||
RSpec.describe "AwesomePrint" do
|
||||
before do
|
||||
stub_dotfile!
|
||||
end
|
||||
|
||||
describe "Array" do
|
||||
before do
|
||||
@arr = [ 1, :two, "three", [ nil, [ true, false] ] ]
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
require 'spec_helper'
|
||||
|
||||
RSpec.describe "Single method" do
|
||||
before do
|
||||
stub_dotfile!
|
||||
end
|
||||
|
||||
after do
|
||||
Object.instance_eval{ remove_const :Hello } if defined?(Hello)
|
||||
end
|
||||
|
@ -81,10 +77,6 @@ RSpec.describe "Single method" do
|
|||
end
|
||||
|
||||
RSpec.describe "Object methods" do
|
||||
before do
|
||||
stub_dotfile!
|
||||
end
|
||||
|
||||
after do
|
||||
Object.instance_eval{ remove_const :Hello } if defined?(Hello)
|
||||
end
|
||||
|
@ -203,10 +195,6 @@ RSpec.describe "Object methods" do
|
|||
end
|
||||
|
||||
RSpec.describe "Class methods" do
|
||||
before do
|
||||
stub_dotfile!
|
||||
end
|
||||
|
||||
after do
|
||||
Object.instance_eval{ remove_const :Hello } if defined?(Hello)
|
||||
end
|
||||
|
|
|
@ -3,10 +3,6 @@ require 'spec_helper'
|
|||
RSpec.describe "AwesomePrint" do
|
||||
|
||||
describe "Misc" do
|
||||
before do
|
||||
stub_dotfile!
|
||||
end
|
||||
|
||||
it "handle weird objects that return nil on inspect" do
|
||||
weird = Class.new do
|
||||
def inspect
|
||||
|
@ -80,10 +76,6 @@ RSpec.describe "AwesomePrint" do
|
|||
|
||||
#------------------------------------------------------------------------------
|
||||
describe "HTML output" do
|
||||
before do
|
||||
stub_dotfile!
|
||||
end
|
||||
|
||||
it "wraps ap output with plain <pre> tag" do
|
||||
markup = rand
|
||||
expect(markup.ai(:html => true, :plain => true)).to eq("<pre>#{markup}</pre>")
|
||||
|
@ -129,10 +121,6 @@ RSpec.describe "AwesomePrint" do
|
|||
|
||||
#------------------------------------------------------------------------------
|
||||
describe "AwesomePrint.defaults" do
|
||||
before do
|
||||
stub_dotfile!
|
||||
end
|
||||
|
||||
after do
|
||||
AwesomePrint.defaults = nil
|
||||
end
|
||||
|
@ -154,10 +142,6 @@ RSpec.describe "AwesomePrint" do
|
|||
|
||||
#------------------------------------------------------------------------------
|
||||
describe "Coexistence with the colorize gem" do
|
||||
before do
|
||||
stub_dotfile!
|
||||
end
|
||||
|
||||
before do # Redefine String#red just like colorize gem does it.
|
||||
@awesome_method = "".method(:red)
|
||||
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
require 'spec_helper'
|
||||
|
||||
RSpec.describe "Objects" do
|
||||
before do
|
||||
stub_dotfile!
|
||||
end
|
||||
|
||||
after do
|
||||
Object.instance_eval{ remove_const :Hello } if defined?(Hello)
|
||||
end
|
||||
|
|
|
@ -23,8 +23,17 @@ Dir[File.dirname(__FILE__) + '/support/**/*.rb'].each do |file|
|
|||
require file
|
||||
end
|
||||
|
||||
ExtVerifier.require_dependencies!(%w{rails active_record action_view
|
||||
active_support/all mongoid mongo_mapper ripple nobrainer})
|
||||
ExtVerifier.require_dependencies!(
|
||||
%w(
|
||||
rails
|
||||
active_record
|
||||
action_view
|
||||
active_support/all
|
||||
mongoid
|
||||
mongo_mapper
|
||||
ripple nobrainer
|
||||
)
|
||||
)
|
||||
require 'nokogiri'
|
||||
require 'awesome_print'
|
||||
|
||||
|
@ -42,8 +51,13 @@ RSpec.configure do |config|
|
|||
mocks.syntax = :expect
|
||||
mocks.verify_partial_doubles = true
|
||||
end
|
||||
if config.files_to_run.one?
|
||||
config.default_formatter = 'doc'
|
||||
|
||||
config.default_formatter = 'doc' if config.files_to_run.one?
|
||||
|
||||
# Run before all examples. Using suite or all will not work as stubs are
|
||||
# killed after each example ends.
|
||||
config.before(:each) do |_example|
|
||||
stub_dotfile!
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -71,13 +85,14 @@ def normalize_object_id_strings(str, options)
|
|||
end
|
||||
|
||||
def stub_dotfile!
|
||||
dotfile = File.join(ENV['HOME'], '.aprc')
|
||||
allow(File).to receive(:readable?).and_call_original
|
||||
expect(File).to receive(:readable?).at_least(:once).with(dotfile).and_return(false)
|
||||
allow_any_instance_of(AwesomePrint::Inspector)
|
||||
.to receive(:load_dotfile)
|
||||
.and_return(true)
|
||||
end
|
||||
|
||||
def capture!
|
||||
standard, $stdout = $stdout, StringIO.new
|
||||
standard = $stdout
|
||||
$stdout = StringIO.new
|
||||
yield
|
||||
ensure
|
||||
$stdout = standard
|
||||
|
|
Loading…
Reference in a new issue