qunit_for_rails 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +5 -0
- data/Gemfile +7 -0
- data/MIT-LICENSE +20 -0
- data/README.mdown +103 -0
- data/Rakefile +31 -0
- data/app/controllers/qunit_for_rails/qunit_tests_controller.rb +19 -0
- data/app/views/layouts/qunit_for_rails/main.haml +15 -0
- data/app/views/qunit_for_rails/qunit_tests/index.html.haml +15 -0
- data/config/routes.rb +3 -0
- data/lib/qunit_for_rails.rb +15 -0
- data/lib/qunit_for_rails/engine.rb +20 -0
- data/lib/qunit_for_rails/version.rb +3 -0
- data/lib/tasks/qunit_for_rails_tasks.rake +4 -0
- data/public/images/bg_diagonalDarkBlue.gif +0 -0
- data/public/images/bg_secondaryNav_left.gif +0 -0
- data/public/images/bg_secondaryNav_right.gif +0 -0
- data/public/images/i_loading_bar.gif +0 -0
- data/public/images/l_qunit.png +0 -0
- data/public/javascripts/qunit_for_rails/index.js +0 -0
- data/public/javascripts/qunit_for_rails/inject.js +191 -0
- data/public/javascripts/qunit_for_rails/jquery-1.6.4.min.js +4 -0
- data/public/javascripts/qunit_for_rails/qunit.js +1585 -0
- data/public/javascripts/qunit_for_rails/qunit.page_load.js +47 -0
- data/public/javascripts/qunit_for_rails/qunit.test_loader.js +98 -0
- data/public/javascripts/qunit_for_rails/qunit.test_page.js +55 -0
- data/public/javascripts/qunit_for_rails/qunit_for_rails.js +159 -0
- data/public/javascripts/tests/test.js +13 -0
- data/public/stylesheets/qunit.css +228 -0
- data/public/stylesheets/qunit_for_rails.css +255 -0
- data/qunit_for_rails.gemspec +29 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +43 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +22 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +26 -0
- data/test/dummy/config/environments/production.rb +49 -0
- data/test/dummy/config/environments/test.rb +35 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +10 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +58 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/log/development.log +4297 -0
- data/test/dummy/log/production.log +0 -0
- data/test/dummy/log/server.log +0 -0
- data/test/dummy/log/test.log +0 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +26 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/public/javascripts/application.js +2 -0
- data/test/dummy/public/javascripts/controls.js +965 -0
- data/test/dummy/public/javascripts/dragdrop.js +974 -0
- data/test/dummy/public/javascripts/effects.js +1123 -0
- data/test/dummy/public/javascripts/prototype.js +6001 -0
- data/test/dummy/public/javascripts/rails.js +191 -0
- data/test/dummy/public/javascripts/test/example2_test.js +23 -0
- data/test/dummy/public/javascripts/test/example_test.js +23 -0
- data/test/dummy/public/stylesheets/.gitkeep +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/integration/navigation_test.rb +7 -0
- data/test/qunit_for_rails_test.rb +33 -0
- data/test/support/integration_case.rb +5 -0
- data/test/test_helper.rb +3 -0
- metadata +224 -0
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 [name of plugin creator]
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.mdown
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
QunitForRails
|
2
|
+
=============
|
3
|
+
|
4
|
+
QUnit for Rails provides an easy way to run JavaScript integration testing
|
5
|
+
against production rendered HTML using the QUnit testing framework.
|
6
|
+
QUnit for Rails simply adds an overlay menu at the top of an app's pages,
|
7
|
+
allowing developers to run JavaScript tests and view the results right in the
|
8
|
+
browser.
|
9
|
+
|
10
|
+
To read more about QUnit:
|
11
|
+
[http://docs.jquery.com/QUnit][]
|
12
|
+
|
13
|
+
The source for this plugin is located on Github:
|
14
|
+
[http://github.com/mkrisher/qunit_for_rails/][]
|
15
|
+
|
16
|
+
The plugin can be installed using:
|
17
|
+
`script/plugin install git@github.com:mkrisher/qunit_for_rails.git`
|
18
|
+
|
19
|
+
Details
|
20
|
+
=======
|
21
|
+
|
22
|
+
QUnit for Rails provides an easy way for developers to write JavaScript tests
|
23
|
+
and run those tests against HTML output in the browser. QUnit for Rails does
|
24
|
+
not run via the command line, it is run in the browser against the real HTML
|
25
|
+
output.
|
26
|
+
|
27
|
+
QUnit for Rails provides some necessary JavaScript and CSS files and places
|
28
|
+
them in your app's public directory. These files simply create the overlay
|
29
|
+
menu that gets added to your pages. The plugin also provides the latest QUnit
|
30
|
+
file. In case you ever want to change the version of QUnit, you would simply
|
31
|
+
replace the file in your public/javascript directory.
|
32
|
+
|
33
|
+
The overlay provides a number of things. First, all your JavaScript tests are
|
34
|
+
stored in /public/javascript/tests. Any JavaScript test added to the directory
|
35
|
+
will appear in a dropdown in the overlay. Simply selecting a test from the
|
36
|
+
dropdown runs it against the current page. Or there is an option to run all
|
37
|
+
tests against a page.
|
38
|
+
|
39
|
+
In much the same way Rails unit testing and functional testing work, you could
|
40
|
+
easily create a JavaScript test for each controller and action of your app.
|
41
|
+
|
42
|
+
During the plugin install process, the tests directory is created and an
|
43
|
+
example test file is included. Follow the test file's formatting to create
|
44
|
+
additional tests.
|
45
|
+
|
46
|
+
The plugin also provides some handy keypress functionality. For example, hiding
|
47
|
+
the overlay you simply press 'shift+h'. All keypress options are
|
48
|
+
shown by press 'shift+?'.
|
49
|
+
|
50
|
+
The QUnit overlay looks like this in the browser:
|
51
|
+
|
52
|
+
[](http://farm3.static.flickr.com/2603/4014493975_cfc0c2af3d_o.png)
|
53
|
+
|
54
|
+
Running a test pushes the page down and reveals the test results:
|
55
|
+
|
56
|
+
[](http://farm3.static.flickr.com/2464/4015257542_d6c759682f_o.png)
|
57
|
+
|
58
|
+
Requirements
|
59
|
+
=======
|
60
|
+
|
61
|
+
The QUnit for Rails plugin requires jQuery at this time. You can include
|
62
|
+
jQuery easily by adding to the head of your document layout:
|
63
|
+
|
64
|
+
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
|
65
|
+
<script type="text/javascript">
|
66
|
+
google.load("jquery", "1.3.2");
|
67
|
+
</script>
|
68
|
+
|
69
|
+
|
70
|
+
Usage
|
71
|
+
=====
|
72
|
+
|
73
|
+
To include the QUnit testing overlay on your page simply add
|
74
|
+
`<%= include_qunit %>` to the head of your document layout.
|
75
|
+
|
76
|
+
If you would like to include qunit_for_rails but not have it show on the top
|
77
|
+
of the page automatically, you can hide it on load using:
|
78
|
+
`<%= include_qunit({:autohide => true}) %>`.
|
79
|
+
|
80
|
+
After adding the `<%= include_qunit %>` to the head of your document layout,
|
81
|
+
you simply need to add some test files to the
|
82
|
+
`/public/javascript/tests directory`.
|
83
|
+
|
84
|
+
The tests are written in JSON and follow a pattern such as:
|
85
|
+
|
86
|
+
var localtests = {
|
87
|
+
test_another_example : function()
|
88
|
+
{
|
89
|
+
module("Module Example Tests");
|
90
|
+
test("simple passing example", function()
|
91
|
+
{
|
92
|
+
var value = "foo";
|
93
|
+
equals( "foo", value, "We expect value to be foo" );
|
94
|
+
});
|
95
|
+
}
|
96
|
+
};
|
97
|
+
$().extend(tests, localtests);
|
98
|
+
|
99
|
+
|
100
|
+
Copyright (c) 2009 Michael Krisher, released under the MIT license
|
101
|
+
|
102
|
+
[http://docs.jquery.com/QUnit]: http://docs.jquery.com/QUnit
|
103
|
+
[http://github.com/mkrisher/qunit_for_rails/]: http://github.com/mkrisher/qunit_for_rails/
|
data/Rakefile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'rubygems'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'bundler/setup'
|
6
|
+
require "bundler/gem_tasks"
|
7
|
+
rescue LoadError
|
8
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
9
|
+
end
|
10
|
+
|
11
|
+
require 'rake'
|
12
|
+
require 'rake/rdoctask'
|
13
|
+
|
14
|
+
require 'rake/testtask'
|
15
|
+
|
16
|
+
Rake::TestTask.new(:test) do |t|
|
17
|
+
t.libs << 'lib'
|
18
|
+
t.libs << 'test'
|
19
|
+
t.pattern = 'test/**/*_test.rb'
|
20
|
+
t.verbose = false
|
21
|
+
end
|
22
|
+
|
23
|
+
task :default => :test
|
24
|
+
|
25
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
26
|
+
rdoc.rdoc_dir = 'rdoc'
|
27
|
+
rdoc.title = 'TestForRails'
|
28
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
29
|
+
rdoc.rdoc_files.include('README.rdoc')
|
30
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
31
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module QunitForRails
|
2
|
+
class QunitTestsController < ApplicationController
|
3
|
+
skip_before_filter :authorize
|
4
|
+
layout "qunit_for_rails/main"
|
5
|
+
|
6
|
+
def index
|
7
|
+
test_files = []
|
8
|
+
|
9
|
+
Dir.glob(::Rails.root.to_s + "/public/javascripts/test/*").each { |file|
|
10
|
+
if file.end_with?('_test.js')
|
11
|
+
test_files << file.split('/').last
|
12
|
+
end
|
13
|
+
}
|
14
|
+
|
15
|
+
render :index, :locals => { :test_files => test_files, :root_url => ENV['RAILS_RELATIVE_URL_ROOT'] }
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
= content_for(:stylesheets) do
|
2
|
+
%link(rel="stylesheet" type="text/css" href="#{root_url}/stylesheets/qunit.css")
|
3
|
+
%link(rel="stylesheet" type="text/css" href="#{root_url}/stylesheets/qunit_for_rails.css")
|
4
|
+
|
5
|
+
= content_for(:javascripts) do
|
6
|
+
%script{:type => "text/javascript", :src => "#{root_url}/javascripts/qunit_for_rails/jquery-1.6.4.min.js"}
|
7
|
+
%script{:type => "text/javascript", :src => "#{root_url}/javascripts/qunit_for_rails/qunit.js"}
|
8
|
+
%script{:type => "text/javascript", :src => "#{root_url}/javascripts/qunit_for_rails/qunit.test_loader.js"}
|
9
|
+
%script{:type => "text/javascript", :src => "#{root_url}/javascripts/qunit_for_rails/qunit_for_rails.js"}
|
10
|
+
|
11
|
+
:javascript
|
12
|
+
var QFR = {};
|
13
|
+
var test_list = #{test_files.to_json};
|
14
|
+
|
15
|
+
QFR.root_url = "#{root_url}";
|
data/config/routes.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require "rails/engine"
|
2
|
+
require "qunit_for_rails"
|
3
|
+
|
4
|
+
module QunitForRails
|
5
|
+
|
6
|
+
class Engine < Rails::Engine
|
7
|
+
|
8
|
+
initializer "load_app_instance_data" do |app|
|
9
|
+
QunitForRails.setup do |config|
|
10
|
+
config.app_root = app.root
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
initializer "static assets" do |app|
|
15
|
+
app.middleware.use ::ActionDispatch::Static, "#{root}/public"
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
File without changes
|
@@ -0,0 +1,191 @@
|
|
1
|
+
(function(){
|
2
|
+
|
3
|
+
var DEBUG = false;
|
4
|
+
// hold each test run as row
|
5
|
+
var testresults = [];
|
6
|
+
|
7
|
+
var doPost = false;
|
8
|
+
|
9
|
+
try {
|
10
|
+
doPost = !!window.top.postMessage;
|
11
|
+
} catch(e){}
|
12
|
+
|
13
|
+
var search = window.location.search,
|
14
|
+
url, index;
|
15
|
+
if( ( index = search.indexOf( "swarmURL=" ) ) != -1 )
|
16
|
+
url = decodeURIComponent( search.slice( index + 9 ) );
|
17
|
+
|
18
|
+
if ( !DEBUG && (!url || url.indexOf("http") !== 0) ) {
|
19
|
+
return;
|
20
|
+
}
|
21
|
+
|
22
|
+
var submitTimeout = 5;
|
23
|
+
|
24
|
+
var curHeartbeat;
|
25
|
+
var beatRate = 20;
|
26
|
+
|
27
|
+
// Expose the TestSwarm API
|
28
|
+
window.TestSwarm = {
|
29
|
+
submit: submit,
|
30
|
+
heartbeat: function(){
|
31
|
+
if ( curHeartbeat ) {
|
32
|
+
clearTimeout( curHeartbeat );
|
33
|
+
}
|
34
|
+
|
35
|
+
curHeartbeat = setTimeout(function(){
|
36
|
+
submit({ fail: -1, total: -1 });
|
37
|
+
}, beatRate * 1000);
|
38
|
+
},
|
39
|
+
serialize: function(){
|
40
|
+
return trimSerialize();
|
41
|
+
}
|
42
|
+
};
|
43
|
+
|
44
|
+
// Prevent careless things from executing
|
45
|
+
window.print = window.confirm = window.alert = window.open = function(){};
|
46
|
+
|
47
|
+
window.onerror = function(e){
|
48
|
+
document.body.appendChild( document.createTextNode( "ERROR: " + e ));
|
49
|
+
submit({ fail: 0, error: 1, total: 1 });
|
50
|
+
return false;
|
51
|
+
};
|
52
|
+
|
53
|
+
// QUnit callbacks - shughes
|
54
|
+
if ( typeof QUnit !== "undefined" ) {
|
55
|
+
QUnit.done = function(results){
|
56
|
+
submit({
|
57
|
+
fail: results.failed,
|
58
|
+
error: 0,
|
59
|
+
time: results.runtime,
|
60
|
+
total: results.total,
|
61
|
+
results: JSON.stringify(testresults)
|
62
|
+
});
|
63
|
+
};
|
64
|
+
QUnit.testDone = function(results){
|
65
|
+
testresults.push(results);
|
66
|
+
};
|
67
|
+
|
68
|
+
QUnit.log = window.TestSwarm.heartbeat;
|
69
|
+
window.TestSwarm.heartbeat();
|
70
|
+
|
71
|
+
window.TestSwarm.serialize = function(){
|
72
|
+
// Clean up the HTML (remove any un-needed test markup)
|
73
|
+
remove("nothiddendiv");
|
74
|
+
remove("loadediframe");
|
75
|
+
remove("dl");
|
76
|
+
remove("main");
|
77
|
+
|
78
|
+
// Show any collapsed results
|
79
|
+
var ol = document.getElementsByTagName("ol");
|
80
|
+
for ( var i = 0; i < ol.length; i++ ) {
|
81
|
+
ol[i].style.display = "block";
|
82
|
+
}
|
83
|
+
|
84
|
+
return trimSerialize();
|
85
|
+
};
|
86
|
+
}
|
87
|
+
|
88
|
+
function trimSerialize(doc) {
|
89
|
+
doc = doc || document;
|
90
|
+
|
91
|
+
var scripts = doc.getElementsByTagName("script");
|
92
|
+
while ( scripts.length ) {
|
93
|
+
remove( scripts[0] );
|
94
|
+
}
|
95
|
+
|
96
|
+
var root = window.location.href.replace(/(https?:\/\/.*?)\/.*/, "$1");
|
97
|
+
var cur = window.location.href.replace(/[^\/]*$/, "");
|
98
|
+
|
99
|
+
var links = doc.getElementsByTagName("link");
|
100
|
+
for ( var i = 0; i < links.length; i++ ) {
|
101
|
+
var href = links[i].href;
|
102
|
+
if ( href.indexOf("/") === 0 ) {
|
103
|
+
href = root + href;
|
104
|
+
} else if ( !/^https?:\/\//.test( href ) ) {
|
105
|
+
href = cur + href;
|
106
|
+
}
|
107
|
+
links[i].href = href;
|
108
|
+
}
|
109
|
+
|
110
|
+
return ("<html>" + doc.documentElement.innerHTML + "</html>")
|
111
|
+
.replace(/\s+/g, " ");
|
112
|
+
}
|
113
|
+
|
114
|
+
function remove(elem){
|
115
|
+
if ( typeof elem === "string" ) {
|
116
|
+
elem = document.getElementById( elem );
|
117
|
+
}
|
118
|
+
|
119
|
+
if ( elem ) {
|
120
|
+
elem.parentNode.removeChild( elem );
|
121
|
+
}
|
122
|
+
}
|
123
|
+
|
124
|
+
function submit(params){
|
125
|
+
if ( curHeartbeat ) {
|
126
|
+
clearTimeout( curHeartbeat );
|
127
|
+
}
|
128
|
+
|
129
|
+
var paramItems = (url.split("?")[1] || "").split("&");
|
130
|
+
|
131
|
+
for ( var i = 0; i < paramItems.length; i++ ) {
|
132
|
+
if ( paramItems[i] ) {
|
133
|
+
var parts = paramItems[i].split("=");
|
134
|
+
if ( !params[ parts[0] ] ) {
|
135
|
+
params[ parts[0] ] = parts[1];
|
136
|
+
}
|
137
|
+
}
|
138
|
+
}
|
139
|
+
|
140
|
+
if ( !params.state ) {
|
141
|
+
params.state = "saverun";
|
142
|
+
}
|
143
|
+
|
144
|
+
if ( !params.results ) {
|
145
|
+
params.results = window.TestSwarm.serialize();
|
146
|
+
}
|
147
|
+
|
148
|
+
if ( doPost ) {
|
149
|
+
// Build Query String
|
150
|
+
var query = "";
|
151
|
+
|
152
|
+
for ( var i in params ) {
|
153
|
+
query += ( query ? "&" : "" ) + i + "=" +
|
154
|
+
encodeURIComponent(params[i]);
|
155
|
+
}
|
156
|
+
|
157
|
+
if ( DEBUG ) {
|
158
|
+
alert( query );
|
159
|
+
} else {
|
160
|
+
window.top.postMessage( query, "*" );
|
161
|
+
}
|
162
|
+
|
163
|
+
} else {
|
164
|
+
var form = document.createElement("form");
|
165
|
+
form.action = url;
|
166
|
+
form.method = "POST";
|
167
|
+
|
168
|
+
for ( var i in params ) {
|
169
|
+
var input = document.createElement("input");
|
170
|
+
input.type = "hidden";
|
171
|
+
input.name = i;
|
172
|
+
input.value = params[i];
|
173
|
+
form.appendChild( input );
|
174
|
+
}
|
175
|
+
|
176
|
+
if ( DEBUG ) {
|
177
|
+
alert( form.innerHTML );
|
178
|
+
} else {
|
179
|
+
|
180
|
+
// Watch for the result submission timing out
|
181
|
+
setTimeout(function(){
|
182
|
+
submit( params );
|
183
|
+
}, submitTimeout * 1000);
|
184
|
+
|
185
|
+
document.body.appendChild( form );
|
186
|
+
form.submit();
|
187
|
+
}
|
188
|
+
}
|
189
|
+
}
|
190
|
+
|
191
|
+
})();
|