jaspec 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +25 -0
  3. data/.travis.yml +4 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +82 -0
  7. data/Rakefile +13 -0
  8. data/bin/jaspec +6 -0
  9. data/jaspec.gemspec +24 -0
  10. data/lib/jaspec.rb +9 -0
  11. data/lib/jaspec/cli.rb +20 -0
  12. data/lib/jaspec/runner.rb +35 -0
  13. data/lib/jaspec/runner/phantom.js +99 -0
  14. data/lib/jaspec/runner/runner.html +83 -0
  15. data/lib/jaspec/version.rb +3 -0
  16. data/spec/javascripts/barSpec.coffee +5 -0
  17. data/spec/javascripts/fooSpec.js +9 -0
  18. data/spec/javascripts/globalSpec.coffee +3 -0
  19. data/spec/javascripts/nonAmdSpec.coffee +4 -0
  20. data/spec/javascripts/stubbableSpec.coffee +7 -0
  21. data/spec/src/bar.coffee +2 -0
  22. data/spec/src/foo.js +5 -0
  23. data/spec/src/nonAmd.js +1 -0
  24. data/spec/src/stubbable.js +5 -0
  25. data/vendor/coffee-script-1.8.0.js +12 -0
  26. data/vendor/cs-0.5.0.js +317 -0
  27. data/vendor/jasmine-2.1.3/MIT.LICENSE +20 -0
  28. data/vendor/jasmine-2.1.3/SpecRunner.html +26 -0
  29. data/vendor/jasmine-2.1.3/lib/jasmine-2.1.3/boot.js +120 -0
  30. data/vendor/jasmine-2.1.3/lib/jasmine-2.1.3/console.js +190 -0
  31. data/vendor/jasmine-2.1.3/lib/jasmine-2.1.3/jasmine-html.js +404 -0
  32. data/vendor/jasmine-2.1.3/lib/jasmine-2.1.3/jasmine.css +62 -0
  33. data/vendor/jasmine-2.1.3/lib/jasmine-2.1.3/jasmine.js +2908 -0
  34. data/vendor/jasmine-2.1.3/lib/jasmine-2.1.3/jasmine_favicon.png +0 -0
  35. data/vendor/jasmine-2.1.3/spec/PlayerSpec.js +58 -0
  36. data/vendor/jasmine-2.1.3/spec/SpecHelper.js +15 -0
  37. data/vendor/jasmine-2.1.3/src/Player.js +22 -0
  38. data/vendor/jasmine-2.1.3/src/Song.js +7 -0
  39. data/vendor/requirejs-2.1.15.min.js +36 -0
  40. metadata +134 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a5e7a8197c96a47c7fd54f02e816898e64debb71
4
+ data.tar.gz: 2a8be4e40167491dd740504a69a4225752cde816
5
+ SHA512:
6
+ metadata.gz: b915f71e545b71f3c798785bd681ce0781f555cb08a72839fa4507a5a4bae0e65f191a479f9d9281157286dc44e73f21856892ceae095e99132bedba7bc5ec3c
7
+ data.tar.gz: 7d3d40ef06ff06d33f21ef575636aad6895a028b2c27a364c8f070e7fe742c0b67f70010260caa6f04856588e3dca09ae99406c0b7d04a107913a2b2cb87e067
data/.gitignore ADDED
@@ -0,0 +1,25 @@
1
+ *.gem
2
+ *.rbc
3
+ *.swp
4
+ *.swo
5
+ *.DS_Store*
6
+ .bundle
7
+ .config
8
+ .yardoc
9
+ Gemfile.lock
10
+ InstalledFiles
11
+ _yardoc
12
+ coverage
13
+ doc/
14
+ lib/bundler/man
15
+ pkg
16
+ rdoc
17
+ spec/reports
18
+ test/tmp
19
+ test/version_tmp
20
+ tmp
21
+ *.bundle
22
+ *.so
23
+ *.o
24
+ *.a
25
+ mkmf.log
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - ruby-head
4
+ - jruby-head
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in jaspec.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Kevin Gisi
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,82 @@
1
+ # Jaspec
2
+
3
+ Jaspec is a dirt-simple Jasmine spec runner. It runs off of [Jasmine](http://jasmine.github.io/) standalone, [RequireJS](http://requirejs.org/), and [PhantomJS](http://phantomjs.org/). It doesn't care about sprockets; it doesn't start a web server; it does something really really simple:
4
+
5
+ It runs your specs.
6
+
7
+ ## Installation
8
+
9
+ You can install jaspec via:
10
+
11
+ $ gem install jaspec
12
+
13
+ Or, if you're using it with an application that includes a Gemfile, add this line:
14
+
15
+ gem 'jaspec'
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ ## Usage
22
+
23
+ Running your specs is nice and easy. Just execute:
24
+
25
+ $ jaspec specs/myCoolSpec.js
26
+
27
+ Or, if you're using CoffeeScript:
28
+
29
+ $ jaspec specs/myCoolerSpec.coffee
30
+
31
+ Finally, if you want to run across an entire directory:
32
+
33
+ $ jaspec specs/
34
+
35
+ This will execute against all \*Spec.js, and \*Spec.coffee files within that directory.
36
+
37
+ ## Writing Your Specs
38
+
39
+ You can format your specs normally:
40
+
41
+ ```coffeescript
42
+ describe 'A useless spec', ->
43
+ it 'should be useless', ->
44
+ expect(true).toBe true
45
+ ```
46
+
47
+ ...but you'll get a LOT more power out of Jaspec if you use AMD-style definitions (RequireJS will include source files that way!)
48
+
49
+ ```coffeescript
50
+ define ['../myLibrary/foo.js'], (foo) ->
51
+ describe 'foo', ->
52
+ it 'should have a value of 5', ->
53
+ expect(foo.value).toBe 5
54
+ ```
55
+
56
+ You can use these dependencies to load non-AMD compliant JS, and stuff will still work!
57
+
58
+ ```coffeescript
59
+ define ['../vendor/jQuery.js'], ->
60
+ # do stuff with $
61
+ ```
62
+
63
+ Best of all, since each spec runs in isolation, you can pre-define your dependencies, in order to provide useful stubs and mocks.
64
+
65
+ ```coffeescript
66
+ define 'foo', -> 'Fake foo'
67
+
68
+ define ['../thingThatNeedsFoo.js'], (thing) ->
69
+ describe 'thing', ->
70
+ it 'should have a stubbed foo', ->
71
+ expect(thing.foo).toBe 'Fake Foo'
72
+ ```
73
+
74
+ Get testing!
75
+
76
+ ## Contributing
77
+
78
+ 1. Fork it ( https://github.com/gisikw/jaspec/fork )
79
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
80
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
81
+ 4. Push to the branch (`git push origin my-new-feature`)
82
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ $LOAD_PATH.unshift File.expand_path("#{File.dirname(__FILE__)}/lib")
2
+
3
+ require "bundler/gem_tasks"
4
+ require "jaspec"
5
+
6
+ namespace :spec do
7
+ desc "Run all the jaspect tests"
8
+ task :jaspec do
9
+ Jaspec::Runner.run_all(File.join(File.dirname(__FILE__),'spec','javascripts')) || exit(1)
10
+ end
11
+ end
12
+
13
+ task :default => 'spec:jaspec'
data/bin/jaspec ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'jaspec'
5
+
6
+ Jaspec::Cli.new.process(ARGV)
data/jaspec.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'jaspec/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "jaspec"
8
+ spec.version = Jaspec::VERSION
9
+ spec.authors = ["Kevin Gisi"]
10
+ spec.email = ["kevin@kevingisi.com"]
11
+ spec.summary = %q{A stupid simple Jasmine spec-runner for AMD modules}
12
+ spec.homepage = ""
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.6"
21
+ spec.add_development_dependency "rake"
22
+
23
+ spec.add_dependency 'phantomjs'
24
+ end
data/lib/jaspec.rb ADDED
@@ -0,0 +1,9 @@
1
+ jaspec_files = [
2
+ 'version',
3
+ 'runner',
4
+ 'cli'
5
+ ]
6
+
7
+ jaspec_files.each do |file|
8
+ require File.join('jaspec', file)
9
+ end
data/lib/jaspec/cli.rb ADDED
@@ -0,0 +1,20 @@
1
+ module Jaspec
2
+ class Cli
3
+ def process(argv)
4
+ @argv = argv
5
+ if @argv.size > 0
6
+ run
7
+ else
8
+ print_help
9
+ end
10
+ end
11
+
12
+ def print_help
13
+ puts "Usage: jaspec [file or directory]"
14
+ end
15
+
16
+ def run
17
+ Jaspec::Runner.run File.expand_path(@argv[0])
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,35 @@
1
+ module Jaspec
2
+ class Runner
3
+ PHANTOM_RUNNER = File.expand_path('runner/phantom.js', File.dirname(__FILE__))
4
+ HTML_RUNNER = File.expand_path('runner/runner.html', File.dirname(__FILE__))
5
+
6
+ class << self
7
+
8
+ def run(spec)
9
+ if File.directory?(spec)
10
+ run_all(spec)
11
+ else
12
+ system("phantomjs #{PHANTOM_RUNNER} #{HTML_RUNNER} #{spec}")
13
+ end
14
+ end
15
+
16
+ def run_all(dir)
17
+ failures = []
18
+
19
+ Dir.glob(File.join(dir,'**','*Spec.{js,coffee}')).each do |spec|
20
+ failures << spec if !run(spec)
21
+ end
22
+
23
+ if failures.empty?
24
+ puts "\nAll specs passing. Badass!"
25
+ return true
26
+ else
27
+ puts "\n#{failures.length} failing spec file#{'s' if failures.length > 1}:"
28
+ puts failures.join("\n")
29
+ return false
30
+ end
31
+ end
32
+
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,99 @@
1
+ var
2
+ system = require('system'),
3
+ page = require('webpage').create(),
4
+ colorWrap,
5
+ interval,
6
+ timeout,
7
+ report,
8
+ yellow,
9
+ green,
10
+ file = system.args[2],
11
+ red;
12
+
13
+ colorWrap = function (code) {
14
+ return function (str) {
15
+ return '\033[' + code + 'm' + str + '\033[0m';
16
+ };
17
+ }
18
+
19
+ page.onConsoleMessage = function(msg) {
20
+ console.log(msg);
21
+ };
22
+
23
+ yellow = colorWrap(33);
24
+ green = colorWrap(32);
25
+ red = colorWrap(31);
26
+
27
+ report = function () {
28
+ var specs = page.evaluate(function () {
29
+ return jsApiReporter.specResults(0, jsApiReporter.specs().length);
30
+ });
31
+
32
+ if (specs.every(function (spec) { return spec.status === 'passed'; })) {
33
+ console.log(green(file));
34
+ page.close();
35
+ setTimeout(function () { phantom.exit(0); });
36
+ } else {
37
+ if (specs.some(function (spec) { return spec.status === 'failed'; })) {
38
+ console.log(red(file));
39
+ } else {
40
+ console.log(yellow(file));
41
+ }
42
+ specs.forEach(function (spec) {
43
+ if (spec.status === 'passed') {
44
+ console.log(green('- ' + spec.fullName));
45
+ } else if (spec.status === 'pending') {
46
+ console.log(yellow('- ' + spec.fullName));
47
+ } else {
48
+ console.log(red('- ' + spec.fullName));
49
+ }
50
+ });
51
+ page.close();
52
+ setTimeout(function () { phantom.exit(1); });
53
+ }
54
+ }
55
+
56
+ page.onInitialized = function () {
57
+ page.evaluate(function (file) {
58
+ document.addEventListener('DOMContentLoaded', function () {
59
+ window.callPhantom();
60
+ });
61
+ });
62
+ };
63
+
64
+ page.onCallback = function () {
65
+ var specsDone;
66
+
67
+ page.evaluate(function (file) {
68
+ window.runSpec(file);
69
+ }, file);
70
+
71
+ specsDone = function () {
72
+ return page.evaluate(function () {
73
+ return window.jsApiReporter && window.jsApiReporter.finished;
74
+ });
75
+ };
76
+
77
+ interval = setInterval(function () {
78
+ if (specsDone()) {
79
+ clearInterval(interval);
80
+ clearTimeout(timeout);
81
+ report();
82
+ }
83
+ });
84
+
85
+ timeout = setTimeout(function () {
86
+ clearInterval(interval);
87
+ console.log(red(file));
88
+ page.close();
89
+ setTimeout(function () { phantom.exit(1); });
90
+ }, 10000);
91
+ };
92
+
93
+ page.open(system.args[1], function (status) {
94
+ if (status !== 'success') {
95
+ console.log(red(file));
96
+ page.close();
97
+ setTimeout(function () { phantom.exit(1); });
98
+ }
99
+ });
@@ -0,0 +1,83 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>Jaspec Runner</title>
6
+ <link rel='shortcut icon' type='image/png' href='../../../vendor/jasmine-2.1.3/lib/jasmine-2.1.3/jasmine_favicon.png'>
7
+ <link rel='stylesheet' href='../../../vendor/jasmine-2.1.3/lib/jasmine-2.1.3/jasmine.css'>
8
+ <script src='../../../vendor/jasmine-2.1.3/lib/jasmine-2.1.3/jasmine.js'></script>
9
+ <script src='../../../vendor/jasmine-2.1.3/lib/jasmine-2.1.3/jasmine-html.js'></script>
10
+ <script src='../../../vendor/jasmine-2.1.3/lib/jasmine-2.1.3/console.js'></script>
11
+ <script src='../../../vendor/requirejs-2.1.15.min.js'></script>
12
+
13
+ <!-- Custom Jasmine Boot -->
14
+ <script>
15
+ window.jasmine = jasmineRequire.core(jasmineRequire);
16
+
17
+ jasmineRequire.html(jasmine);
18
+
19
+ var env = jasmine.getEnv();
20
+ var jasmineInterface = jasmineRequire.interface(jasmine, env);
21
+
22
+ if (typeof window == "undefined" && typeof exports == "object") {
23
+ extend(exports, jasmineInterface);
24
+ } else {
25
+ extend(window, jasmineInterface);
26
+ }
27
+
28
+ var queryString = new jasmine.QueryString({
29
+ getWindowLocation: function() { return window.location; }
30
+ });
31
+
32
+ var catchingExceptions = queryString.getParam("catch");
33
+ env.catchExceptions(typeof catchingExceptions === "undefined" ? true : catchingExceptions);
34
+
35
+ var htmlReporter = new jasmine.HtmlReporter({
36
+ env: env,
37
+ onRaiseExceptionsClick: function() { queryString.setParam("catch", !env.catchingExceptions()); },
38
+ getContainer: function() { return document.body; },
39
+ createElement: function() { return document.createElement.apply(document, arguments); },
40
+ createTextNode: function() { return document.createTextNode.apply(document, arguments); },
41
+ timer: new jasmine.Timer()
42
+ });
43
+
44
+ env.addReporter(jasmineInterface.jsApiReporter);
45
+ env.addReporter(htmlReporter);
46
+
47
+ var specFilter = new jasmine.HtmlSpecFilter({
48
+ filterString: function() { return queryString.getParam("spec"); }
49
+ });
50
+
51
+ env.specFilter = function(spec) {
52
+ return specFilter.matches(spec.getFullName());
53
+ };
54
+
55
+ window.setTimeout = window.setTimeout;
56
+ window.setInterval = window.setInterval;
57
+ window.clearTimeout = window.clearTimeout;
58
+ window.clearInterval = window.clearInterval;
59
+
60
+ var currentWindowOnload = window.onload;
61
+
62
+ function extend(destination, source) {
63
+ for (var property in source) destination[property] = source[property];
64
+ return destination;
65
+ }
66
+
67
+ require.config({
68
+ paths: {
69
+ 'coffee-script': '../../../vendor/coffee-script-1.8.0',
70
+ 'cs': '../../../vendor/cs-0.5.0'
71
+ }
72
+ });
73
+
74
+ window.runSpec = function(file) {
75
+ require([file.indexOf('.coffee') !== -1 ? 'cs!' + file : file], function () {
76
+ htmlReporter.initialize();
77
+ env.execute();
78
+ });
79
+ };
80
+
81
+ </script>
82
+ </head>
83
+ </html>