tuev 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitmodules +6 -0
- data/.rvmrc +1 -0
- data/Gemfile +19 -0
- data/Gemfile.lock +32 -0
- data/LICENSE.txt +20 -0
- data/README.md +75 -0
- data/Rakefile +50 -0
- data/VERSION +1 -0
- data/bin/tuev +85 -0
- data/contrib/jquery-1.5.1.js +8316 -0
- data/contrib/mockjax/jquery.mockjax.js +382 -0
- data/contrib/qunit/qunit/qunit.css +215 -0
- data/contrib/qunit/qunit/qunit.js +1442 -0
- data/contrib/test_default.html +88 -0
- data/contrib/tuev.yml +37 -0
- data/contrib/tuev_helper.rb +70 -0
- data/contrib/tuev_qunit.js +23 -0
- data/lib/tasks/tuev.rake +112 -0
- data/lib/tuev/tuev.rb +116 -0
- data/lib/tuev/tuev_runner.rb +64 -0
- data/lib/tuev.rb +15 -0
- data/spec/fixtures/fake_root/config/tuev.yml +39 -0
- data/spec/fixtures/file_layout1.txt +13 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/tuev_spec.rb +7 -0
- data/tuev.gemspec +94 -0
- data/tuev_helper.rb +11 -0
- metadata +175 -0
@@ -0,0 +1,88 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
<link rel="stylesheet" href="<%= @qunit_css %>" type="text/css"/>
|
4
|
+
<title><%= @test_set_name %></title>
|
5
|
+
<!-- test dependencies: jquery, qunit, mockjax ... delete if they conflict
|
6
|
+
with your needs -->
|
7
|
+
<script type="text/javascript" src="<%= @jquery_js %>"></script>
|
8
|
+
<script type="text/javascript" src="<%= @qunit_js %>"></script>
|
9
|
+
<script type="text/javascript" src="<%= @mockjax_js %>"></script>
|
10
|
+
</head>
|
11
|
+
<body>
|
12
|
+
<h1 id="qunit-header"><%= @test_set_name %> tests</h1>
|
13
|
+
<h2 id="qunit-banner"></h2>
|
14
|
+
<h2 id="qunit-userAgent"></h2>
|
15
|
+
<ol id="qunit-tests">
|
16
|
+
</ol>
|
17
|
+
<div id="qunit-fixture"></div>
|
18
|
+
|
19
|
+
<script type="text/template" id="user-list-template">
|
20
|
+
<table id="whitelisted-users-list" class="list whitelisted-users">
|
21
|
+
<thead>
|
22
|
+
<tr>
|
23
|
+
<th>User</th>
|
24
|
+
<th>Whitelisted at</th>
|
25
|
+
<th>Whitelisted by</th>
|
26
|
+
<th>Note</th>
|
27
|
+
<th>Action</th></tr>
|
28
|
+
</thead>
|
29
|
+
</table>
|
30
|
+
</script>
|
31
|
+
|
32
|
+
<script type="text/template" id="list-item-template">
|
33
|
+
<tr class="pending-state-{{ pending }}">
|
34
|
+
<td>
|
35
|
+
<span>
|
36
|
+
<a href="http://soundcloud.com/{{ permalink }}" class="user">{{ username }}</a>
|
37
|
+
</span>
|
38
|
+
</td>
|
39
|
+
<td class="created-at">{{ created_at }}</td>
|
40
|
+
<td>
|
41
|
+
<a href="http://soundcloud.com/{{ whitelisted_by }}">
|
42
|
+
{{ whitelisted_by}}
|
43
|
+
</a>
|
44
|
+
</td>
|
45
|
+
<td>
|
46
|
+
<a class="cancel-edit-note" href="#/users/{{ APP.user.get('permalink') }}" title="{{ note }}">Cancel edit</a>
|
47
|
+
<a class="edit-note" href="#/users/{{ APP.user.get('permalink') }}/whitelist/{{ permalink }}/edit" title="{{ note }}">Edit note</a>
|
48
|
+
</td>
|
49
|
+
<td><img class="spinner" src="/images/spinner.gif"><button class="revoke">revoke</button></td>
|
50
|
+
</tr>
|
51
|
+
<tr class="whitelist-note-edit">
|
52
|
+
<td colspan="5">
|
53
|
+
<p>Notes:</p>
|
54
|
+
<form class="note" method="post">
|
55
|
+
<textarea name="note">{{ note }}</textarea>
|
56
|
+
<input type="submit" id="submit"><img class="spinner" src="/images/spinner.gif">
|
57
|
+
</form>
|
58
|
+
</td>
|
59
|
+
</tr>
|
60
|
+
</script>
|
61
|
+
|
62
|
+
<script type="text/template" id="search-result-item-template">
|
63
|
+
<div class="search-result-row">
|
64
|
+
<div class="checkbox"> <input type="checkbox" name="new-whitelist-users" value="{{ id }}"></div>
|
65
|
+
<div class="avatar"><img src="{{ avatar_url_badge }}"></div>
|
66
|
+
<div class="description">
|
67
|
+
<span class="user-info"><a href="{{ permalink }}" target="_blank" class="user">{{ username }}</a></span>
|
68
|
+
<span> ({{ city }} / {{ country }})</span>
|
69
|
+
</div>
|
70
|
+
</div>
|
71
|
+
</script>
|
72
|
+
|
73
|
+
|
74
|
+
<!-- dependencies -->
|
75
|
+
<% @dependencies.each do |dependency| %>
|
76
|
+
<script type="text/javascript" src="<%= dependency %>"></script>
|
77
|
+
<% end %>
|
78
|
+
|
79
|
+
<!-- tests -->
|
80
|
+
<% @test_set.each do |test| %>
|
81
|
+
<script type="text/javascript" src="<%= test %>"></script>
|
82
|
+
<% end %>
|
83
|
+
|
84
|
+
<!-- leave this at the bottom sir! -->
|
85
|
+
<script type="text/javascript" src="<%= @tuev_qunit_js %>"></script>
|
86
|
+
|
87
|
+
</body>
|
88
|
+
</html>
|
data/contrib/tuev.yml
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# basic selenium stuff
|
2
|
+
selenium:
|
3
|
+
host: 'localhost' # host which runs selenium server
|
4
|
+
port: '4444' # selenium server port (if you get connection refused, try 5555)
|
5
|
+
browsers:
|
6
|
+
- '*firefox' # should work on most systems
|
7
|
+
#- *googlechrome # ... can't get it to work on mac os x or linux
|
8
|
+
#- *safari # well: mac os x only
|
9
|
+
default_timeout_in_seconds: 15 # requests that take longer fail
|
10
|
+
|
11
|
+
# define test suite here ... it's basically a Dir.glob-pattern for all test files
|
12
|
+
# and dependencies needed by test files
|
13
|
+
# qunit will be included automatically ... don't bother
|
14
|
+
# If JS-Files need to be loaded in a special order, list them individually ... all
|
15
|
+
# paths are relative to the directory from where the test is called (root of your
|
16
|
+
# project usually)
|
17
|
+
test_suites:
|
18
|
+
-
|
19
|
+
name: 'qunit_tests'
|
20
|
+
|
21
|
+
# it should be there ... check it out, adjust it to your needs
|
22
|
+
test_file_template: 'tests/tuev/contrib/test_default.html'
|
23
|
+
combine_tests: false # whether to create one big test file or one pre js-test-file
|
24
|
+
test_files:
|
25
|
+
include: 'client/public/javascripts/tests/**/*.js' # Dir.glob-pattern
|
26
|
+
exclude: 'mocks.js'
|
27
|
+
dependencies:
|
28
|
+
include: # include in a specified order
|
29
|
+
- 'client/public/javascripts/vendor/underscore-1.1.4.js'
|
30
|
+
- 'client/public/javascripts/vendor/backbone-0.3.3.js'
|
31
|
+
- 'client/public/javascripts/config/config.js'
|
32
|
+
- 'client/public/javascripts/models/*.js'
|
33
|
+
- 'client/public/javascripts/controller/*.js'
|
34
|
+
- 'client/public/javascripts/views/*.js'
|
35
|
+
- 'client/public/javascripts/tests/**/*mocks.js' # Dir.glob-pattern
|
36
|
+
- 'client/public/javascripts/vendor/backbone-0.3.3.js'
|
37
|
+
- 'client/public/javascripts/vendor/backbone.js'
|
@@ -0,0 +1,70 @@
|
|
1
|
+
$browsers = ENV['BROWSERS'] && ENV['BROWSERS'].split(",") || ["*firefox", "*safari"]
|
2
|
+
|
3
|
+
def run_test
|
4
|
+
$browsers.each do |browserstring|
|
5
|
+
browser = Selenium::Client::Driver.new \
|
6
|
+
:host => "localhost",
|
7
|
+
:port => 5555,
|
8
|
+
:browser => browserstring,
|
9
|
+
:url => "http://deck.s-cloud.net",
|
10
|
+
:timeout_in_second => 60
|
11
|
+
|
12
|
+
browser.start_new_browser_session
|
13
|
+
|
14
|
+
yield(browser)
|
15
|
+
|
16
|
+
browser.close_current_browser_session
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def goto_start_state(browser)
|
21
|
+
browser.open "/"
|
22
|
+
browser.refresh
|
23
|
+
browser.wait_for_page_to_load "60000"
|
24
|
+
browser.click "link=logout"
|
25
|
+
browser.wait_for_page_to_load "60000"
|
26
|
+
end
|
27
|
+
|
28
|
+
def login(browser)
|
29
|
+
goto_start_state(browser)
|
30
|
+
browser.type "id=login-username", "arms-test"
|
31
|
+
browser.type "name=password", "geheim"
|
32
|
+
browser.click "css=#login-form input[type=submit]"
|
33
|
+
wait{ browser.is_element_present("css=body.logging-in-state") }
|
34
|
+
wait{ browser.is_element_present("css=body.whitelist-view-state") }
|
35
|
+
end
|
36
|
+
|
37
|
+
def delete_all_whitelisted_users(browser)
|
38
|
+
while browser.is_element_present("css=#whitelisted-users-list tbody.user") do
|
39
|
+
browser.click "css=.revoke"
|
40
|
+
browser.get_confirmation
|
41
|
+
wait{ !browser.is_element_present("css=tr.pending-state-true") }
|
42
|
+
end
|
43
|
+
|
44
|
+
wait(60, "*** error while deleting all whitelist users") do
|
45
|
+
!browser.is_element_present("css=#whitelisted-users-list tbody.user")
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def add_a_user(browser)
|
50
|
+
if !browser.is_element_present("css=#whitelisted-users-list tbody.user")
|
51
|
+
browser.click "id=show-hide-add-user-dialog"
|
52
|
+
wait{ browser.is_element_present("css=body.add-user-state") }
|
53
|
+
browser.type "id=search-term", "arms-test"
|
54
|
+
browser.click "name=commit"
|
55
|
+
wait{ browser.is_element_present("css=body.show-search-result-state") }
|
56
|
+
browser.check "name=new-whitelist-users"
|
57
|
+
browser.type "name=note", "test-adding"
|
58
|
+
browser.click "id=submit"
|
59
|
+
wait(15, "no pending state when adding user #{__FILE__} / #{__LINE__}") do
|
60
|
+
browser.is_element_present("css=tr.pending-state-true")
|
61
|
+
end
|
62
|
+
wait{ !browser.is_element_present("css=tr.pending-state-true") }
|
63
|
+
wait{ browser.is_element_present("css=#whitelisted-users-list tbody.user") }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def wait(timeout = 30, message = "")
|
68
|
+
assert !timeout.times{ break if (yield rescue false); sleep 1 },
|
69
|
+
message
|
70
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
QUnit.log = function(result_object, message) {
|
2
|
+
message = result_object.result ? "ok " : "FAILED ";
|
3
|
+
message += result_object.message;
|
4
|
+
if(!result_object.result){
|
5
|
+
message += "\n-----------------------8<-------------------------"
|
6
|
+
message += "\nexpected: " + result_object.expected
|
7
|
+
message += "\nbut got: " + result_object.actual
|
8
|
+
message += "\nsource: " + result_object.source
|
9
|
+
message += "\n----------------------->8-------------------------\n"
|
10
|
+
window.errors.push(message);
|
11
|
+
}
|
12
|
+
window.results.push(message);
|
13
|
+
|
14
|
+
if (window.console && window.console.log) {
|
15
|
+
window.console.log(message);
|
16
|
+
}
|
17
|
+
};
|
18
|
+
if(!window.results) {
|
19
|
+
window.results = [];
|
20
|
+
}
|
21
|
+
if(!window.errors) {
|
22
|
+
window.errors = [];
|
23
|
+
}
|
data/lib/tasks/tuev.rake
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
TEST_DIR="tests"
|
5
|
+
|
6
|
+
def ansi_colors(color)
|
7
|
+
case color
|
8
|
+
when :green then ["\033[32m", "\033[0m"]
|
9
|
+
when :red then ["\033[31m", "\033[0m"]
|
10
|
+
else ['','']
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def cp_if_not_already_there(source, destination)
|
15
|
+
destination_expanded = File.join(Tuev.cwd, destination)
|
16
|
+
source_expanded = File.join(Tuev.gem_path, source)
|
17
|
+
print "%-60s" % destination
|
18
|
+
|
19
|
+
if File.exists?(destination_expanded)
|
20
|
+
prefix, suffix = ansi_colors(:red)
|
21
|
+
puts "#{prefix} ... already exists ... skipping#{suffix}"
|
22
|
+
else
|
23
|
+
FileUtils.cp(source_expanded, destination_expanded)
|
24
|
+
prefix, suffix = ansi_colors(:green)
|
25
|
+
puts "#{prefix} ... copied#{suffix}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def mkdir_if_not_already_there(dir)
|
30
|
+
dir_expanded = File.join(Tuev.cwd, dir)
|
31
|
+
print "%-60s" % "#{dir}"
|
32
|
+
|
33
|
+
if File.exists?(dir_expanded)
|
34
|
+
prefix, suffix = ansi_colors(:red)
|
35
|
+
puts "#{prefix} ... directory already exists#{suffix}"
|
36
|
+
else
|
37
|
+
FileUtils.mkdir_p(dir_expanded)
|
38
|
+
prefix, suffix = ansi_colors(:green)
|
39
|
+
puts "#{prefix} ... directory created#{suffix}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
namespace :tuev do
|
44
|
+
desc "prepare this project for tuev tests (create sample files, download qunit & friends)"
|
45
|
+
task :prepare do
|
46
|
+
mkdir_if_not_already_there("config")
|
47
|
+
cp_if_not_already_there("contrib/tuev.yml", "config/tuev.yml")
|
48
|
+
|
49
|
+
mkdir_if_not_already_there("#{TEST_DIR}/tuev/test_files")
|
50
|
+
cp_if_not_already_there("contrib/tuev_helper.rb", "#{TEST_DIR}/tuev_helper.rb")
|
51
|
+
|
52
|
+
mkdir_if_not_already_there("#{TEST_DIR}/tuev/contrib")
|
53
|
+
cp_if_not_already_there("contrib/qunit/qunit/qunit.css",
|
54
|
+
File.join(Tuev.contrib_dir, "qunit.css"))
|
55
|
+
cp_if_not_already_there("contrib/qunit/qunit/qunit.js",
|
56
|
+
File.join(Tuev.contrib_dir, "qunit.js"))
|
57
|
+
cp_if_not_already_there("contrib/jquery-1.5.1.js",
|
58
|
+
File.join(Tuev.contrib_dir, "jquery-1.5.1.js"))
|
59
|
+
cp_if_not_already_there("contrib/mockjax/jquery.mockjax.js",
|
60
|
+
File.join(Tuev.contrib_dir, "jquery.mockjax.js"))
|
61
|
+
cp_if_not_already_there("contrib/test_default.html",
|
62
|
+
File.join(Tuev.contrib_dir, "test_default.html"))
|
63
|
+
cp_if_not_already_there("contrib/tuev_qunit.js",
|
64
|
+
File.join(Tuev.contrib_dir, "tuev_qunit.js"))
|
65
|
+
end
|
66
|
+
|
67
|
+
desc "run tests"
|
68
|
+
task :run do
|
69
|
+
failures = 0
|
70
|
+
Tuev.test_suites.each do |test_suite|
|
71
|
+
test_suite.create_test_files.each do |file|
|
72
|
+
failures += QunitRunner.new(file, Tuev.selenium_conf).run
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
puts
|
77
|
+
|
78
|
+
case failures
|
79
|
+
when 0
|
80
|
+
puts "woohoo: all tests pass -- you rock !!!"
|
81
|
+
when 1
|
82
|
+
puts "1 test failing -- this is very close to 0 failing actually!"
|
83
|
+
when 2..5
|
84
|
+
puts "mmm ... #{failures} failing tests! Can't you do better?"
|
85
|
+
when 6..15
|
86
|
+
puts "ufff ... get to work: #{failures} tests are still failing"
|
87
|
+
when 100..1_000_000
|
88
|
+
puts "I hope you don't get paid for this code! #{failures} errors!"
|
89
|
+
else
|
90
|
+
puts "#{failures} failing tests! You gotta be kidding me!"
|
91
|
+
end
|
92
|
+
|
93
|
+
puts
|
94
|
+
|
95
|
+
exit(failures)
|
96
|
+
end
|
97
|
+
|
98
|
+
desc "create static testfiles for qunit tests"
|
99
|
+
task :create_testfiles => :clean_testfiles do
|
100
|
+
files = []
|
101
|
+
Tuev.test_suites.each do |test_suite|
|
102
|
+
files << test_suite.create_test_files
|
103
|
+
end
|
104
|
+
|
105
|
+
puts "Created the following test files:\n\t#{files.join("\n\t")}"
|
106
|
+
end
|
107
|
+
|
108
|
+
desc "delete all statically created testfiles"
|
109
|
+
task :clean_testfiles do
|
110
|
+
FileUtils.rm_f(Dir.glob(File.join(Tuev.test_out, "*.html")))
|
111
|
+
end
|
112
|
+
end
|
data/lib/tuev/tuev.rb
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
require 'erb'
|
2
|
+
|
3
|
+
class Tuev
|
4
|
+
@contrib_dir = "tests/tuev/contrib"
|
5
|
+
class << self
|
6
|
+
attr_accessor :cwd, :gem_path, :config, :contrib_dir
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.test_suites
|
10
|
+
config["test_suites"].inject([]) do |memo, test_suite_conf|
|
11
|
+
memo << TestSuite.new(test_suite_conf)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.test_out
|
16
|
+
File.expand_path(File.join(Tuev.cwd, "tests", "tuev", "test_files"))
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.selenium_conf
|
20
|
+
@selenium_conf ||= {
|
21
|
+
:host => config["selenium"]["host"],
|
22
|
+
:port => config["selenium"]["port"],
|
23
|
+
:browsers => [*config["selenium"]["browsers"]]
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
class TestSuite
|
28
|
+
def initialize(test_suite_config)
|
29
|
+
begin
|
30
|
+
@test_file_template = File.join(Tuev.cwd, test_suite_config["test_file_template"])
|
31
|
+
rescue
|
32
|
+
raise "could not find 'test_file_template' setting for current suite"
|
33
|
+
end
|
34
|
+
|
35
|
+
@jquery_js = file_url(Tuev.contrib_dir, "jquery-1.5.1.js")
|
36
|
+
@mockjax_js = file_url(Tuev.contrib_dir, "jquery.mockjax.js")
|
37
|
+
@qunit_js = file_url(Tuev.contrib_dir, "qunit.js")
|
38
|
+
@tuev_qunit_js = file_url(Tuev.contrib_dir, "tuev_qunit.js")
|
39
|
+
@qunit_css = file_url(Tuev.contrib_dir, "qunit.css")
|
40
|
+
@test_suite_name = test_suite_config["name"]
|
41
|
+
|
42
|
+
@combine_tests = test_suite_config["combine_tests"]
|
43
|
+
|
44
|
+
@test_set = @tests = build_file_list(test_suite_config["test_files"])
|
45
|
+
|
46
|
+
@dependencies = build_file_list(test_suite_config["dependencies"])
|
47
|
+
end
|
48
|
+
|
49
|
+
def create_test_files
|
50
|
+
files = []
|
51
|
+
if @combine_tests
|
52
|
+
files << File.join(out_path, "#{@test_suite_name}.html")
|
53
|
+
|
54
|
+
@test_set_name = title_from_filename(files.last)
|
55
|
+
@test_set = @tests
|
56
|
+
save(render_template(@tests), files.last)
|
57
|
+
else
|
58
|
+
@tests.each do |test|
|
59
|
+
files << File.join(out_path, "#{@test_suite_name}_#{test.gsub('file://','').gsub(Tuev.cwd, '').tr('/.','_')}.html")
|
60
|
+
|
61
|
+
@test_set_name = title_from_filename(files.last)
|
62
|
+
@test_set = [test]
|
63
|
+
save(render_template(test), files.last)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
files
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
def title_from_filename(filename)
|
72
|
+
filename.gsub(/#{out_path}[\/]*/, '').gsub('.html','').gsub('_js','').gsub('_',' ')
|
73
|
+
end
|
74
|
+
|
75
|
+
def out_path
|
76
|
+
Tuev.test_out
|
77
|
+
end
|
78
|
+
|
79
|
+
def save(source_code, filename)
|
80
|
+
File.open(filename, "w") do |f|
|
81
|
+
f << source_code
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def render_template(tests)
|
86
|
+
template = ERB.new(File.read(@test_file_template))
|
87
|
+
template.result(binding)
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
def build_file_list(includes_and_excludes)
|
92
|
+
file_list = [*includes_and_excludes["include"]].map do |pattern|
|
93
|
+
files = Dir.glob(pattern)
|
94
|
+
if files.empty?
|
95
|
+
raise "could not find file matching '#{pattern}'"
|
96
|
+
end
|
97
|
+
files
|
98
|
+
end
|
99
|
+
|
100
|
+
file_list.flatten!
|
101
|
+
|
102
|
+
if excludes = includes_and_excludes["exclude"]
|
103
|
+
[*excludes].each do |exclude_regexp|
|
104
|
+
file_list.delete_if{|x| x =~ /#{exclude_regexp}/ }
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
|
109
|
+
file_list.map{|x| file_url(x)}
|
110
|
+
end
|
111
|
+
|
112
|
+
def file_url(*relativ_path_parts)
|
113
|
+
"file://#{File.expand_path(File.join(Tuev.cwd, *relativ_path_parts))}"
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require "selenium/client"
|
2
|
+
class QunitRunner
|
3
|
+
def initialize(path, selenium_conf)
|
4
|
+
@test_file = path
|
5
|
+
@selenium_conf = selenium_conf
|
6
|
+
end
|
7
|
+
|
8
|
+
def run_in_browser(browser_string)
|
9
|
+
begin
|
10
|
+
Net::HTTP.new(@selenium_conf[:host], @selenium_conf[:port]).get2("/")
|
11
|
+
rescue
|
12
|
+
puts
|
13
|
+
puts "It seems that there is no selenium server listening on '#{@selenium_conf[:host]}:#{@selenium_conf[:port]}'"
|
14
|
+
puts
|
15
|
+
puts "... aborting (try installing the gem 'selenium-server' and execute 'selenium-server' for an easy solution)"
|
16
|
+
puts
|
17
|
+
puts
|
18
|
+
exit(1)
|
19
|
+
end
|
20
|
+
|
21
|
+
selenium = Selenium::Client::Driver.new(
|
22
|
+
:host => @selenium_conf[:host],
|
23
|
+
:port => @selenium_conf[:port],
|
24
|
+
:browser => browser_string,
|
25
|
+
:url => "file://",
|
26
|
+
:timeout_in_second => 60
|
27
|
+
)
|
28
|
+
|
29
|
+
selenium.start_new_browser_session
|
30
|
+
yield(selenium)
|
31
|
+
selenium.close_current_browser_session
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
def run
|
36
|
+
num_of_errors = 0
|
37
|
+
errors = ""
|
38
|
+
|
39
|
+
@selenium_conf[:browsers].each do |browser_id|
|
40
|
+
run_in_browser(browser_id) do |browser|
|
41
|
+
browser.open "file://#{@test_file}"
|
42
|
+
browser.wait_for_page_to_load "60000"
|
43
|
+
puts "\n****** testing #{browser.get_text('css=title')} in #{browser_id}"
|
44
|
+
puts "file:\n\t#{@test_file}\n\n"
|
45
|
+
60.times{ break if (browser.is_element_present("id=qunit-testresult") rescue false); sleep 1 }
|
46
|
+
sleep 1
|
47
|
+
puts browser.get_eval('window.results.join("\n")')
|
48
|
+
errors += browser.get_eval('window.errors.join("\n")')
|
49
|
+
60.times{ break if (browser.get_text('id=qunit-testresult') != "Running..." rescue false); sleep 1 }
|
50
|
+
puts browser.get_text('id=qunit-testresult')
|
51
|
+
num_of_errors += browser.get_text("css=#qunit-testresult .failed").to_i
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
unless errors == ""
|
56
|
+
puts
|
57
|
+
puts "Finished with these errors:"
|
58
|
+
puts
|
59
|
+
puts errors
|
60
|
+
end
|
61
|
+
|
62
|
+
num_of_errors
|
63
|
+
end
|
64
|
+
end
|
data/lib/tuev.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'tuev/tuev.rb'
|
2
|
+
require 'tuev/tuev_runner.rb'
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
Tuev.gem_path = Gem.searcher.find('tuev').full_gem_path
|
6
|
+
|
7
|
+
if defined?(TESTING)
|
8
|
+
Tuev.cwd = File.join(Dir.pwd, "spec", "fixtures", "fake_root")
|
9
|
+
else
|
10
|
+
Tuev.cwd = Dir.pwd
|
11
|
+
Dir["#{Tuev.gem_path}/lib/tasks/*.rake"].each { |ext| load ext }
|
12
|
+
end
|
13
|
+
|
14
|
+
config_file = File.join(Tuev.cwd, "config/tuev.yml")
|
15
|
+
Tuev.config = YAML.load_file(config_file) if File.exists?(config_file)
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# basic selenium stuff
|
2
|
+
selenium_stuff:
|
3
|
+
host: 'localhost' # host which runs selenium server
|
4
|
+
port: '4444' # selenium server port (if you get connection refused, try 5555)
|
5
|
+
browsers:
|
6
|
+
- '*firefox' # should work on most systems
|
7
|
+
#- *googlechrome # ... can't get it to work on mac os x or linux
|
8
|
+
#- *safari # well: mac os x only
|
9
|
+
default_timeout_in_seconds: 15 # requests that take longer fail
|
10
|
+
|
11
|
+
# define test suite here ... it's basically a Dir.glob-pattern for all test files
|
12
|
+
# and dependencies needed by test files
|
13
|
+
# qunit will be included automatically ... don't bother
|
14
|
+
# If JS-Files need to be loaded in a special order, list them individually ... all
|
15
|
+
# paths are relative to the directory from where the test is called (root of your
|
16
|
+
# project usually)
|
17
|
+
test_suites:
|
18
|
+
suite:
|
19
|
+
name: 'qunit_tests'
|
20
|
+
test_file_template: 'test/default_test.html' # it should be there ... check it out, adjust it to your needs
|
21
|
+
test_runner: 'test/qunit_tester.rb'
|
22
|
+
combine_tests: false # whether to create one big test file or one pre js-test-file
|
23
|
+
test_files:
|
24
|
+
include: 'spec/tuev/unit_tests/**/*.js' # Dir.glob-pattern
|
25
|
+
exclude: 'config\..*\.js' # regex of file names to be ignored
|
26
|
+
dependencies:
|
27
|
+
include: # include in a specified order
|
28
|
+
- 'client/public/javascripts/vendor/backbone-0.3.3.js'
|
29
|
+
- 'client/public/javascripts/vendor/backbone.js'
|
30
|
+
- 'client/public/javascripts/vendor/jquery.mockjax.js'
|
31
|
+
- 'client/public/javascripts/vendor/qunit.js'
|
32
|
+
- 'client/public/javascripts/vendor/underscore-1.1.4.js'
|
33
|
+
- 'client/public/javascripts/vendor/underscore.js'
|
34
|
+
- 'client/public/javascripts/vendor/models/*.js'
|
35
|
+
- 'client/public/javascripts/vendor/views/*.js'
|
36
|
+
- 'client/public/javascripts/vendor/controller/*.js'
|
37
|
+
suite:
|
38
|
+
name: 'selenium_tests'
|
39
|
+
test_url: 'http://soundcloud.com'
|
@@ -0,0 +1,13 @@
|
|
1
|
+
client/public/javascripts//tests
|
2
|
+
client/public/javascripts//tests/.test_helper.js.swp
|
3
|
+
client/public/javascripts//tests/fixtures
|
4
|
+
client/public/javascripts//tests/fixtures/user_mocks.js
|
5
|
+
client/public/javascripts//tests/fixtures/whitelist_list_mocks.js
|
6
|
+
client/public/javascripts//tests/models
|
7
|
+
client/public/javascripts//tests/models/user_list_tests.js
|
8
|
+
client/public/javascripts//tests/models/user_tests.js
|
9
|
+
client/public/javascripts//tests/models/whitelist_list_tests.js
|
10
|
+
client/public/javascripts//tests/test_helper.js
|
11
|
+
client/public/javascripts//tests/views
|
12
|
+
client/public/javascripts//tests/views/whitelist_list_tests.js
|
13
|
+
client/public/javascripts//tests/views/whitelist_user_tests.js
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'bacon'
|
11
|
+
|
12
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
TESTING=true
|
15
|
+
require 'tuev'
|
16
|
+
|
17
|
+
Bacon.summary_on_exit
|