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:
parent
8aef1bde91
commit
f628193028
14 changed files with 10 additions and 62 deletions
|
@ -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!
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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!
|
||||
|
|
Loading…
Reference in a new issue