Class: Expectations::Suite

Inherits:
Object show all
Includes:
Mocha::Standalone
Defined in:
lib/expectations/suite.rb

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSuite

Returns a new instance of Suite.



8
9
10
# File 'lib/expectations/suite.rb', line 8

def initialize
  @do_not_run = false
end

Class Attribute Details

.silentObject

Returns the value of attribute silent.



5
6
7
# File 'lib/expectations/suite.rb', line 5

def silent
  @silent
end

Instance Method Details

#do_not_runObject



30
31
32
# File 'lib/expectations/suite.rb', line 30

def do_not_run
  @do_not_run = true
end

#execute(out = STDOUT, suite_result = Expectations::SuiteResults.new(out)) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/expectations/suite.rb', line 16

def execute(out=STDOUT, suite_result = Expectations::SuiteResults.new(out))
  return suite_result if @do_not_run
  benchmark = Benchmark.measure do
    expectations_for(ENV["LINE"]).each { |expectation| suite_result << expectation.execute }
  end
  suite_result.print_results(benchmark)
  suite_result.write_junit_xml(ENV["JUnitXmlPath"]) unless ENV["JUnitXmlPath"].nil?
  suite_result
end

#expect(expected, &block) ⇒ Object



26
27
28
# File 'lib/expectations/suite.rb', line 26

def expect(expected, &block)
  expectations << Expectations::Expectation.new(expected, *caller.first.match(/\A(.+):(\d+)\Z/)[1..2], &block)
end

#expectationsObject



39
40
41
# File 'lib/expectations/suite.rb', line 39

def expectations
  @expectations ||= []
end

#expectations_for(line) ⇒ Object



34
35
36
37
# File 'lib/expectations/suite.rb', line 34

def expectations_for(line)
  return expectations if line.nil?
  [expectations.inject { |result, expectation| expectation.line > line.to_i ? result : expectation }]
end

#xml(string) ⇒ Object



12
13
14
# File 'lib/expectations/suite.rb', line 12

def xml(string)
  Expectations::XmlString.new(string)
end