1
0
Fork 0
mirror of https://github.com/awesome-print/awesome_print synced 2023-03-27 23:22:34 -04:00

Ensure stub_dotfile! is called before all specs

The previous stubbing of dotfiles was still allowing calls to fall
through and populate the AwesomePrint.defaults hash which would then
cause some tests to fail if run in a certain order.

e.g. https://github.com/awesome-print/awesome_print/issues/265

One place in particular where this would happen is if you ran the
action_view_spec before other specs as it did not stub the dotfile.

This change makes dotfile stubbing more reliable, specific and
ensures it is run for every spec. I've also removed all instances
where it was being called manually, as this is now not needed due
to it being automatic.
This commit is contained in:
Gerard Caulfield 2016-08-27 23:43:32 +10:00
parent 8aef1bde91
commit f628193028
No known key found for this signature in database
GPG key ID: 623B327128A9BEC3
14 changed files with 10 additions and 62 deletions

View file

@ -9,10 +9,6 @@ RSpec.describe "AwesomePrint" do
end end
end end
before do
stub_dotfile!
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 ] ] ]"

View file

@ -2,12 +2,6 @@ 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
before do
stub_dotfile!
end
#------------------------------------------------------------------------------
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

View file

@ -2,7 +2,6 @@ require 'spec_helper'
RSpec.describe "AwesomePrint::ActiveSupport", skip: ->{ !ExtVerifier.has_rails? }.call do RSpec.describe "AwesomePrint::ActiveSupport", skip: ->{ !ExtVerifier.has_rails? }.call do
before do before do
stub_dotfile!
@ap = AwesomePrint::Inspector.new @ap = AwesomePrint::Inspector.new
end end

View file

@ -1,7 +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
@ -19,7 +18,6 @@ RSpec.describe "AwesomePrint/MongoMapper", skip: ->{ !ExtVerifier.has_mongo_mapp
end end
before do before do
stub_dotfile!
@ap = AwesomePrint::Inspector.new(:plain => true, :sort_keys => true) @ap = AwesomePrint::Inspector.new(:plain => true, :sort_keys => true)
end end

View file

@ -19,7 +19,6 @@ RSpec.describe "AwesomePrint/Mongoid", skip: ->{ !ExtVerifier.has_mongoid? }.cal
end end
before do before do
stub_dotfile!
@ap = AwesomePrint::Inspector.new :plain => true, :sort_keys => true @ap = AwesomePrint::Inspector.new :plain => true, :sort_keys => true
end end

View file

@ -26,7 +26,6 @@ RSpec.describe "AwesomePrint/NoBrainer", skip: ->{ !ExtVerifier.has_nobrainer? }
end end
before do before do
stub_dotfile!
@ap = AwesomePrint::Inspector.new :plain => true @ap = AwesomePrint::Inspector.new :plain => true
end end

View file

@ -1,10 +1,6 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe "AwesomePrint/Nokogiri" do RSpec.describe "AwesomePrint/Nokogiri" do
before do
stub_dotfile!
end
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

View file

@ -2,7 +2,6 @@ require 'spec_helper'
RSpec.describe 'AwesomePrint Ostruct extension' do RSpec.describe 'AwesomePrint Ostruct extension' do
before do before do
stub_dotfile!
@ap = AwesomePrint::Inspector.new(:plain => true, :sort_keys => true) @ap = AwesomePrint::Inspector.new(:plain => true, :sort_keys => true)
end end

View file

@ -20,7 +20,6 @@ RSpec.describe 'AwesomePrint/Ripple', skip: ->{ !ExtVerifier.has_ripple? }.call
end end
before do before do
stub_dotfile!
@ap = AwesomePrint::Inspector.new :plain => true, :sort_keys => true @ap = AwesomePrint::Inspector.new :plain => true, :sort_keys => true
end end

View file

@ -4,10 +4,6 @@ require "rational"
require "set" require "set"
RSpec.describe "AwesomePrint" do RSpec.describe "AwesomePrint" do
before do
stub_dotfile!
end
describe "Array" do describe "Array" do
before do before do
@arr = [ 1, :two, "three", [ nil, [ true, false] ] ] @arr = [ 1, :two, "three", [ nil, [ true, false] ] ]

View file

@ -1,10 +1,6 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe "Single method" do RSpec.describe "Single method" do
before do
stub_dotfile!
end
after do after do
Object.instance_eval{ remove_const :Hello } if defined?(Hello) Object.instance_eval{ remove_const :Hello } if defined?(Hello)
end end
@ -81,10 +77,6 @@ RSpec.describe "Single method" do
end end
RSpec.describe "Object methods" do RSpec.describe "Object methods" do
before do
stub_dotfile!
end
after do after do
Object.instance_eval{ remove_const :Hello } if defined?(Hello) Object.instance_eval{ remove_const :Hello } if defined?(Hello)
end end
@ -203,10 +195,6 @@ RSpec.describe "Object methods" do
end end
RSpec.describe "Class methods" do RSpec.describe "Class methods" do
before do
stub_dotfile!
end
after do after do
Object.instance_eval{ remove_const :Hello } if defined?(Hello) Object.instance_eval{ remove_const :Hello } if defined?(Hello)
end end

View file

@ -3,10 +3,6 @@ require 'spec_helper'
RSpec.describe "AwesomePrint" do RSpec.describe "AwesomePrint" do
describe "Misc" do describe "Misc" do
before do
stub_dotfile!
end
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
@ -80,10 +76,6 @@ RSpec.describe "AwesomePrint" do
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
describe "HTML output" do describe "HTML output" do
before do
stub_dotfile!
end
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>")
@ -129,10 +121,6 @@ RSpec.describe "AwesomePrint" do
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
describe "AwesomePrint.defaults" do describe "AwesomePrint.defaults" do
before do
stub_dotfile!
end
after do after do
AwesomePrint.defaults = nil AwesomePrint.defaults = nil
end end
@ -154,10 +142,6 @@ RSpec.describe "AwesomePrint" do
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
describe "Coexistence with the colorize gem" do describe "Coexistence with the colorize gem" do
before do
stub_dotfile!
end
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)

View file

@ -1,10 +1,6 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe "Objects" do RSpec.describe "Objects" do
before do
stub_dotfile!
end
after do after do
Object.instance_eval{ remove_const :Hello } if defined?(Hello) Object.instance_eval{ remove_const :Hello } if defined?(Hello)
end end

View file

@ -53,6 +53,11 @@ RSpec.configure do |config|
end end
config.default_formatter = 'doc' if config.files_to_run.one? 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
end end
@ -80,9 +85,9 @@ def normalize_object_id_strings(str, options)
end end
def stub_dotfile! def stub_dotfile!
dotfile = File.join(ENV['HOME'], '.aprc') allow_any_instance_of(AwesomePrint::Inspector)
allow(File).to receive(:readable?).and_call_original .to receive(:load_dotfile)
expect(File).to receive(:readable?).at_least(:once).with(dotfile).and_return(false) .and_return(true)
end end
def capture! def capture!