test_squad 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
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
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8558931146248c1acab78a3a1927c68d27fac067
4
+ data.tar.gz: f852e96638b6e735c0380aef4067c5660d207a5e
5
+ SHA512:
6
+ metadata.gz: 7f4084ca3a280d2fc46c8a152e28832b507cb2f49899650ad07ab17d7c55c01737add06d838afbce4680d92fb9e5600d927ee3ed3320f0555946502ff58a04dc
7
+ data.tar.gz: 8793c9502f41d95046be6aed10cdcfbaee7176f0b30b6e371bd4228bd275f44d84202962d238a91f1927f33273b9968041abd1f142be486597f50f6a054feb56
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2015 Nando Vieira
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.md ADDED
@@ -0,0 +1,194 @@
1
+ # TestSquad
2
+
3
+ Running JavaScript tests on your Rails app, the easy way.
4
+
5
+ - Supports QUnit, Ember.js, Mocha and Jasmine
6
+ - Go headless with [Phantom.js](http://phantomjs.org)
7
+ - Colored output
8
+ - Asset pipeline support
9
+
10
+ ## Installation
11
+
12
+ Add these lines to your application's Gemfile:
13
+
14
+ ```ruby
15
+ group :development, :test do
16
+ gem 'test_squad'
17
+ end
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ ```console
23
+ $ bundle
24
+ ```
25
+
26
+ ## Usage
27
+
28
+ After installing TestSquad, generate your tests skeleton. The generator will detect if you're using RSpec or TestUnit and will generate the `javascript` directory basead on that detection. Just use the command `rails generate test_squad:install --framework FRAMEWORK`.
29
+
30
+ ```console
31
+ $ rails generate test_squad:install --framework jasmine
32
+ create test/javascript/squad_sample
33
+ create test/javascript/squad_sample/.keep
34
+ create test/javascript/spec_helper.js
35
+ source https://rails-assets.org
36
+ exist test/javascript
37
+ create test/javascript/test_squad.rb
38
+ ```
39
+
40
+ ## Running tests
41
+
42
+ You can run your tests with `rake test_squad`. You can also visit `http://localhost:3000/tests` for in-browser testing.
43
+
44
+ ![Jasmine](https://github.com/fnando/test_squad/raw/master/screenshots/jasmine.png)
45
+
46
+ ![Mocha](https://github.com/fnando/test_squad/raw/master/screenshots/mocha.png)
47
+
48
+ ![QUnit](https://github.com/fnando/test_squad/raw/master/screenshots/qunit.png)
49
+
50
+ ![Terminal](https://github.com/fnando/test_squad/raw/master/screenshots/terminal.png)
51
+
52
+ ### Configure Ember
53
+
54
+ When using the Ember framework, you must configure your application name. It'll default to your Rails application name.
55
+
56
+ ```javascript
57
+ //= require application
58
+ //= require_self
59
+ //= require_tree ./components
60
+ //= require_tree ./models
61
+ //= require_tree ./routes
62
+ //= require_tree ./unit
63
+ //= require_tree ./views
64
+
65
+ // Set the application.
66
+ App = SquadSample;
67
+
68
+ // Set up Ember testing.
69
+ App.rootElement = '#ember-testing';
70
+ App.setupForTesting();
71
+ App.injectTestHelpers();
72
+ ```
73
+
74
+ To disable all Ember logging, add the following line to `test_helper.js`, just before the `//= require application` line.
75
+
76
+ ```javascript
77
+ //= require ./logging
78
+ ```
79
+
80
+ Then create the file `spec/javascript/logging.js` with this content:
81
+
82
+ ```javascript
83
+ Ember = {ENV: {
84
+ LOG_TRANSITIONS: false,
85
+ LOG_VIEW_LOOKUPS: false,
86
+ LOG_ACTIVE_GENERATION: false,
87
+ LOG_RESOLVER: false,
88
+ LOG_TRANSITIONS: false,
89
+ LOG_TRANSITIONS_INTERNAL: false,
90
+ LOG_VERSION: false
91
+ }};
92
+ ```
93
+
94
+ ### Configure Mocha
95
+
96
+ By default, Mocha is configured with [expect.js](https://github.com/Automattic/expect.js). You can use different libraries like [should.js](https://github.com/visionmedia/should.js) or [chai](http://chaijs.com/).
97
+
98
+ Just add the dependency to your `Gemfile`. Use `rails-assets-chai` or `rails-assets-should`:
99
+
100
+ ```ruby
101
+ source 'https://rubygems.org'
102
+ source 'https://rails-assets.org'
103
+
104
+ gem 'rails', '4.2.0'
105
+ gem 'sass-rails', '~> 5.0'
106
+ gem 'uglifier', '>= 1.3.0'
107
+
108
+ gem 'ember-rails'
109
+ gem 'rails-assets-jquery'
110
+
111
+ group :development, :test do
112
+ gem 'test_squad', path: '../../test_squad'
113
+ gem 'rails-assets-mocha'
114
+ gem 'rails-assets-chai'
115
+ end
116
+ ```
117
+
118
+ Install the dependency with `bundle install`. Then require the library on `{test/spec}/javascript/spec_helper.js`.
119
+
120
+ ```javascript
121
+ //= require application
122
+ //= require chai
123
+ //= require_self
124
+ //= require_tree ./squad_sample
125
+
126
+ var assert = chai.assert;
127
+
128
+ mocha.setup('bdd');
129
+ mocha.checkLeaks();
130
+ mocha.globals(['jQuery']);
131
+ mocha.reporter(mocha.TestSquad);
132
+ window.onload = function(){
133
+ mocha.run();
134
+ };
135
+ ```
136
+
137
+ ## Troubleshooting
138
+
139
+ If you have a catch-all route, add the following line to your `config/routes.rb` file. This will be required if you configure Ember.js to use `history.pushState`.
140
+
141
+ ```ruby
142
+ get :tests, to: 'test_squad#tests' unless Rails.env.production?
143
+ ```
144
+
145
+ Otherwise you won't be able to to run your in-browser tests.
146
+
147
+ ## Configuration
148
+
149
+ The rake task accepts some env variables.
150
+
151
+ - `HOST`: the binding host. Defaults to `localhost`.
152
+ - `PORT`: the server port. Defaults to `50000`.
153
+ - `TIMEOUT`: how much time a test can take. Defaults to `10` (seconds).
154
+ - `LOG`: set if console messages should be logged. Defaults to `false`.
155
+ - `PHANTOMJS_BIN`: set the PhantomJS binary. Defaults to `phantomjs`.
156
+
157
+ ## Contributing
158
+
159
+ Before starting, create an issue asking if it'd be a useful/wanted feature. This will avoid wasting your time.
160
+
161
+ 1. Fork it ( http://github.com/fnando/test_squad/fork )
162
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
163
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
164
+ 4. Push to the branch (`git push origin my-new-feature`)
165
+ 5. Create new Pull Request
166
+
167
+ Remember:
168
+
169
+ - Don't mess with versioning.
170
+ - Follow the code style already present.
171
+ - Opening an issue asking if your feature/change will be welcomed it's recommended. That way you don't waste your time.
172
+
173
+ ## License
174
+
175
+ (The MIT License)
176
+
177
+ Permission is hereby granted, free of charge, to any person obtaining
178
+ a copy of this software and associated documentation files (the
179
+ 'Software'), to deal in the Software without restriction, including
180
+ without limitation the rights to use, copy, modify, merge, publish,
181
+ distribute, sublicense, and/or sell copies of the Software, and to
182
+ permit persons to whom the Software is furnished to do so, subject to
183
+ the following conditions:
184
+
185
+ The above copyright notice and this permission notice shall be
186
+ included in all copies or substantial portions of the Software.
187
+
188
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
189
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
190
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
191
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
192
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
193
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
194
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ Bundler::GemHelper.install_tasks
8
+
9
+ require 'rake/testtask'
10
+
11
+ Rake::TestTask.new(:test) do |t|
12
+ t.libs << 'lib'
13
+ t.libs << 'test'
14
+ t.pattern = 'test/**/*_test.rb'
15
+ t.verbose = false
16
+ end
17
+
18
+ task default: :test
@@ -0,0 +1,67 @@
1
+ (function() {
2
+ window.jasmine = jasmineRequire.core(jasmineRequire);
3
+ jasmineRequire.html(jasmine);
4
+ jasmineRequire.phantom(jasmine);
5
+ var env = jasmine.getEnv();
6
+ var jasmineInterface = jasmineRequire.interface(jasmine, env);
7
+
8
+ if (typeof window == 'undefined' && typeof exports == 'object') {
9
+ extend(exports, jasmineInterface);
10
+ } else {
11
+ extend(window, jasmineInterface);
12
+ }
13
+
14
+ var queryString = new jasmine.QueryString({
15
+ getWindowLocation: function() { return window.location; }
16
+ });
17
+
18
+ var catchingExceptions = queryString.getParam('catch');
19
+ env.catchExceptions(typeof catchingExceptions === 'undefined' ? true : catchingExceptions);
20
+
21
+ var htmlReporter = new jasmine.HtmlReporter({
22
+ env: env,
23
+ onRaiseExceptionsClick: function() { queryString.setParam('catch', !env.catchingExceptions()); },
24
+ getContainer: function() { return document.body; },
25
+ createElement: function() { return document.createElement.apply(document, arguments); },
26
+ createTextNode: function() { return document.createTextNode.apply(document, arguments); },
27
+ timer: new jasmine.Timer()
28
+ });
29
+
30
+ var phantomReporter = new jasmine.PhantomReporter({
31
+ env: env,
32
+ onRaiseExceptionsClick: function() { queryString.setParam('catch', !env.catchingExceptions()); },
33
+ timer: new jasmine.Timer()
34
+ });
35
+
36
+ env.addReporter(jasmineInterface.jsApiReporter);
37
+ env.addReporter(htmlReporter);
38
+ env.addReporter(phantomReporter);
39
+
40
+ var specFilter = new jasmine.HtmlSpecFilter({
41
+ filterString: function() { return queryString.getParam('spec'); }
42
+ });
43
+
44
+ env.specFilter = function(spec) {
45
+ return specFilter.matches(spec.getFullName());
46
+ };
47
+
48
+ window.setTimeout = window.setTimeout;
49
+ window.setInterval = window.setInterval;
50
+ window.clearTimeout = window.clearTimeout;
51
+ window.clearInterval = window.clearInterval;
52
+
53
+ var currentWindowOnload = window.onload;
54
+
55
+ window.onload = function() {
56
+ if (currentWindowOnload) {
57
+ currentWindowOnload();
58
+ }
59
+ htmlReporter.initialize();
60
+ env.execute();
61
+ };
62
+
63
+ function extend(destination, source) {
64
+ for (var property in source) destination[property] = source[property];
65
+ return destination;
66
+ }
67
+ }());
@@ -0,0 +1,85 @@
1
+ (function(){
2
+ jasmineRequire.phantom = function(j$) {
3
+ if (!navigator.userAgent.match(/phantomjs/i)) {
4
+ j$.PhantomReporter = function() { /* noop */ };
5
+ } else {
6
+ j$.PhantomReporter = jasmineRequire.PhantomReporter();
7
+ }
8
+ };
9
+
10
+ jasmineRequire.PhantomReporter = function() {
11
+ function PhantomReporter(options) {
12
+ var stats = {
13
+ passes: 0,
14
+ fails: 0,
15
+ pending: 0,
16
+ elapsed: 0,
17
+ assertions: 0,
18
+ tests: 0
19
+ };
20
+
21
+ var start;
22
+
23
+ this.jasmineStarted = function() {
24
+ start = new Date().getTime();
25
+ };
26
+
27
+ this.jasmineDone = function() {
28
+ stats.elapsed = new Date().getTime() - start;
29
+
30
+ callPhantom({
31
+ name: 'end',
32
+ stats: stats
33
+ });
34
+ };
35
+
36
+ this.specStarted = function(result) {
37
+ stats.tests += 1;
38
+
39
+ callPhantom({
40
+ name: 'test start',
41
+ title: result.description
42
+ });
43
+ };
44
+
45
+ this.specDone = function(result) {
46
+ var pending = result.status === 'pending';
47
+ var passed = result.status === 'passed';
48
+ var failed = result.status === 'failed';
49
+ var error, assertion;
50
+
51
+ stats.assertions += result.failedExpectations.length;
52
+ stats.assertions += result.passedExpectations.length;
53
+ stats.pending += (pending ? 1 : 0);
54
+ stats.passes += (passed ? 1 : 0);
55
+ stats.fails += (failed ? 1 : 0);
56
+
57
+ if (failed) {
58
+ assertion = result.failedExpectations[0];
59
+ error = assertion.stack.replace(/^\s*/gm, ' ');
60
+ error = error.replace(/^\s+at .*?assets\/jasmine\/(jasmine|boot).*?\.js.*?$/mg, '');
61
+ error = error.replace(/\n+$/, '');
62
+ }
63
+
64
+ callPhantom({
65
+ name: 'test end',
66
+ title: result.description,
67
+ passed: passed,
68
+ pending: pending,
69
+ failure: error
70
+ });
71
+ };
72
+
73
+ this.suiteStarted = function(result) {
74
+ callPhantom({
75
+ name: 'suite start',
76
+ title: result.description
77
+ });
78
+ };
79
+
80
+ return this;
81
+ }
82
+
83
+ return PhantomReporter;
84
+ };
85
+ })();
@@ -0,0 +1,104 @@
1
+ Mocha.reporters.PhantomJS = function(runner) {
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;
16
+
17
+ runner.on('pass', function(test){
18
+ stats.passes += 1;
19
+ });
20
+
21
+ runner.on('fail', function(test, err){
22
+ stats.fails += 1;
23
+ });
24
+
25
+ runner.on('pending', function(suite){
26
+ stats.pending += 1;
27
+ });
28
+
29
+ runner.on('start', function(test){
30
+ start = new Date().getTime();
31
+ });
32
+
33
+ runner.on('end', function(){
34
+ stats.elapsed = new Date().getTime() - start;
35
+ callPhantom({
36
+ name: 'end',
37
+ stats: stats
38
+ });
39
+ });
40
+
41
+ runner.on('test', function(test){
42
+ stats.tests += 1;
43
+
44
+ callPhantom({
45
+ name: 'test start',
46
+ title: test.title
47
+ });
48
+ });
49
+
50
+ runner.on('test end', function(test){
51
+ if (test.state === 'failed') {
52
+ var error = test.err.stack || test.err.toString();
53
+
54
+ // FF / Opera do not add the message
55
+ if (!~error.indexOf(test.err.message)) {
56
+ error = test.err.message + '\n' + error;
57
+ }
58
+
59
+ // <=IE7 stringifies to [Object Error]. Since it can be overloaded, we
60
+ // check for the result of the stringifying.
61
+ if ('[object Error]' == error) {
62
+ error = test.err.message;
63
+ }
64
+
65
+ // Safari doesn't give you a stack. Let's at least provide a source line.
66
+ if (!test.err.stack && test.err.sourceURL && test.err.line !== undefined) {
67
+ error += "\n(" + test.err.sourceURL + ":" + test.err.line + ")";
68
+ }
69
+
70
+ error = error.replace(/^\s+at .*?assets\/mocha\/.*?\.js.*?$/mg, '');
71
+ error = error.replace(/^\s+at .*?assets\/expect\/.*?\.js.*?$/mg, '');
72
+ error = error.replace(/^\s+at .*?assets\/should\/.*?\.js.*?$/mg, '');
73
+ error = error.replace(/^\s+at .*?assets\/chai\/.*?\.js.*?$/mg, '');
74
+ error = error.replace(/\n+$/, '');
75
+ }
76
+
77
+ callPhantom({
78
+ name: 'test end',
79
+ title: test.title,
80
+ passed: test.state === 'passed',
81
+ pending: test.pending,
82
+ failure: error
83
+ });
84
+ });
85
+
86
+ runner.on('suite', function(suite){
87
+ callPhantom({
88
+ name: 'suite start',
89
+ title: suite.title
90
+ });
91
+ });
92
+
93
+ runner.on('suite end', function(suite){
94
+ callPhantom({
95
+ name: 'suite end',
96
+ title: suite.title
97
+ });
98
+ });
99
+ };
100
+
101
+ mocha.TestSquad = function(runner) {
102
+ new Mocha.reporters.HTML(runner);
103
+ new Mocha.reporters.PhantomJS(runner);
104
+ };