Move some testing code into spec/helpers/

This commit is contained in:
Ryan Fitzgerald 2012-12-08 17:08:16 -08:00
parent f0c61ac418
commit 038bdf8a91
4 changed files with 50 additions and 54 deletions

View File

@ -185,7 +185,3 @@ class PryTester
@pry.output = @out
end
end
if defined?(Bacon)
require File.join(File.expand_path(File.dirname(__FILE__)), 'bacon_helper')
end

View File

@ -3,7 +3,12 @@ unless Object.const_defined? 'Pry'
require 'pry'
end
require File.expand_path('../../lib/pry/test/helper', __FILE__)
require 'mocha/api'
require 'pry/test/helper'
require File.expand_path('../helpers/bacon', __FILE__)
require File.expand_path('../helpers/mock_pry', __FILE__)
class Module
public :remove_const
@ -14,57 +19,11 @@ end
# in tests)
$VERBOSE = nil
# Set I/O streams.
#
# Out defaults to an anonymous StringIO.
def redirect_pry_io(new_in, new_out = StringIO.new)
old_in = Pry.input
old_out = Pry.output
Pry.input = new_in
Pry.output = new_out
begin
yield
ensure
Pry.input = old_in
Pry.output = old_out
end
end
def mock_pry(*args)
args.flatten!
binding = args.first.is_a?(Binding) ? args.shift : binding()
input = InputTester.new(*args)
output = StringIO.new
redirect_pry_io(input, output) do
binding.pry
end
output.string
end
Pad = OpenStruct.new
def Pad.clear
@table = {}
end
class InputTester
def initialize(*actions)
@orig_actions = actions.dup
@actions = actions
end
def readline(*)
@actions.shift
end
def rewind
@actions = @orig_actions.dup
end
end
# to help with tracking down bugs that cause an infinite loop in the test suite
if ENV["SET_TRACE_FUNC"]
require 'set_trace' if Pry::Helpers::BaseHelpers.rbx?

View File

@ -43,7 +43,7 @@ module Bacon
end
end
# Reset toplevel binding at the beginning of each test case.
# Reset top-level binding at the beginning of each test case.
module Bacon
class Context
def it_with_reset_binding(description, &block)
@ -57,8 +57,6 @@ end
# Support mocha
# mocha-on-bacon (c) Copyright (C) 2011, Eloy Durán <eloy.de.enige@gmail.com>
require 'mocha/api'
module Bacon
module MochaRequirementsCounter
def self.increment

43
spec/helpers/mock_pry.rb Normal file
View File

@ -0,0 +1,43 @@
def mock_pry(*args)
args.flatten!
binding = args.first.is_a?(Binding) ? args.shift : binding()
input = InputTester.new(*args)
output = StringIO.new
redirect_pry_io(input, output) do
binding.pry
end
output.string
end
# Set I/O streams. Out defaults to an anonymous StringIO.
def redirect_pry_io(new_in, new_out = StringIO.new)
old_in = Pry.input
old_out = Pry.output
Pry.input = new_in
Pry.output = new_out
begin
yield
ensure
Pry.input = old_in
Pry.output = old_out
end
end
class InputTester
def initialize(*actions)
@orig_actions = actions.dup
@actions = actions
end
def readline(*)
@actions.shift
end
def rewind
@actions = @orig_actions.dup
end
end