# File lib/shindo.rb, line 19 def initialize(description, tags = [], &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, tags, &block) end
# File lib/shindo.rb, line 41 def after(&block) @afters.last.push(block) end
# File lib/shindo.rb, line 45 def before(&block) @befores.last.push(block) end
# File lib/shindo.rb, line 49 def pending raise(Shindo::Pending.new) end
# File lib/shindo.rb, line 106 def raises(error, description = "raises #{error.inspect}", &block) assert(:raises, error, description, &block) end
# File lib/shindo.rb, line 110 def returns(expectation, description = "returns #{expectation.inspect}", &block) assert(:returns, expectation, description, &block) end
# File lib/shindo.rb, line 114 def test(description = 'returns true', &block) assert(:returns, true, description, &block) end
# File lib/shindo.rb, line 53 def tests(description, tags = [], &block) return self if Thread.main[:exit] || Thread.current[:reload] tags = [*tags] @tag_stack.push(tags) @befores.push([]) @afters.push([]) @description = nil @inline = false description ||= 'Shindo.tests' description = "[bold]#{description}[normal]" unless tags.empty? description << " (#{tags.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