Class: JSTestSan::TestCase
- Inherits:
-
OSX::NSObject
- Object
- OSX::NSObject
- JSTestSan::TestCase
- Defined in:
- lib/js_test_san/test.rb,
lib/js_test_san/test_case.rb
Defined Under Namespace
Classes: FileDoesNotExistError, Test
Constant Summary collapse
- RESULTS_REGEXP =
/^((\d+) tests, )?(\d+) assertions, (\d+) failures, (\d+) errors\n?/- STATES =
%w{ passed failed error }
Instance Attribute Summary collapse
-
#assertions ⇒ Object
readonly
Returns the value of attribute assertions.
-
#delegate ⇒ Object
readonly
Returns the value of attribute delegate.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#failures ⇒ Object
readonly
Returns the value of attribute failures.
-
#html_file ⇒ Object
readonly
Returns the value of attribute html_file.
-
#tests ⇒ Object
readonly
Returns the value of attribute tests.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Class Method Summary collapse
Instance Method Summary collapse
- #document ⇒ Object
- #finished? ⇒ Boolean
- #handleEvent(event) ⇒ Object
- #initWithHTMLFile_delegate(html_file, delegate) ⇒ Object
- #log ⇒ Object
- #loglines ⇒ Object
- #run ⇒ Object
- #webView ⇒ Object
-
#webView_didFinishLoadForFrame(_, __) ⇒ Object
Not yet sure why the extra check for log not being nil is necessary.
Instance Attribute Details
#assertions ⇒ Object (readonly)
Returns the value of attribute assertions.
19 20 21 |
# File 'lib/js_test_san/test_case.rb', line 19 def assertions @assertions end |
#delegate ⇒ Object (readonly)
Returns the value of attribute delegate.
18 19 20 |
# File 'lib/js_test_san/test_case.rb', line 18 def delegate @delegate end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
19 20 21 |
# File 'lib/js_test_san/test_case.rb', line 19 def errors @errors end |
#failures ⇒ Object (readonly)
Returns the value of attribute failures.
19 20 21 |
# File 'lib/js_test_san/test_case.rb', line 19 def failures @failures end |
#html_file ⇒ Object (readonly)
Returns the value of attribute html_file.
18 19 20 |
# File 'lib/js_test_san/test_case.rb', line 18 def html_file @html_file end |
#tests ⇒ Object (readonly)
Returns the value of attribute tests.
19 20 21 |
# File 'lib/js_test_san/test_case.rb', line 19 def tests @tests end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
18 19 20 |
# File 'lib/js_test_san/test_case.rb', line 18 def title @title end |
Class Method Details
.sharedWebView ⇒ Object
10 11 12 |
# File 'lib/js_test_san/test_case.rb', line 10 def self.sharedWebView @sharedWebView ||= OSX::WebView.alloc.init end |
Instance Method Details
#document ⇒ Object
43 44 45 |
# File 'lib/js_test_san/test_case.rb', line 43 def document webView.mainFrame.DOMDocument end |
#finished? ⇒ Boolean
35 36 37 |
# File 'lib/js_test_san/test_case.rb', line 35 def finished? @finished end |
#handleEvent(event) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/js_test_san/test_case.rb', line 64 def handleEvent(event) element = event.target case element when OSX::DOMText finalize unless log.innerText == 'running...' else parent = element.parentNode state = parent.className if element == parent.lastChild && STATES.include?(state) output = parent.children.item(2).innerText.to_s return if output.empty? output.sub!(RESULTS_REGEXP, '') name = parent.children.item(0).innerText @delegate.test_ran(Test.new(self, name, state.to_sym, output)) end end end |
#initWithHTMLFile_delegate(html_file, delegate) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/js_test_san/test_case.rb', line 21 def initWithHTMLFile_delegate(html_file, delegate) if init raise FileDoesNotExistError, "The file `#{html_file}' does not exist." unless File.exist?(html_file) @html_file, @delegate = html_file, delegate @tests = @assertions = @failures = @errors = 0 @title = '' self end end |
#log ⇒ Object
47 48 49 |
# File 'lib/js_test_san/test_case.rb', line 47 def log document.getElementsByClassName('logsummary').item(0) end |
#loglines ⇒ Object
51 52 53 |
# File 'lib/js_test_san/test_case.rb', line 51 def loglines document.getElementsByClassName('loglines').item(0) end |
#run ⇒ Object
31 32 33 |
# File 'lib/js_test_san/test_case.rb', line 31 def run webView end |
#webView ⇒ Object
39 40 41 |
# File 'lib/js_test_san/test_case.rb', line 39 def webView @webView ||= load_webView end |
#webView_didFinishLoadForFrame(_, __) ⇒ Object
Not yet sure why the extra check for log not being nil is necessary. Might be a test only thing.
57 58 59 60 61 62 |
# File 'lib/js_test_san/test_case.rb', line 57 def webView_didFinishLoadForFrame(_, __) @title = webView.mainFrameTitle.to_s [log, loglines].each do |element| element.addEventListener___('DOMSubtreeModified', self, true) if element end end |