Class: OSpec::Runner

Inherits:
Object show all
Defined in:
lib/ospec/runner.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRunner

Returns a new instance of Runner.



35
36
37
38
39
40
41
# File 'lib/ospec/runner.rb', line 35

def initialize
  if Runner.in_phantom?
    @formatter = PhantomFormatter.new
  elsif Runner.in_browser?
    @formatter = BrowserFormatter.new
  end
end

Class Method Details

.autorunObject



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ospec/runner.rb', line 23

def self.autorun
  if in_browser?
    %x{
      setTimeout(function() {
        #{ Runner.new.run };
      }, 0);
    }
  else
    Runner.new.run
  end
end

.in_browser?Boolean

Returns:

  • (Boolean)


3
4
5
6
7
8
9
10
11
# File 'lib/ospec/runner.rb', line 3

def self.in_browser?
  %x{
    if (typeof(window) !== 'undefined' && typeof(document) !== 'undefined') {
      return true;
    }

    return false;
  }
end

.in_phantom?Boolean

Returns:

  • (Boolean)


13
14
15
16
17
18
19
20
21
# File 'lib/ospec/runner.rb', line 13

def self.in_phantom?
  %x{
    if (typeof(phantom) !== 'undefined' && phantom.exit) {
      return true;
    }

    return false;
  }
end

Instance Method Details

#example_failed(example) ⇒ Object



66
67
68
# File 'lib/ospec/runner.rb', line 66

def example_failed example
  @formatter.example_failed example
end

#example_group_finished(group) ⇒ Object



54
55
56
# File 'lib/ospec/runner.rb', line 54

def example_group_finished group
  @formatter.example_group_finished group
end

#example_group_started(group) ⇒ Object



50
51
52
# File 'lib/ospec/runner.rb', line 50

def example_group_started group
  @formatter.example_group_started group
end

#example_passed(example) ⇒ Object



62
63
64
# File 'lib/ospec/runner.rb', line 62

def example_passed example
  @formatter.example_passed example
end

#example_started(example) ⇒ Object



58
59
60
# File 'lib/ospec/runner.rb', line 58

def example_started example
  @formatter.example_started example
end

#runObject



43
44
45
46
47
48
# File 'lib/ospec/runner.rb', line 43

def run
  groups = ExampleGroup.example_groups
  @formatter.start
  groups.each { |group| group.run self }
  @formatter.finish
end