Class: JavascriptFeatures::TestCase
- Inherits:
-
ActiveSupport::TestCase
- Object
- ActiveSupport::TestCase
- JavascriptFeatures::TestCase
show all
- Extended by:
- Helper
- Defined in:
- lib/javascript_features/test_case.rb,
lib/javascript_features/test_case/servlet.rb
Defined Under Namespace
Classes: Servlet
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Helper
include_javascript_features, included, javascript_feature_classes, use_javascript_for, use_javascript_for?
Class Method Details
.feature_names ⇒ Object
32
33
34
|
# File 'lib/javascript_features/test_case.rb', line 32
def feature_names
@feature_names ||= [self.name.downcase.sub(/test$/, '')]
end
|
.feature_package ⇒ Object
24
25
26
|
# File 'lib/javascript_features/test_case.rb', line 24
def feature_package
@feature_package ||= 'main'
end
|
.request ⇒ Object
16
17
18
|
# File 'lib/javascript_features/test_case.rb', line 16
def request
nil
end
|
.server_pages ⇒ Object
40
41
42
|
# File 'lib/javascript_features/test_case.rb', line 40
def server_pages
@server_pages ||= {}
end
|
.stubs_http_request(url, options) ⇒ Object
36
37
38
|
# File 'lib/javascript_features/test_case.rb', line 36
def stubs_http_request(url, options)
@server_pages = server_pages.merge(url => options)
end
|
.tests_feature(*names) ⇒ Object
28
29
30
|
# File 'lib/javascript_features/test_case.rb', line 28
def tests_feature(*names)
@feature_names = names
end
|
.uses_feature_package(package) ⇒ Object
20
21
22
|
# File 'lib/javascript_features/test_case.rb', line 20
def uses_feature_package(package)
@feature_package = package
end
|
.uses_html(&block) ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/javascript_features/test_case.rb', line 44
def uses_html(&block)
define_method(:setup) do
self.class.feature_names.each{ |f| self.class.use_javascript_for f }
@html = yield.strip
server_config = {:BindAddress => '0.0.0.0', :Port => 8076, :AccessLog => [], :Logger => WEBrick::Log::new('/dev/null', 7)}
@server = ::WEBrick::HTTPServer.new(server_config)
pages = self.class.server_pages.merge(
'/index.html' => @html,
'/jquery.js' => File.read(File.expand_path('../../../assets/jquery.js', __FILE__))
)
@server.mount('/', JavascriptFeatures::TestCase::Servlet, pages)
Thread.new{ @server.start }
@page = Harmony::Page.fetch("http://#{server_config[:BindAddress]}:#{server_config[:Port]}/index.html")
Harmony::Page::Window::BASE_RUNTIME.wait
end
define_method(:teardown) do
@server.shutdown
end
end
|
.uses_html_body ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/javascript_features/test_case.rb', line 67
def uses_html_body
uses_html do
%%
<!DOCTYPE html>
<html lang="en">
<head>
<title>Test page</title>
</head>
<body class="#{javascript_feature_classes}">
#{yield.strip}
<script src='/jquery.js'></script>
#{include_javascript_features(feature_package)}
</body>
</html>
%
end
end
|
Instance Method Details
#assert_selector_count(expected_count, selector) ⇒ Object
91
92
93
94
|
# File 'lib/javascript_features/test_case.rb', line 91
def assert_selector_count(expected_count, selector)
real_count = execute_js("jQuery(#{selector.to_json}).length")
assert_equal expected_count, real_count, "Expected #{expected_count} elements matching selector #{selector}, found #{real_count}"
end
|
#execute_js(*args) ⇒ Object
87
88
89
|
# File 'lib/javascript_features/test_case.rb', line 87
def execute_js(*args)
@page.execute_js(*args)
end
|