Module: Declare

Defined in:
lib/declare/scope.rb,
lib/declare/errors.rb,
lib/declare/version.rb,
lib/declare/assertions.rb,
lib/declare/callerentry.rb,
lib/declare/singleton_class.rb,
lib/declare/object_extension.rb

Defined Under Namespace

Modules: Assertions, ObjectExtension Classes: CallerEntry, DupulicatedCategoryError, FrameworkError, Scope, ScopeSummary, UnhandledError

Constant Summary collapse

VERSION =
'0.0.6'.freeze

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.failuresObject (readonly)

Returns the value of attribute failures


14
15
16
# File 'lib/declare/singleton_class.rb', line 14

def failures
  @failures
end

Class Method Details

.auto_runObject


18
19
20
21
22
23
# File 'lib/declare/singleton_class.rb', line 18

def auto_run
  @auto_run = true
  at_exit do
    $! || report
  end
end

.auto_run?Boolean

Returns:

  • (Boolean)

25
26
27
# File 'lib/declare/singleton_class.rb', line 25

def auto_run?
  @auto_run
end

.declared!Object


37
38
39
# File 'lib/declare/singleton_class.rb', line 37

def declared!
  @declare_counter += 1
end

.failure!(report) ⇒ Object


49
50
51
52
# File 'lib/declare/singleton_class.rb', line 49

def failure!(report)
  @failures[@scope_summaries.last] ||= []
  @failures[@scope_summaries.last] << report
end

.new_scope(target, &block) ⇒ Object


33
34
35
# File 'lib/declare/singleton_class.rb', line 33

def new_scope(target, &block)
  Scope.new(target).instance_exec(target, &block)
end

.pass!Object


45
46
47
# File 'lib/declare/singleton_class.rb', line 45

def pass!
  @pass_counter += 1
end

.reportObject


54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/declare/singleton_class.rb', line 54

def report
  unless @failures.empty?
    report_detail
    puts '-' * 78
  end
  
  failure_count = @failures.values.flatten.length
  puts "#{@scope_summaries.length} scopes, #{@declare_counter} assertions, #{failure_count} failures"
  puts " Unexpected Failers: #{@unexpected_failures.inspect}" unless @unexpected_failures.empty?
  
  exit failure_count
end

.report_detailObject (private)


69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/declare/singleton_class.rb', line 69

def report_detail
  top_header = 'Detail testing report'
  puts top_header
  puts '=' * top_header.length, nil

  @failures.each_pair do |scope, lines|
    header = (
      case scope.nesting_level
      when 0
        obj_header = "#{scope.target.inspect} [#{scope.caller_entry.file_name}:#{scope.caller_entry.line_number}]"
        "#{obj_header}\n#{'-' * obj_header.length}"
      else
        "###{'#' * scope.nesting_level} #{scope.target.inspect} ###{'#' * scope.nesting_level} [#{scope.caller_entry.file_name}:#{scope.caller_entry.line_number}]"
      end
    )
    puts header, nil
    puts lines.map{|l|"* #{l}"}
  end
end

.scope!(target, caller_entry, description = nil) ⇒ Object


41
42
43
# File 'lib/declare/singleton_class.rb', line 41

def scope!(target, caller_entry, description=nil)
  @scope_summaries << ScopeSummary.new(target, description, caller_entry, caller_entry.block_level)
end

.unexpected_failure_in_the(scoped, exception, _caller) ⇒ Object


29
30
31
# File 'lib/declare/singleton_class.rb', line 29

def unexpected_failure_in_the(scoped, exception, _caller)
  @unexpected_failures[scoped] = [exception, _caller]
end