diff --git a/spec/colors_spec.rb b/spec/colors_spec.rb index 16d859b..bca11cb 100644 --- a/spec/colors_spec.rb +++ b/spec/colors_spec.rb @@ -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 ] ] ]" @@ -67,7 +63,7 @@ RSpec.describe "AwesomePrint" do before do AwesomePrint.force_colors! end - + it "still colorizes tty processes" do stub_tty! expect(@arr.ai(:multiline => false)).to eq(COLORIZED) @@ -82,7 +78,7 @@ RSpec.describe "AwesomePrint" do ENV['ANSICON'] = term end end - + it "colorizes dumb terminals" do begin stub_tty! diff --git a/spec/ext/active_record_spec.rb b/spec/ext/active_record_spec.rb index 958aad7..eff9d67 100644 --- a/spec/ext/active_record_spec.rb +++ b/spec/ext/active_record_spec.rb @@ -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 diff --git a/spec/ext/active_support_spec.rb b/spec/ext/active_support_spec.rb index f6f3ad7..f2eb7af 100644 --- a/spec/ext/active_support_spec.rb +++ b/spec/ext/active_support_spec.rb @@ -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 diff --git a/spec/ext/mongo_mapper_spec.rb b/spec/ext/mongo_mapper_spec.rb index 4608610..690b757 100644 --- a/spec/ext/mongo_mapper_spec.rb +++ b/spec/ext/mongo_mapper_spec.rb @@ -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 diff --git a/spec/ext/mongoid_spec.rb b/spec/ext/mongoid_spec.rb index 97fbf05..75fab5a 100644 --- a/spec/ext/mongoid_spec.rb +++ b/spec/ext/mongoid_spec.rb @@ -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 diff --git a/spec/ext/nobrainer_spec.rb b/spec/ext/nobrainer_spec.rb index a6a6ddd..b9d4b41 100644 --- a/spec/ext/nobrainer_spec.rb +++ b/spec/ext/nobrainer_spec.rb @@ -26,7 +26,6 @@ RSpec.describe "AwesomePrint/NoBrainer", skip: ->{ !ExtVerifier.has_nobrainer? } end before do - stub_dotfile! @ap = AwesomePrint::Inspector.new :plain => true end diff --git a/spec/ext/nokogiri_spec.rb b/spec/ext/nokogiri_spec.rb index 466059b..47c1263 100644 --- a/spec/ext/nokogiri_spec.rb +++ b/spec/ext/nokogiri_spec.rb @@ -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('

') expect(xml.ai).to eq <<-EOS diff --git a/spec/ext/ostruct_spec.rb b/spec/ext/ostruct_spec.rb index d58c2fe..6fe4c6a 100644 --- a/spec/ext/ostruct_spec.rb +++ b/spec/ext/ostruct_spec.rb @@ -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 diff --git a/spec/ext/ripple_spec.rb b/spec/ext/ripple_spec.rb index 9c35372..7d5623a 100644 --- a/spec/ext/ripple_spec.rb +++ b/spec/ext/ripple_spec.rb @@ -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 diff --git a/spec/formats_spec.rb b/spec/formats_spec.rb index 5d6fde3..371363b 100644 --- a/spec/formats_spec.rb +++ b/spec/formats_spec.rb @@ -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] ] ] diff --git a/spec/methods_spec.rb b/spec/methods_spec.rb index f837a30..2297126 100644 --- a/spec/methods_spec.rb +++ b/spec/methods_spec.rb @@ -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 diff --git a/spec/misc_spec.rb b/spec/misc_spec.rb index 60f51c7..5b99dae 100644 --- a/spec/misc_spec.rb +++ b/spec/misc_spec.rb @@ -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
 tag" do
       markup = rand
       expect(markup.ai(:html => true, :plain => true)).to eq("
#{markup}
") @@ -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) diff --git a/spec/objects_spec.rb b/spec/objects_spec.rb index aa3f476..e9ede9c 100644 --- a/spec/objects_spec.rb +++ b/spec/objects_spec.rb @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index dbf086d..55cdb03 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -53,6 +53,11 @@ RSpec.configure do |config| end 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 @@ -80,9 +85,9 @@ 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!