test_squad 0.0.1

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.
Files changed (77) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +194 -0
  4. data/Rakefile +18 -0
  5. data/app/assets/javascripts/jasmine/boot.js +67 -0
  6. data/app/assets/javascripts/test_squad/jasmine-phantom.js +85 -0
  7. data/app/assets/javascripts/test_squad/mocha-reporter.js +104 -0
  8. data/app/assets/javascripts/test_squad/qunit-phantom.js +84 -0
  9. data/app/assets/stylesheets/test_squad/ember.css +16 -0
  10. data/app/controllers/test_squad_controller.rb +6 -0
  11. data/app/views/test_squad/ember.html.erb +14 -0
  12. data/app/views/test_squad/jasmine.html.erb +15 -0
  13. data/app/views/test_squad/mocha.html.erb +11 -0
  14. data/app/views/test_squad/qunit.html.erb +13 -0
  15. data/config/routes.rb +5 -0
  16. data/lib/generators/test_squad/install/USAGE +8 -0
  17. data/lib/generators/test_squad/install/install_generator.rb +86 -0
  18. data/lib/generators/test_squad/install/templates/ember/router_test.js +11 -0
  19. data/lib/generators/test_squad/install/templates/ember/test_helper.js.erb +15 -0
  20. data/lib/generators/test_squad/install/templates/jasmine/answer_spec.js +6 -0
  21. data/lib/generators/test_squad/install/templates/jasmine/spec_helper.js.erb +3 -0
  22. data/lib/generators/test_squad/install/templates/mocha/answer_spec.js +6 -0
  23. data/lib/generators/test_squad/install/templates/mocha/spec_helper.js.erb +12 -0
  24. data/lib/generators/test_squad/install/templates/qunit/answer_test.js +6 -0
  25. data/lib/generators/test_squad/install/templates/qunit/test_helper.js.erb +3 -0
  26. data/lib/generators/test_squad/install/templates/test_squad.rb.erb +5 -0
  27. data/lib/tasks/test_squad_tasks.rake +39 -0
  28. data/lib/terminal.png +0 -0
  29. data/lib/test_squad.rb +26 -0
  30. data/lib/test_squad/engine.rb +36 -0
  31. data/lib/test_squad/version.rb +3 -0
  32. data/phantomjs/helpers.js +24 -0
  33. data/phantomjs/runner.js +176 -0
  34. data/test/dummy/README.rdoc +28 -0
  35. data/test/dummy/Rakefile +6 -0
  36. data/test/dummy/app/assets/javascripts/application.js +13 -0
  37. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  38. data/test/dummy/app/controllers/application_controller.rb +5 -0
  39. data/test/dummy/app/helpers/application_helper.rb +2 -0
  40. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  41. data/test/dummy/bin/bundle +3 -0
  42. data/test/dummy/bin/rails +4 -0
  43. data/test/dummy/bin/rake +4 -0
  44. data/test/dummy/bin/setup +29 -0
  45. data/test/dummy/config.ru +4 -0
  46. data/test/dummy/config/application.rb +29 -0
  47. data/test/dummy/config/boot.rb +5 -0
  48. data/test/dummy/config/environment.rb +5 -0
  49. data/test/dummy/config/environments/development.rb +38 -0
  50. data/test/dummy/config/environments/production.rb +76 -0
  51. data/test/dummy/config/environments/test.rb +42 -0
  52. data/test/dummy/config/initializers/assets.rb +11 -0
  53. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  54. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  55. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  56. data/test/dummy/config/initializers/inflections.rb +16 -0
  57. data/test/dummy/config/initializers/mime_types.rb +4 -0
  58. data/test/dummy/config/initializers/session_store.rb +3 -0
  59. data/test/dummy/config/initializers/wrap_parameters.rb +9 -0
  60. data/test/dummy/config/locales/en.yml +23 -0
  61. data/test/dummy/config/routes.rb +56 -0
  62. data/test/dummy/config/secrets.yml +22 -0
  63. data/test/dummy/public/404.html +67 -0
  64. data/test/dummy/public/422.html +67 -0
  65. data/test/dummy/public/500.html +66 -0
  66. data/test/dummy/public/favicon.ico +0 -0
  67. data/test/integration/navigation_test.rb +9 -0
  68. data/test/lib/generators/squad/install_generator_test.rb +14 -0
  69. data/test/test_helper.rb +17 -0
  70. data/test/test_squad_test.rb +7 -0
  71. data/vendor/assets/libs/jasmine/boot.js +120 -0
  72. data/vendor/assets/libs/jasmine/console.js +190 -0
  73. data/vendor/assets/libs/jasmine/jasmine-html.js +404 -0
  74. data/vendor/assets/libs/jasmine/jasmine.css +62 -0
  75. data/vendor/assets/libs/jasmine/jasmine.js +2908 -0
  76. data/vendor/assets/libs/jasmine/jasmine_favicon.png +0 -0
  77. metadata +186 -0
@@ -0,0 +1,84 @@
1
+ (function(){
2
+ if (!navigator.userAgent.match(/phantomjs/i)) {
3
+ return;
4
+ }
5
+
6
+ var stats = {
7
+ passes: 0,
8
+ fails: 0,
9
+ pending: 0,
10
+ elapsed: 0,
11
+ assertions: 0,
12
+ tests: 0
13
+ };
14
+
15
+ var start, assertion;
16
+
17
+ QUnit.testStart(function(data){
18
+ assertion = null;
19
+ stats.tests += 1;
20
+
21
+ callPhantom({
22
+ name: 'test start',
23
+ title: data.name
24
+ });
25
+ });
26
+
27
+ QUnit.log(function(data){
28
+ stats.assertions += 1;
29
+
30
+ if (!assertion && !data.result) {
31
+ assertion = data;
32
+ }
33
+ });
34
+
35
+ QUnit.moduleStart(function(data){
36
+ callPhantom({
37
+ name: 'suite start',
38
+ title: data.name
39
+ });
40
+ });
41
+
42
+ QUnit.testDone(function(data){
43
+ var error;
44
+
45
+ if (data.failed) {
46
+ stats.fails += 1;
47
+ error = assertion.message;
48
+
49
+ if (assertion.source) {
50
+ error += '\n' + assertion.source;
51
+ }
52
+
53
+ error = error.replace(/(Died on test #\d+)/gmi, '$1\n');
54
+ error = error.replace(/^\s*/gm, ' ');
55
+ error = error.replace(/^\s+at .*?assets\/qunit\/qunit.*?\.js.*?$/mg, '');
56
+ error = error.replace(/\n+$/, '');
57
+ } else if (data.skipped) {
58
+ stats.pending += 1;
59
+ } else {
60
+ stats.passes += 1;
61
+ }
62
+
63
+ callPhantom({
64
+ name: 'test end',
65
+ title: data.name,
66
+ passed: data.failed === 0 && !data.skipped,
67
+ pending: data.skipped,
68
+ failure: error
69
+ });
70
+ });
71
+
72
+ QUnit.begin(function(data){
73
+ start = new Date().getTime();
74
+ });
75
+
76
+ QUnit.done(function(data){
77
+ stats.elapsed = new Date().getTime() - start;
78
+
79
+ callPhantom({
80
+ name: 'end',
81
+ stats: stats
82
+ });
83
+ });
84
+ })();
@@ -0,0 +1,16 @@
1
+ #ember-testing-container {
2
+ position: absolute;
3
+ background: white;
4
+ width: 640px;
5
+ height: 384px;
6
+ overflow: auto;
7
+ z-index: 9999;
8
+ border: 1px solid #ccc;
9
+ right: 50px;
10
+ bottom: 50px;
11
+ padding: 5px;
12
+ }
13
+
14
+ #ember-testing {
15
+ zoom: 50%;
16
+ }
@@ -0,0 +1,6 @@
1
+ class TestSquadController < ActionController::Base
2
+ def tests
3
+ load Rails.root.join(TestSquad.test_directory, 'test_squad.rb').to_s
4
+ render TestSquad.configuration.framework
5
+ end
6
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>Ember: <%= TestSquad.app_class_name %></title>
6
+ <%= stylesheet_link_tag 'qunit', 'test_squad/ember' %>
7
+ </head>
8
+ <body>
9
+ <div id="qunit"></div>
10
+ <div id="qunit-fixture"></div>
11
+ <div id="ember-testing-container"><div id="ember-testing"></div></div>
12
+ <%= javascript_include_tag 'qunit', 'test_squad/qunit-phantom', 'test_helper' %>
13
+ </body>
14
+ </html>
@@ -0,0 +1,15 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>Jasmine: <%= TestSquad.app_class_name %></title>
6
+
7
+ <%= favicon_link_tag 'jasmine/jasmine_favicon.png' %>
8
+ <%= stylesheet_link_tag 'jasmine/jasmine' %>
9
+ <%= javascript_include_tag 'jasmine/jasmine', 'jasmine/jasmine-html', 'test_squad/jasmine-phantom', 'jasmine/boot', 'spec_helper' %>
10
+ </head>
11
+
12
+ <body>
13
+ <div id="jasmine-fixture"></div>
14
+ </body>
15
+ </html>
@@ -0,0 +1,11 @@
1
+ <html>
2
+ <head>
3
+ <meta charset="utf-8">
4
+ <title>Mocha: <%= TestSquad.app_class_name %></title>
5
+ <%= stylesheet_link_tag 'mocha' %>
6
+ </head>
7
+ <body>
8
+ <div id="mocha"></div>
9
+ <%= javascript_include_tag 'mocha', 'test_squad/mocha-reporter', 'spec_helper' %>
10
+ </body>
11
+ </html>
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>QUnit: <%= TestSquad.app_class_name %></title>
6
+ <%= stylesheet_link_tag 'qunit' %>
7
+ </head>
8
+ <body>
9
+ <div id="qunit"></div>
10
+ <div id="qunit-fixture"></div>
11
+ <%= javascript_include_tag 'qunit', 'test_squad/qunit-phantom', 'test_helper' %>
12
+ </body>
13
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,5 @@
1
+ Rails.application.routes.draw do
2
+ unless Rails.env.production?
3
+ get 'tests' => 'test_squad#tests', format: false, as: false
4
+ end
5
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Generates the JavaScript test directory.
3
+
4
+ Example:
5
+ rails generate squad:install -f qunit
6
+
7
+ This will create:
8
+ {spec,test}/javascript
@@ -0,0 +1,86 @@
1
+ class TestSquad::InstallGenerator < Rails::Generators::Base
2
+ source_root File.expand_path('../templates', __FILE__)
3
+
4
+ class_option :framework,
5
+ type: 'string',
6
+ desc: 'Select the JavaScript framework. Can be jasmine, qunit, mocha or ember.',
7
+ aliases: '-f',
8
+ required: true
9
+
10
+ def generate
11
+ send "generate_#{options[:framework]}"
12
+ end
13
+
14
+ def generate_defaults
15
+ add_source 'https://rails-assets.org'
16
+ empty_directory test_directory
17
+ template 'test_squad.rb.erb', "#{test_directory}/test_squad.rb"
18
+ end
19
+
20
+ private
21
+
22
+ def test_directory
23
+ TestSquad.test_directory
24
+ end
25
+
26
+ def app_name
27
+ app_class_name.underscore
28
+ end
29
+
30
+ def app_class_name
31
+ TestSquad.app_class_name
32
+ end
33
+
34
+ def generate_qunit
35
+ empty_directory "#{test_directory}/#{app_name}"
36
+ create_file "#{test_directory}/#{app_name}/.keep"
37
+ template 'qunit/test_helper.js.erb', "#{test_directory}/test_helper.js"
38
+ copy_file 'qunit/answer_test.js', "#{test_directory}/#{app_name}/answer_test.js"
39
+
40
+ gem_group :development, :test do
41
+ gem 'rails-assets-qunit'
42
+ end
43
+ end
44
+
45
+ def generate_jasmine
46
+ empty_directory "#{test_directory}/#{app_name}"
47
+ create_file "#{test_directory}/#{app_name}/.keep"
48
+ template 'jasmine/spec_helper.js.erb', "#{test_directory}/spec_helper.js"
49
+ copy_file 'jasmine/answer_spec.js', "#{test_directory}/#{app_name}/answer_spec.js"
50
+ end
51
+
52
+ def generate_mocha
53
+ empty_directory "#{test_directory}/#{app_name}"
54
+ create_file "#{test_directory}/#{app_name}/.keep"
55
+ template 'mocha/spec_helper.js.erb', "#{test_directory}/spec_helper.js"
56
+ copy_file 'mocha/answer_spec.js', "#{test_directory}/#{app_name}/answer_spec.js"
57
+
58
+ gem_group :development, :test do
59
+ gem 'rails-assets-mocha'
60
+ gem 'rails-assets-expect'
61
+ end
62
+ end
63
+
64
+ def generate_ember
65
+ empty_directory "#{test_directory}/unit"
66
+ copy_file 'ember/router_test.js', "#{test_directory}/unit/router_test.js"
67
+
68
+ empty_directory "#{test_directory}/routes"
69
+ create_file "#{test_directory}/routes/.keep"
70
+
71
+ empty_directory "#{test_directory}/components"
72
+ create_file "#{test_directory}/components/.keep"
73
+
74
+ empty_directory "#{test_directory}/views"
75
+ create_file "#{test_directory}/views/.keep"
76
+
77
+ empty_directory "#{test_directory}/models"
78
+ create_file "#{test_directory}/models/.keep"
79
+
80
+ template 'ember/test_helper.js.erb', "#{test_directory}/test_helper.js"
81
+
82
+ gem_group :development, :test do
83
+ gem 'rails-assets-qunit'
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,11 @@
1
+ module('Router', {setup: function(){
2
+ App.reset();
3
+ }});
4
+
5
+ test('root route', function() {
6
+ visit('/');
7
+
8
+ andThen(function(){
9
+ equal(currentRouteName(), 'index');
10
+ });
11
+ });
@@ -0,0 +1,15 @@
1
+ //= require application
2
+ //= require_self
3
+ //= require_tree ./components
4
+ //= require_tree ./models
5
+ //= require_tree ./routes
6
+ //= require_tree ./unit
7
+ //= require_tree ./views
8
+
9
+ // Set the application.
10
+ App = <%= app_class_name %>;
11
+
12
+ // Set up Ember testing.
13
+ App.rootElement = '#ember-testing';
14
+ App.setupForTesting();
15
+ App.injectTestHelpers();
@@ -0,0 +1,6 @@
1
+ describe('The answer to life the universe and everything', function(){
2
+ it('is 42', function(){
3
+ var answer = 42;
4
+ expect(answer).toEqual(42);
5
+ });
6
+ });
@@ -0,0 +1,3 @@
1
+ //= require application
2
+ //= require_self
3
+ //= require_tree ./<%= app_name %>
@@ -0,0 +1,6 @@
1
+ describe('The answer to life the universe and everything', function(){
2
+ it('is 42', function(){
3
+ var answer = 42;
4
+ expect(answer).to.eql(42);
5
+ });
6
+ });
@@ -0,0 +1,12 @@
1
+ //= require application
2
+ //= require expect
3
+ //= require_self
4
+ //= require_tree ./<%= app_name %>
5
+
6
+ mocha.setup('bdd');
7
+ mocha.checkLeaks();
8
+ mocha.globals(['jQuery']);
9
+ mocha.reporter(mocha.TestSquad);
10
+ window.onload = function(){
11
+ mocha.run();
12
+ };
@@ -0,0 +1,6 @@
1
+ module('The answer to life the universe and everything');
2
+
3
+ test('the answer is 42', function() {
4
+ var answer = 42;
5
+ equal(answer, 42);
6
+ });
@@ -0,0 +1,3 @@
1
+ //= require application
2
+ //= require_self
3
+ //= require_tree ./<%= app_name %>
@@ -0,0 +1,5 @@
1
+ TestSquad.configure do |config|
2
+ # Set the testing framework.
3
+ # Can be jasmine, qunit, mocha or ember.
4
+ config.framework = '<%= options[:framework] %>'
5
+ end
@@ -0,0 +1,39 @@
1
+ desc 'Run JavaScript tests'
2
+ task :test_squad do
3
+ ENV['RAILS_ENV'] = 'test'
4
+ ENV['RACK_ENV'] = 'test'
5
+
6
+ require './config/environment'
7
+ require 'stringio'
8
+
9
+ phantomjs_bin = ENV.fetch('PHANTOMJS_BIN', 'phantomjs')
10
+ port = ENV.fetch('PORT', 50000)
11
+ host = ENV.fetch('HOST', 'localhost')
12
+ path = ENV.fetch('TEST_PATH', '/tests')
13
+ timeout = ENV.fetch('TIMEOUT', '10')
14
+ log = ENV.fetch('LOG', 'false')
15
+ url = File.join("http://#{host}:#{port}", path)
16
+ logger = Logger.new(StringIO.new)
17
+
18
+ handler = Rack::Handler.pick(['puma', 'thin', 'webrick'])
19
+
20
+ Rails.configuration.logger = logger
21
+
22
+ thread = Thread.new {
23
+ handler.run Rails.application,
24
+ Port: port,
25
+ Host: host,
26
+ Logger: logger,
27
+ AccessLog: []
28
+ }
29
+
30
+ thread.abort_on_exception = true
31
+
32
+ system phantomjs_bin,
33
+ File.expand_path('../../../phantomjs/runner.js', __FILE__),
34
+ url,
35
+ timeout,
36
+ log
37
+
38
+ exit $?.exitstatus
39
+ end
data/lib/terminal.png ADDED
Binary file
data/lib/test_squad.rb ADDED
@@ -0,0 +1,26 @@
1
+ require 'test_squad/engine'
2
+ require 'ostruct'
3
+
4
+ module TestSquad
5
+ def self.configuration
6
+ @configuration ||= OpenStruct.new
7
+ end
8
+
9
+ def self.configure(&block)
10
+ configuration.tap(&block)
11
+ end
12
+
13
+ def self.app_class_name
14
+ Rails.application.class.name.split('::').first
15
+ end
16
+
17
+ def self.test_directory
18
+ @test_directory ||= begin
19
+ if Rails.root.join('spec').exist?
20
+ 'spec/javascript'
21
+ else
22
+ 'test/javascript'
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,36 @@
1
+ module TestSquad
2
+ class Engine < ::Rails::Engine
3
+ initializer 'test_squad' do
4
+ next unless %w[development test].include?(Rails.env)
5
+
6
+ config = Rails.application.config
7
+
8
+ config.assets.paths += [
9
+ Rails.root.join(TestSquad.test_directory).to_s
10
+ ]
11
+
12
+ config.assets.precompile += %W[
13
+ test_helper.js
14
+ spec_helper.js
15
+
16
+ test_squad/qunit-phantom.js
17
+ test_squad/jasmine-phantom.js
18
+ test_squad/mocha-phantom.js
19
+ test_squad/ember.css
20
+ test_squad/mocha-reporter.js
21
+
22
+ qunit.css
23
+ qunit.js
24
+
25
+ jasmine/jasmine_favicon.png
26
+ jasmine/jasmine.js
27
+ jasmine/jasmine.css
28
+ jasmine/jasmine-html.js
29
+ jasmine/boot.js
30
+
31
+ mocha.js
32
+ mocha.css
33
+ ]
34
+ end
35
+ end
36
+ end