Module: Declare

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

Defined Under Namespace

Modules: Assertions Classes: AssertionsScope, BasicScope, CallerEntry, ScopeSummary

Constant Summary collapse

VERSION =
'0.3.1'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.failuresObject (readonly)

Returns the value of attribute failures.



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

def failures
  @failures
end

Class Method Details

.auto_runObject



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

def auto_run
  at_exit do
    $! || report
  end
end

.declared!Object



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

def declared!
  @declare_counter += 1
end

.describe(&block) ⇒ Object



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

def describe(&block)
  BasicScope.new.instance_exec(&block)
end

.failure!(report) ⇒ Object



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

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

.failure_countObject



47
48
49
# File 'lib/declare/singleton_class.rb', line 47

def failure_count
  @failures.values.flatten.size
end

.new_scope(target, &block) ⇒ AssertionsScope

Returns:



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

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

.pass!Object



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

def pass!
  @pass_counter += 1
end

.reportObject



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/declare/singleton_class.rb', line 51

def report
  unless @failures.empty?
    report_detail
    puts '-' * 78
  end

  failure_count = failure_count()
  puts "#{@scope_summaries.length} scopes, #{@declare_counter} assertions, #{failure_count} failures"

  exit(failure_count)
end

.scope!(target, caller_entry) ⇒ Object



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

def scope!(target, caller_entry)
  @scope_summaries << ScopeSummary.new(target: target, caller_entry: caller_entry, nesting_level: caller_entry.block_level)
end