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

Improves spec runner harness, switches to better env detection.

Does not run rails specs when running mongoid specs

WIP Start of remove BRE to check tests

Remove old helper of active record

Use RSpec skip to skip AR specs

Run ActionView only when needed

Run ActiveSupport only when needed

Run Mongoid only when needed

Create ExtVerifier.require_dependencies

Run MongoMapper only when needed

Always load nokogiri specs

Always load ostruct specs

Run Ripple only when needed

Remove :: when check for defined constants

Require spec_helper directly

Remove 1.8.6 old monkey patch

Add some RSpec configs
This commit is contained in:
Mauro George 2014-12-31 18:59:32 -02:00 committed by James Cox
parent 69815f01b2
commit 526f907629
24 changed files with 490 additions and 526 deletions

View file

@ -15,17 +15,14 @@ appraise 'rails-4.2' do
end
appraise 'mongoid-3.0' do
gem 'rails', '~> 3.2.0'
gem 'mongoid', '~> 3.0.0'
end
appraise 'mongoid-3.1' do
gem 'rails', '~> 3.2.0'
gem 'mongoid', '~> 3.1.0'
end
appraise 'mongoid-4.0' do
gem 'rails', '~> 4.2.0'
gem 'mongoid', '~> 4.0.0'
end

View file

@ -2,7 +2,6 @@
source "https://rubygems.org"
gem "rails", "~> 3.2.0"
gem "mongoid", "~> 3.0.0"
gemspec :path => "../"

View file

@ -2,7 +2,6 @@
source "https://rubygems.org"
gem "rails", "~> 3.2.0"
gem "mongoid", "~> 3.1.0"
gemspec :path => "../"

View file

@ -2,7 +2,6 @@
source "https://rubygems.org"
gem "rails", "~> 4.2.0"
gem "mongoid", "~> 4.0.0"
gemspec :path => "../"

View file

@ -1,5 +1,4 @@
require 'active_record'
if ExtVerifier.has_rails?
# Required to use the column support
module Rails
def self.env
@ -22,13 +21,4 @@ end
# Create models
class User < ActiveRecord::Base; end
class SubUser < User; end
# Helper methods
# ##############
# we only work with ActiveRecord 2+
def is_usable_activerecord?
defined?(ActiveRecord::VERSION::MAJOR) && ActiveRecord::VERSION::MAJOR >= 2
end

View file

@ -1,6 +1,6 @@
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
require 'spec_helper'
describe "AwesomePrint" do
RSpec.describe "AwesomePrint" do
def stub_tty!(output = true, stream = STDOUT)
if output
stream.instance_eval { def tty?; true; end }

View file

@ -1,10 +1,10 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require 'spec_helper'
require 'logger'
require 'awesome_print/core_ext/logger'
describe "AwesomePrint logging extensions" do
RSpec.describe "AwesomePrint logging extensions" do
before(:all) do
@logger = Logger.new('/dev/null') rescue Logger.new('nul')
end

View file

@ -1,6 +1,6 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require 'spec_helper'
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")

View file

@ -1,10 +1,7 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require 'spec_helper'
begin
require 'action_view'
require 'awesome_print/ext/action_view'
RSpec.describe "AwesomePrint ActionView extensions", skip: ->{ !ExtVerifier.has_rails? }.call do
describe "AwesomePrint ActionView extensions" do
before do
@view = ActionView::Base.new
end
@ -19,7 +16,3 @@ begin
expect(@view.ap(markup)).to eq('<pre class="debug_dump"><kbd style="color:brown">&quot; &amp;&lt;hello&gt;&quot;</kbd></pre>')
end
end
rescue LoadError => error
puts "Skipping ActionView specs: #{error}"
end

View file

@ -1,12 +1,8 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require 'spec_helper'
require 'active_record_helper'
begin
require 'awesome_print/ext/active_record'
require File.expand_path(File.dirname(__FILE__) + '/../active_record_helper')
RSpec.describe "AwesomePrint/ActiveRecord", skip: ->{ !ExtVerifier.has_rails? }.call do
if is_usable_activerecord?
describe "AwesomePrint/ActiveRecord" do
before do
stub_dotfile!
end
@ -1227,7 +1223,3 @@ EOS
end
end
end
end
rescue LoadError => error
puts "Skipping ActiveRecord specs: #{error}"
end

View file

@ -1,10 +1,6 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require 'spec_helper'
begin
require 'active_support/all'
require 'awesome_print/ext/active_support'
describe "AwesomePrint::ActiveSupport" do
RSpec.describe "AwesomePrint::ActiveSupport", skip: ->{ !ExtVerifier.has_rails? }.call do
before do
stub_dotfile!
@ap = AwesomePrint::Inspector.new
@ -29,7 +25,3 @@ begin
expect(date.ai).to eq("\e[0;32mMon, 26 May 2003\e[0m")
end
end
rescue LoadError => error
puts "Skipping ActiveSupport specs: #{error}"
end

View file

@ -1,10 +1,8 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require 'spec_helper'
begin
require "mongo_mapper"
require "awesome_print/ext/mongo_mapper"
RSpec.describe "AwesomePrint/MongoMapper", skip: ->{ !ExtVerifier.has_mongo_mapper? }.call do
describe "AwesomePrint/MongoMapper" do
if ExtVerifier.has_mongo_mapper?
before :all do
class MongoUser
include MongoMapper::Document
@ -18,6 +16,7 @@ begin
Object.instance_eval{ remove_const :MongoUser }
Object.instance_eval{ remove_const :Chamelion }
end
end
before do
stub_dotfile!
@ -157,6 +156,8 @@ EOS
end
describe "with associations" do
if ExtVerifier.has_mongo_mapper?
before :all do
class Child
include MongoMapper::EmbeddedDocument
@ -176,6 +177,7 @@ EOS
one :sibling
end
end
end
describe "with show associations turned off (default)" do
it "should render the class as normal" do
@ -266,7 +268,3 @@ EOS
end
end
end
rescue LoadError => error
puts "Skipping MongoMapper specs: #{error}"
end

View file

@ -1,10 +1,8 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require 'spec_helper'
begin
require "mongoid"
require "awesome_print/ext/mongoid"
RSpec.describe "AwesomePrint/Mongoid", skip: ->{ !ExtVerifier.has_mongoid? }.call do
describe "AwesomePrint/Mongoid" do
if ExtVerifier.has_mongoid?
before :all do
class MongoUser
include Mongoid::Document
@ -18,6 +16,7 @@ begin
Object.instance_eval{ remove_const :MongoUser }
Object.instance_eval{ remove_const :Chamelion }
end
end
before do
stub_dotfile!
@ -105,7 +104,3 @@ EOS
expect(@ap.send(:awesome, Chamelion)).to eq class_spec
end
end
rescue LoadError => error
puts "Skipping Mongoid specs: #{error}"
end

View file

@ -1,10 +1,6 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require 'spec_helper'
begin
require "nokogiri"
require "awesome_print/ext/nokogiri"
describe "AwesomePrint/Nokogiri" do
RSpec.describe "AwesomePrint/Nokogiri" do
before do
stub_dotfile!
end
@ -47,7 +43,3 @@ EOS
EOS
end
end
rescue LoadError => error
puts "Skipping Nokogiri specs: #{error}"
end

View file

@ -1,10 +1,6 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require 'spec_helper'
begin
require 'ostruct'
require 'awesome_print/ext/ostruct'
describe 'AwesomePrint Ostruct extension' do
RSpec.describe 'AwesomePrint Ostruct extension' do
before do
stub_dotfile!
@ap = AwesomePrint::Inspector.new(:plain => true, :sort_keys => true)
@ -25,7 +21,3 @@ OpenStruct {
EOS
end
end
rescue LoadError => error
puts "Skipping OpenStruct specs: #{error}"
end

View file

@ -1,10 +1,8 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require 'spec_helper'
begin
require 'ripple'
require 'awesome_print/ext/ripple'
RSpec.describe 'AwesomePrint/Ripple', skip: ->{ !ExtVerifier.has_ripple? }.call do
describe 'AwesomePrint/Ripple' do
if ExtVerifier.has_ripple?
before :all do
class RippleUser
include Ripple::Document
@ -19,6 +17,7 @@ begin
after :all do
Object.instance_eval { remove_const :RippleUser }
end
end
before do
stub_dotfile!
@ -48,7 +47,3 @@ class RippleUser < Object {
EOS
end
end
rescue LoadError => error
puts "Skipping Ripple specs: #{error}"
end

View file

@ -1,9 +1,9 @@
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
require 'spec_helper'
require "bigdecimal"
require "rational"
require "set"
describe "AwesomePrint" do
RSpec.describe "AwesomePrint" do
before do
stub_dotfile!
end

View file

@ -1,6 +1,6 @@
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
require 'spec_helper'
describe "Single method" do
RSpec.describe "Single method" do
before do
stub_dotfile!
end
@ -80,7 +80,7 @@ describe "Single method" do
end
end
describe "Object methods" do
RSpec.describe "Object methods" do
before do
stub_dotfile!
end
@ -202,7 +202,7 @@ describe "Object methods" do
end
end
describe "Class methods" do
RSpec.describe "Class methods" do
before do
stub_dotfile!
end
@ -313,7 +313,7 @@ describe "Class methods" do
end
if RUBY_VERSION >= '1.9.2'
describe "Ruby 1.9.2+ Method#parameters" do
RSpec.describe "Ruby 1.9.2+ Method#parameters" do
before do
stub_dotfile!
end
@ -364,7 +364,7 @@ if RUBY_VERSION >= '1.9.2'
end
end
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)

View file

@ -1,6 +1,6 @@
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
require 'spec_helper'
describe "AwesomePrint" do
RSpec.describe "AwesomePrint" do
describe "Misc" do
before do

View file

@ -1,6 +1,6 @@
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
require 'spec_helper'
describe "Objects" do
RSpec.describe "Objects" do
before do
stub_dotfile!
end

View file

@ -16,12 +16,35 @@
#
$LOAD_PATH.unshift(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'awesome_print'
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})
require 'nokogiri'
require 'awesome_print'
RSpec.configure do |config|
config.disable_monkey_patching!
# TODO: Make specs not order dependent
# config.order = :random
Kernel.srand config.seed
config.filter_run focus: true
config.run_all_when_everything_filtered = true
config.expect_with :rspec do |expectations|
expectations.syntax = :expect
end
config.mock_with :rspec do |mocks|
mocks.syntax = :expect
mocks.verify_partial_doubles = true
end
if config.files_to_run.one?
config.default_formatter = 'doc'
end
end
def stub_dotfile!
dotfile = File.join(ENV["HOME"], ".aprc")
expect(File).to receive(:readable?).at_least(:once).with(dotfile).and_return(false)
@ -33,36 +56,3 @@ def capture!
ensure
$stdout = standard
end
# The following is needed for the Infinity Test. It runs tests as subprocesses,
# which sets STDOUT.tty? to false and would otherwise prematurely disallow colors.
### AwesomePrint.force_colors!
# Ruby 1.8.6 only: define missing String methods that are needed for the specs to pass.
if RUBY_VERSION < '1.8.7'
class String
def shellescape # Taken from Ruby 1.9.2 standard library, see lib/shellwords.rb.
return "''" if self.empty?
str = self.dup
str.gsub!(/([^A-Za-z0-9_\-.,:\/@\n])/n, "\\\\\\1")
str.gsub!(/\n/, "'\n'")
str
end
def start_with?(*prefixes)
prefixes.each do |prefix|
prefix = prefix.to_s
return true if prefix == self[0, prefix.size]
end
false
end
def end_with?(*suffixes)
suffixes.each do |suffix|
suffix = suffix.to_s
return true if suffix == self[-suffix.size, suffix.size]
end
false
end
end
end

View file

@ -1,26 +0,0 @@
module ActiveRecordVersions
def activerecord_version
Gem::Version.new(ActiveRecord::VERSION::STRING)
end
def activerecord_4_2?
Gem::Requirement.new('~> 4.2.0').satisfied_by?(activerecord_version)
end
def activerecord_4_1?
Gem::Requirement.new('~> 4.1.0').satisfied_by?(activerecord_version)
end
def activerecord_4_0?
Gem::Requirement.new('~> 4.0.0').satisfied_by?(activerecord_version)
end
def activerecord_3_2?
Gem::Requirement.new('~> 3.2.0').satisfied_by?(activerecord_version)
end
end
RSpec.configure do |config|
config.include(ActiveRecordVersions)
config.extend(ActiveRecordVersions)
end

View file

@ -0,0 +1,37 @@
module ExtVerifier
def require_dependencies!(dependencies)
dependencies.each do |dependency|
begin
require dependency
rescue LoadError
end
end
end
module_function :require_dependencies!
def has_rails?
defined?(Rails)
end
module_function :has_rails?
def has_mongoid?
defined?(Mongoid)
end
module_function :has_mongoid?
def has_mongo_mapper?
defined?(MongoMapper)
end
module_function :has_mongo_mapper?
def has_ripple?
defined?(Ripple)
end
module_function :has_ripple?
end
RSpec.configure do |config|
config.include(ExtVerifier)
config.extend(ExtVerifier)
end

View file

@ -0,0 +1,30 @@
module RailsVersions
def rails_version
Gem::Version.new(Rails::VERSION::STRING)
end
def rails_4_2?
Gem::Requirement.new('~> 4.2.0').satisfied_by?(rails_version)
end
alias_method :activerecord_4_2?, :rails_4_2?
def rails_4_1?
Gem::Requirement.new('~> 4.1.0').satisfied_by?(rails_version)
end
alias_method :activerecord_4_1?, :rails_4_1?
def rails_4_0?
Gem::Requirement.new('~> 4.0.0').satisfied_by?(rails_version)
end
alias_method :activerecord_4_0?, :rails_4_0?
def rails_3_2?
Gem::Requirement.new('~> 3.2.0').satisfied_by?(rails_version)
end
alias_method :activerecord_3_2?, :rails_3_2?
end
RSpec.configure do |config|
config.include(RailsVersions)
config.extend(RailsVersions)
end