lib/dfect.rb in dfect-0.1.0 vs lib/dfect.rb in dfect-1.0.0
- old
+ new
@@ -10,12 +10,20 @@
# TypeError: can't dump anonymous class Class
#
# Work around this by representing a class by its name.
#
class Class #:nodoc: all
+ alias __to_yaml__ to_yaml
+ undef to_yaml
+
def to_yaml opts = {}
- name.to_yaml opts
+ begin
+ __to_yaml__
+ rescue TypeError => e
+ warn e
+ self.name.to_yaml opts
+ end
end
end
# load interactive debugger
begin
@@ -75,11 +83,11 @@
# [:debug]
# Launch an interactive debugger
# during assertion failures so
# the user can investigate them.
#
- # The default value is $DEBUG.
+ # The default value is true.
#
# [:quiet]
# Do not print the report
# after executing all tests.
#
@@ -217,11 +225,11 @@
# # message specified:
#
# T( "computers do not doublethink" ) { 2 + 2 != 5 } # passes
#
def T message = nil, &block
- assert_block :assert, message, &block
+ assert_yield :assert, message, &block
end
##
# Asserts that the result of the given block is
# either nil or false and returns that result.
@@ -243,11 +251,11 @@
# # message specified:
#
# T!( "computers do not doublethink" ) { 2 + 2 == 5 } # passes
#
def T! message = nil, &block
- assert_block :negate, message, &block
+ assert_yield :negate, message, &block
end
##
# Returns true if the result of the given block is
# neither nil nor false. Otherwise, returns false.
@@ -268,11 +276,11 @@
# # message specified:
#
# T?( "computers do not doublethink" ) { 2 + 2 != 5 } # => true
#
def T? message = nil, &block
- assert_block :sample, message, &block
+ assert_yield :sample, message, &block
end
alias F T!
alias F! T
@@ -517,20 +525,25 @@
end
##
# Executes all tests defined thus far and stores the results in #report.
#
- def run
+ # ==== Parameters
+ #
+ # [continue]
+ # If true, results from previous executions will not be cleared.
+ #
+ def run continue = true
# clear previous results
- @exec_stats.clear
- @exec_trace.clear
- @test_stack.clear
+ unless continue
+ @exec_stats.clear
+ @exec_trace.clear
+ @test_stack.clear
+ end
# make new results
- catch :stop_dfect_execution do
- execute
- end
+ catch(:stop_dfect_execution) { execute }
# print new results
puts @report.to_yaml unless @options[:quiet]
end
@@ -542,11 +555,11 @@
throw :stop_dfect_execution
end
private
- def assert_block mode, message = nil, &block
+ def assert_yield mode, message = nil, &block
raise ArgumentError, 'block must be given' unless block
message ||=
case mode
when :assert then 'block must yield true (!nil && !false)'
@@ -884,10 +897,10 @@
end
#:startdoc:
end
- @options = {:debug => $DEBUG, :quiet => false}
+ @options = {:debug => true, :quiet => false}
@exec_stats = Hash.new {|h,k| h[k] = 0 }
@exec_trace = []
@report = {:execution => @exec_trace, :statistics => @exec_stats}.freeze