Class: HeadlessSquirrel::TestCase
- Inherits:
-
OSX::NSObject
- Object
- OSX::NSObject
- HeadlessSquirrel::TestCase
- Defined in:
- lib/headless_squirrel/test.rb,
lib/headless_squirrel/test_case.rb
Defined Under Namespace
Classes: FileDoesNotExistError, Test
Constant Summary collapse
- RESULTS_REGEXP_KEYS =
[:report, :_, :tests, :assertions, :failures, :errors]
- 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_addMessageToConsole(_, info) ⇒ Object
Catches resource load errors:.
- #webView_didClearWindowObject_forFrame(_, scriptObject, __) ⇒ 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.
21 22 23 |
# File 'lib/headless_squirrel/test_case.rb', line 21 def assertions @assertions end |
#delegate ⇒ Object (readonly)
Returns the value of attribute delegate.
20 21 22 |
# File 'lib/headless_squirrel/test_case.rb', line 20 def delegate @delegate end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
21 22 23 |
# File 'lib/headless_squirrel/test_case.rb', line 21 def errors @errors end |
#failures ⇒ Object (readonly)
Returns the value of attribute failures.
21 22 23 |
# File 'lib/headless_squirrel/test_case.rb', line 21 def failures @failures end |
#html_file ⇒ Object (readonly)
Returns the value of attribute html_file.
20 21 22 |
# File 'lib/headless_squirrel/test_case.rb', line 20 def html_file @html_file end |
#tests ⇒ Object (readonly)
Returns the value of attribute tests.
21 22 23 |
# File 'lib/headless_squirrel/test_case.rb', line 21 def tests @tests end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
20 21 22 |
# File 'lib/headless_squirrel/test_case.rb', line 20 def title @title end |
Class Method Details
.sharedWebView ⇒ Object
11 12 13 |
# File 'lib/headless_squirrel/test_case.rb', line 11 def self.sharedWebView @sharedWebView ||= OSX::WebView.alloc.init end |
Instance Method Details
#document ⇒ Object
45 46 47 |
# File 'lib/headless_squirrel/test_case.rb', line 45 def document webView.mainFrame.DOMDocument end |
#finished? ⇒ Boolean
37 38 39 |
# File 'lib/headless_squirrel/test_case.rb', line 37 def finished? @finished end |
#handleEvent(event) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/headless_squirrel/test_case.rb', line 85 def handleEvent(event) element = event.target case element when OSX::DOMText contents = element.wholeText.to_s when OSX::DOMHTMLTableCellElement, OSX::DOMHTMLDivElement contents = element.innerText.to_s end if contents if result = self.class.parse_result(contents) if result[:tests] finalize_test_suite(result) else finalize_test(result) end end end end |
#initWithHTMLFile_delegate(html_file, delegate) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/headless_squirrel/test_case.rb', line 23 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
49 50 51 |
# File 'lib/headless_squirrel/test_case.rb', line 49 def log document.getElementsByClassName('logsummary').item(0) || document.getElementById('logsummary') end |
#loglines ⇒ Object
53 54 55 |
# File 'lib/headless_squirrel/test_case.rb', line 53 def loglines document.getElementsByClassName('loglines').item(0) || document.getElementById('loglines') end |
#run ⇒ Object
33 34 35 |
# File 'lib/headless_squirrel/test_case.rb', line 33 def run webView end |
#webView ⇒ Object
41 42 43 |
# File 'lib/headless_squirrel/test_case.rb', line 41 def webView @webView ||= load_webView end |
#webView_addMessageToConsole(_, info) ⇒ Object
Catches resource load errors:
webView.resourceLoadDelegate = self
def webView_resource_didFailLoadingWithError_fromDataSource(w,r,e,d)
= "#{e.userInfo['NSLocalizedDescription']}: #{e.userInfo['NSErrorFailingURLStringKey']}"
@delegate.test_ran(Test.new(self, "Unable to load test case", :failed, ))
@delegate.test_case_finished(self)
end
80 81 82 83 |
# File 'lib/headless_squirrel/test_case.rb', line 80 def webView_addMessageToConsole(_, info) puts format_js_log(info) OSX::NSApplication.sharedApplication.terminate(self) if info['message'].to_s =~ /^[A-Z]\w+Error/ end |
#webView_didClearWindowObject_forFrame(_, scriptObject, __) ⇒ Object
66 67 68 |
# File 'lib/headless_squirrel/test_case.rb', line 66 def webView_didClearWindowObject_forFrame(_, scriptObject, __) scriptObject.setValue_forKey(HeadlessSquirrel::Console.alloc.init, 'console') end |
#webView_didFinishLoadForFrame(_, __) ⇒ Object
Not yet sure why the extra check for log not being nil is necessary. Might be a test only thing.
59 60 61 62 63 64 |
# File 'lib/headless_squirrel/test_case.rb', line 59 def webView_didFinishLoadForFrame(_, __) @title = webView.mainFrameTitle.to_s [log, loglines].each do |element| element.addEventListener___('DOMSubtreeModified', self, true) if element end end |