1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

moved test helper.rb to lib/pry/test/helper.rb, so plugins can use our test helpers

This commit is contained in:
John Mair 2012-11-28 01:26:28 +01:00
parent e5ad6fc561
commit d1489a59a3
3 changed files with 54 additions and 56 deletions

View file

@ -49,7 +49,7 @@ task :test do
check_dependencies unless ENV['SKIP_DEP_CHECK'] check_dependencies unless ENV['SKIP_DEP_CHECK']
all_specs = Dir['spec/**/*_spec.rb'] all_specs = Dir['spec/**/*_spec.rb']
all_specs.shuffle! if all_specs.respond_to? :shuffle! all_specs.shuffle! if all_specs.respond_to? :shuffle!
sh "bacon -Ispec -rubygems -a -q #{all_specs.join ' '}" system "bacon -Ilib/pry/test -Ispec -rubygems -a -q #{all_specs.join ' '}"
end end
task :spec => :test task :spec => :test

View file

@ -0,0 +1,51 @@
# Colorize output (based on greeneggs (c) 2009 Michael Fleet)
# TODO: Make own gem (assigned to rking)
module Bacon
COLORS = {'F' => 31, 'E' => 35, 'M' => 33, '.' => 32}
USE_COLOR = !(ENV['NO_PRY_COLORED_BACON'] == 'true') && Pry::Helpers::BaseHelpers.use_ansi_codes?
module TestUnitOutput
def handle_requirement(description)
error = yield
if error.empty?
print colorize_string('.')
else
print colorize_string(error[0..0])
end
end
def handle_summary
puts
puts ErrorLog if Backtraces
out = "%d tests, %d assertions, %d failures, %d errors" %
Counter.values_at(:specifications, :requirements, :failed, :errors)
if Counter.values_at(:failed, :errors).inject(:+) > 0
puts colorize_string(out, 'F')
else
puts colorize_string(out, '.')
end
end
def colorize_string(text, color = nil)
if USE_COLOR
"\e[#{ COLORS[color || text] }m#{ text }\e[0m"
else
text
end
end
end
end
# Reset toplevel binding at the beginning of each test case.
module Bacon
class Context
alias _real_it it
def it(description, &block)
Pry.toplevel_binding = nil
_real_it(description, &block)
end
end
end

View file

@ -1,64 +1,11 @@
unless Object.const_defined? 'Pry' unless Object.const_defined? 'Pry'
$:.unshift File.expand_path '../../lib', __FILE__ $:.unshift File.expand_path '../../../../lib', __FILE__
require 'pry' require 'pry'
end end
puts "Ruby v#{RUBY_VERSION} (#{defined?(RUBY_ENGINE) ? RUBY_ENGINE : "ruby"}), Pry v#{Pry::VERSION}, method_source v#{MethodSource::VERSION}, CodeRay v#{CodeRay::VERSION}, Slop v#{Slop::VERSION}" puts "Ruby v#{RUBY_VERSION} (#{defined?(RUBY_ENGINE) ? RUBY_ENGINE : "ruby"}), Pry v#{Pry::VERSION}, method_source v#{MethodSource::VERSION}, CodeRay v#{CodeRay::VERSION}, Slop v#{Slop::VERSION}"
require 'bacon' require File.join(File.expand_path(File.dirname(__FILE__)), 'bacon_helper') if defined?(Bacon)
require 'open4'
# Colorize output (based on greeneggs (c) 2009 Michael Fleet)
# TODO: Make own gem (assigned to rking)
module Bacon
COLORS = {'F' => 31, 'E' => 35, 'M' => 33, '.' => 32}
USE_COLOR = !(ENV['NO_PRY_COLORED_BACON'] == 'true') && Pry::Helpers::BaseHelpers.use_ansi_codes?
module TestUnitOutput
def handle_requirement(description)
error = yield
if error.empty?
print colorize_string('.')
else
print colorize_string(error[0..0])
end
end
def handle_summary
puts
puts ErrorLog if Backtraces
out = "%d tests, %d assertions, %d failures, %d errors" %
Counter.values_at(:specifications, :requirements, :failed, :errors)
if Counter.values_at(:failed, :errors).inject(:+) > 0
puts colorize_string(out, 'F')
else
puts colorize_string(out, '.')
end
end
def colorize_string(text, color = nil)
if USE_COLOR
"\e[#{ COLORS[color || text] }m#{ text }\e[0m"
else
text
end
end
end
end
# Reset toplevel binding at the beginning of each test case.
module Bacon
class Context
alias _real_it it
def it(description, &block)
Pry.toplevel_binding = nil
_real_it(description, &block)
end
end
end
# A global space for storing temporary state during tests. # A global space for storing temporary state during tests.
Pad = OpenStruct.new Pad = OpenStruct.new