Class: OSpecRunner
Class Method Summary collapse
Instance Method Summary collapse
- #after(state = nil) ⇒ Object
- #before(state = nil) ⇒ Object
- #bm!(repeat) ⇒ Object
- #did_finish ⇒ Object
-
#initialize(formatter_class) ⇒ OSpecRunner
constructor
A new instance of OSpecRunner.
- #register ⇒ Object
- #run ⇒ Object
- #will_start ⇒ Object
Constructor Details
#initialize(formatter_class) ⇒ OSpecRunner
Returns a new instance of OSpecRunner
209 210 211 212 213 |
# File 'opal/lib/mspec/opal/runner.rb', line 209 def initialize(formatter_class) @formatter_class = formatter_class register run end |
Class Method Details
.main(formatter_class = BrowserFormatter) ⇒ Object
205 206 207 |
# File 'opal/lib/mspec/opal/runner.rb', line 205 def self.main(formatter_class = BrowserFormatter) @main ||= self.new formatter_class end |
Instance Method Details
#after(state = nil) ⇒ Object
245 246 247 248 249 250 251 |
# File 'opal/lib/mspec/opal/runner.rb', line 245 def after(state = nil) %x{ if (self.bm) { self.bm[state.description].stopped = Date.now(); } } end |
#before(state = nil) ⇒ Object
237 238 239 240 241 242 243 |
# File 'opal/lib/mspec/opal/runner.rb', line 237 def before(state = nil) %x{ if (self.bm && !self.bm.hasOwnProperty(state.description)) { self.bm[state.description] = {started: Date.now()}; } } end |
#bm!(repeat) ⇒ Object
230 231 232 233 234 235 |
# File 'opal/lib/mspec/opal/runner.rb', line 230 def bm!(repeat) `self.bm = {}` MSpec.repeat = repeat; MSpec.register :before, self MSpec.register :after, self end |
#did_finish ⇒ Object
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 |
# File 'opal/lib/mspec/opal/runner.rb', line 253 def did_finish %x{ var obj = self.bm, key, val, json, file; if (obj) { for (key in obj) { if (obj.hasOwnProperty(key)) { val = obj[key]; obj[key] = val.stopped - val.started; } } json = JSON.stringify(obj, null, ' '); file = #{Time.now.strftime('tmp/bm_%Y-%m-%d_%H-%M-%S-%L.json')}; #{File.open(`file`, 'w') {|f| f.write(`json`)}} } } MSpec.actions :finish end |
#register ⇒ Object
215 216 217 218 219 220 |
# File 'opal/lib/mspec/opal/runner.rb', line 215 def register formatter = @formatter_class.new formatter.register OSpecFilter.main.register end |
#run ⇒ Object
222 223 224 |
# File 'opal/lib/mspec/opal/runner.rb', line 222 def run MSpec.opal_runner end |