Class: BrowserFormatter
  
  
  
  
    
      Instance Method Summary
      collapse
    
    
  
  Constructor Details
  
    
  
  
    Returns a new instance of BrowserFormatter
   
 
  
  
    
      
34
35
36
37
38
39
40
41 
     | 
    
      # File 'opal/lib/mspec/opal/runner.rb', line 34
def initialize(out=nil)
  @exception = @failure = false
  @exceptions = []
  @count = 0
  @examples = 0
  @current_state = nil
end 
     | 
  
 
  
 
  
    Instance Method Details
    
      
  
  
    #after(state = nil)  ⇒ Object 
  
  
  
  
    
      
87
88
89
90 
     | 
    
      # File 'opal/lib/mspec/opal/runner.rb', line 87
def after(state = nil)
  @current_state = nil
  @examples += 1
end 
     | 
  
 
    
      
  
  
    #before(state = nil)  ⇒ Object 
  
  
  
  
    
      
75
76
77
78 
     | 
    
      # File 'opal/lib/mspec/opal/runner.rb', line 75
def before(state=nil)
  @current_state = nil
  @failure = @exception = false
end 
     | 
  
 
    
      
  
  
    #enter(describe)  ⇒ Object 
  
  
  
  
    
      
73 
     | 
    
      # File 'opal/lib/mspec/opal/runner.rb', line 73
def enter(describe); end 
     | 
  
 
    
      
  
  
    #exception(exception)  ⇒ Object 
  
  
  
  
    
      
80
81
82
83
84
85 
     | 
    
      # File 'opal/lib/mspec/opal/runner.rb', line 80
def exception(exception)
  @count += 1
  @failure = @exception ? @failure && exception.failure? : exception.failure?
  @exception = true
  @exceptions << exception
end 
     | 
  
 
    
      
  
  
    #exception?  ⇒ Boolean 
  
  
  
  
    
      
65
66
67 
     | 
    
      # File 'opal/lib/mspec/opal/runner.rb', line 65
def exception?
  @exception
end 
     | 
  
 
    
      
  
  
    #failure?  ⇒ Boolean 
  
  
  
  
    
      
69
70
71 
     | 
    
      # File 'opal/lib/mspec/opal/runner.rb', line 69
def failure?
  @failure
end 
     | 
  
 
    
      
  
  
    
      
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118 
     | 
    
      # File 'opal/lib/mspec/opal/runner.rb', line 96
def finish
  time = Time.now.to_f - @start_time
  if @exceptions.empty?
    log "\nFinished"
    green "#{@examples} examples, #{@count} failures (time taken: #{time})"
    finish_with_code 0
  else
    log "\nFailures:"
    @exceptions.each_with_index do |exception, idx|
      log "\n  #{idx + 1}. #{exception.description}"
      red "\n    #{exception.message}"
      log "\n    #{`#{exception.exception}.stack`}\n"
    end
    log "\nFinished"
    red "#{@examples} examples, #{@count} failures (time taken: #{time})"
    finish_with_code(1)
  end
end
     | 
  
 
    
      
  
  
    #finish_with_code(code)  ⇒ Object 
  
  
  
  
    
      
120
121
122 
     | 
    
      # File 'opal/lib/mspec/opal/runner.rb', line 120
def finish_with_code(code)
  `window.OPAL_SPEC_CODE = code;`
end 
     | 
  
 
    
      
  
  
    #green(str)  ⇒ Object 
  
  
  
  
    
      
53
54
55 
     | 
    
      # File 'opal/lib/mspec/opal/runner.rb', line 53
def green(str)
  `console.info(str)`
end 
     | 
  
 
    
      
  
  
    
      
61
62
63 
     | 
    
      # File 'opal/lib/mspec/opal/runner.rb', line 61
def log(str)
  `console.log(str)`
end 
     | 
  
 
    
      
  
  
    
      
57
58
59 
     | 
    
      # File 'opal/lib/mspec/opal/runner.rb', line 57
def red(str)
  `console.error(str)`
end 
     | 
  
 
    
      
  
  
    
      
43
44
45
46
47
48
49
50
51 
     | 
    
      # File 'opal/lib/mspec/opal/runner.rb', line 43
def register
  MSpec.register :exception, self
  MSpec.register :before,    self
  MSpec.register :after,     self
  MSpec.register :start,     self
  MSpec.register :finish,    self
  MSpec.register :abort,     self
  MSpec.register :enter,     self
end 
     | 
  
 
    
      
  
  
    
      
92
93
94 
     | 
    
      # File 'opal/lib/mspec/opal/runner.rb', line 92
def start
  @start_time = Time.now.to_f
end 
     |