Class: Expectations::Suite

Inherits:
Object show all
Includes:
Mocha::API
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



32
33
34
# File 'lib/expectations/suite.rb', line 32

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
29
30
# File 'lib/expectations/suite.rb', line 26

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

#expectationsObject



41
42
43
# File 'lib/expectations/suite.rb', line 41

def expectations
  @expectations ||= []
end

#expectations_for(line) ⇒ Object



36
37
38
39
# File 'lib/expectations/suite.rb', line 36

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