Class: Shindo::Tests
- Inherits:
-
Object
- Object
- Shindo::Tests
- Defined in:
- lib/shindo.rb,
lib/shindo/verbose.rb,
lib/shindo/taciturn.rb
Instance Method Summary collapse
- #after(&block) ⇒ Object
- #before(&block) ⇒ Object
-
#initialize(description, tags = [], &block) ⇒ Tests
constructor
A new instance of Tests.
- #pending ⇒ Object
- #raises(error, description = "raises #{error.inspect}", &block) ⇒ Object
- #returns(expectation, description = "returns #{expectation.inspect}", &block) ⇒ Object
- #test(description = 'returns true', &block) ⇒ Object
- #tests(description, tags = [], &block) ⇒ Object
Constructor Details
#initialize(description, tags = [], &block) ⇒ Tests
Returns a new instance of Tests.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/shindo.rb', line 18 def initialize(description, = [], &block) @afters = [] @befores = [] @description_stack = [] @tag_stack = [] Thread.current[:reload] = false Thread.current[:tags] ||= [] Thread.current[:totals] ||= { :failed => 0, :pending => 0, :skipped => 0, :succeeded => 0 } @if_tagged = [] @unless_tagged = [] for tag in Thread.current[:tags] case tag[0...1] when '+' @if_tagged << tag[1..-1] when '-' @unless_tagged << tag[1..-1] end end Formatador.display_line tests(description, , &block) end |
Instance Method Details
#after(&block) ⇒ Object
40 41 42 |
# File 'lib/shindo.rb', line 40 def after(&block) @afters.last.push(block) end |
#before(&block) ⇒ Object
44 45 46 |
# File 'lib/shindo.rb', line 44 def before(&block) @befores.last.push(block) end |
#pending ⇒ Object
48 49 50 |
# File 'lib/shindo.rb', line 48 def pending raise(Shindo::Pending.new) end |
#raises(error, description = "raises #{error.inspect}", &block) ⇒ Object
105 106 107 |
# File 'lib/shindo.rb', line 105 def raises(error, description = "raises #{error.inspect}", &block) assert(:raises, error, description, &block) end |
#returns(expectation, description = "returns #{expectation.inspect}", &block) ⇒ Object
109 110 111 |
# File 'lib/shindo.rb', line 109 def returns(expectation, description = "returns #{expectation.inspect}", &block) assert(:returns, expectation, description, &block) end |
#test(description = 'returns true', &block) ⇒ Object
113 114 115 |
# File 'lib/shindo.rb', line 113 def test(description = 'returns true', &block) assert(:returns, true, description, &block) end |
#tests(description, tags = [], &block) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/shindo.rb', line 52 def tests(description, = [], &block) return self if Thread.main[:exit] || Thread.current[:reload] = [*].collect { |tag| tag.to_s } @tag_stack.push() @befores.push([]) @afters.push([]) @description = nil @inline = false description ||= 'Shindo.tests' description = "[bold]#{description}[normal]" unless .empty? description << " (#{.join(', ')})" end @description_stack.push(description) # if the test includes +tags and discludes -tags, evaluate it if (@if_tagged.empty? || !(@if_tagged & @tag_stack.flatten).empty?) && (@unless_tagged.empty? || (@unless_tagged & @tag_stack.flatten).empty?) if block_given? begin display_description(description) # HACK: increase indent indent = Thread.current[:formatador].instance_variable_get(:@indent) Thread.current[:formatador].instance_variable_set(:@indent, indent + 1) instance_eval(&block) rescue Shindo::Pending display_pending(description) rescue => error display_error(error) ensure # HACK: decrease indent indent = Thread.current[:formatador].instance_variable_get(:@indent) Thread.current[:formatador].instance_variable_set(:@indent, indent - 1) end else @inline = true display_description(description) end else display_description("[light_black]#{description}[/]") end @description_stack.pop @afters.pop @befores.pop @tag_stack.pop Thread.exit if Thread.main[:exit] || Thread.current[:reload] self end |