Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

initial version of jasmine.async

  • Loading branch information...
commit 1d89c0ec288119753d92ee01b093020e1efee106 0 parents
Derick Bailey authored
8 .gitignore
@@ -0,0 +1,8 @@
+.DS_Store
+*.swp
+*.swo
+*.orig
+tmp/
+ext/
+node_modules/
+npm-debug.log
1  .rvmrc
@@ -0,0 +1 @@
+rvm use 1.9.3@jasmine.async --create
8 Gemfile
@@ -0,0 +1,8 @@
+source :rubygems
+
+gem 'jasmine'
+gem 'rb-fsevent'
+gem 'guard'
+gem 'guard-process'
+gem 'guard-compass'
+gem 'rake'
72 Gemfile.lock
@@ -0,0 +1,72 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ addressable (2.3.2)
+ childprocess (0.3.5)
+ ffi (~> 1.0, >= 1.0.6)
+ chunky_png (1.2.6)
+ compass (0.12.2)
+ chunky_png (~> 1.2)
+ fssm (>= 0.2.7)
+ sass (~> 3.1)
+ diff-lcs (1.1.3)
+ ffi (1.0.11)
+ fssm (0.2.9)
+ guard (1.3.2)
+ listen (>= 0.4.2)
+ thor (>= 0.14.6)
+ guard-compass (0.0.6)
+ compass (>= 0.10.5)
+ guard (>= 0.2.1)
+ guard-process (1.0.3)
+ ffi (~> 1.0.9)
+ guard (>= 0.4.2)
+ spoon (~> 0.0.1)
+ jasmine (1.2.1)
+ jasmine-core (>= 1.2.0)
+ rack (~> 1.0)
+ rspec (>= 1.3.1)
+ selenium-webdriver (>= 0.1.3)
+ jasmine-core (1.2.0)
+ libwebsocket (0.1.5)
+ addressable
+ listen (0.4.7)
+ rb-fchange (~> 0.0.5)
+ rb-fsevent (~> 0.9.1)
+ rb-inotify (~> 0.8.8)
+ multi_json (1.3.6)
+ rack (1.4.1)
+ rake (0.9.2.2)
+ rb-fchange (0.0.5)
+ ffi
+ rb-fsevent (0.9.1)
+ rb-inotify (0.8.8)
+ ffi (>= 0.5.0)
+ rspec (2.11.0)
+ rspec-core (~> 2.11.0)
+ rspec-expectations (~> 2.11.0)
+ rspec-mocks (~> 2.11.0)
+ rspec-core (2.11.1)
+ rspec-expectations (2.11.2)
+ diff-lcs (~> 1.1.3)
+ rspec-mocks (2.11.2)
+ rubyzip (0.9.9)
+ sass (3.2.1)
+ selenium-webdriver (2.25.0)
+ childprocess (>= 0.2.5)
+ libwebsocket (~> 0.1.3)
+ multi_json (~> 1.0)
+ rubyzip
+ spoon (0.0.1)
+ thor (0.16.0)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ guard
+ guard-compass
+ guard-process
+ jasmine
+ rake
+ rb-fsevent
2  Guardfile
@@ -0,0 +1,2 @@
+guard 'process', :name => 'Jasmine', :command => 'rake jasmine', :stop_signal => "TERM" do
+end
9 Rakefile
@@ -0,0 +1,9 @@
+
+begin
+ require 'jasmine'
+ load 'jasmine/tasks/jasmine.rake'
+rescue LoadError
+ task :jasmine do
+ abort "Jasmine is not available. In order to run jasmine, you must: (sudo) gem install jasmine"
+ end
+end
59 grunt.js
@@ -0,0 +1,59 @@
+/*global module:false*/
+module.exports = function(grunt) {
+
+ grunt.loadNpmTasks('grunt-rigger');
+
+ // Project configuration.
+ grunt.initConfig({
+ meta: {
+ version: '0.1.0',
+ banner: '// Jasmine.Async, v<%= meta.version %>\n' +
+ '// Copyright (c)<%= grunt.template.today("yyyy") %> Derick Bailey, Muted Solutions, LLC.\n' +
+ '// Distributed under MIT license\n' +
+ '// http://github.com/derickbailey/jasmine.async'
+ },
+
+ lint: {
+ files: ['src/jasmine.async.js']
+ },
+
+ rig: {
+ build: {
+ src: ['<banner:meta.banner>', 'src/jasmine.async.js'],
+ dest: 'lib/jasmine.async.js'
+ }
+ },
+
+ min: {
+ standard: {
+ src: ['<banner:meta.banner>', '<config:rig.build.dest>'],
+ dest: 'lib/jasmine.async.min.js'
+ }
+ },
+
+ jshint: {
+ options: {
+ curly: true,
+ eqeqeq: true,
+ immed: false,
+ latedef: true,
+ newcap: true,
+ noarg: true,
+ sub: true,
+ undef: true,
+ boss: true,
+ eqnull: true,
+ browser: true
+ },
+ globals: {
+ jQuery: true,
+ _: true
+ }
+ },
+ uglify: {}
+ });
+
+ // Default task.
+ grunt.registerTask('default', 'lint rig min');
+
+};
58 package.json
@@ -0,0 +1,58 @@
+{
+ "name": "Jasmine.Async",
+ "description": "Make Jasmine's asynchronous testing suck less.",
+ "version": "0.1.0",
+ "homepage": "https://github.com/derickbailey/jasmine.async",
+ "keywords": [
+ "jasmine",
+ "async",
+ "unit",
+ "test",
+ "browser"
+ ],
+
+ "licenses": [
+ {
+ "type": "MIT",
+ "url": "https://github.com/derickbailey/jasmine.async/blob/master/readme.md"
+ }
+ ],
+
+ "author": {
+ "name": "Derick Bailey",
+ "email": "derickbailey@gmail.com",
+ "web": "http://derickbailey.lostechies.com"
+ },
+
+ "bugs": {
+ "web": "https://github.com/derickbailey/jasmine.async/issues"
+ },
+
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/derickbailey/jasmine.async.git"
+ },
+
+ "github": "https://github.com/derickbailey/jasmine.async",
+
+ "developmentDependencies": {
+ "grunt": "*",
+ "grunt-rigger": "*"
+ },
+
+ "volo": {
+ "url": "https://raw.github.com/derickbailey/jasmine.async/v{version}/lib/amd/jasmine.async.js",
+ "dependencies": {
+ }
+ },
+
+ "jam":{
+ "dependencies": {
+ },
+ "main": "lib/amd/jasmine.async.js",
+ "include": [
+ "lib/amd/jasmine.async.js",
+ "readme.md"
+ ]
+ }
+}
90 readme.md
@@ -0,0 +1,90 @@
+# Jasmine.Async
+
+Make Jasmine's asynchronous testing suck less.
+
+## About Jasmine.Async
+
+I love [Jasmine](http://pivotal.github.com/jasmine/). It's a great BDD-style testing framework
+for browser based JavaScript, and my preferred tool for doing
+that kind of work. But the asynchronous testing story in Jasmine
+is painful at best.
+
+Thus, Jasmine.Async was born out of frustration and little bit
+of jealousy in how easy it is to do async tests with [Mocha](http://visionmedia.github.com/mocha/).
+
+## Basic Usage
+
+```js
+describe("an async spec", function(){
+
+ // set up the async spec
+ var async = new AsyncSpec(this);
+
+ // run an async setup
+ async.beforeEach(function(done){
+ doSomething();
+
+ // simulate async stuff and wait 10ms
+ setTimeout(function(){
+
+ // more code here
+ doMoreStuff();
+
+ // when the async stuff is done, call `done()`
+ done();
+
+ }, 10);
+ });
+
+ // run an async cleanup
+ async.afterEach(function(done){
+ // simulate async cleanup
+ setTimeout(function(){
+
+ done(); // done with the async stuff
+
+ }, 10);
+ });
+
+ // run an async expectation
+ async.it("did stuff", function(done){
+
+ // simulate async code again
+ setTimeout(function(){
+
+ expect(1).toBe(1);
+
+ // all async stuff done, and spec asserted
+ done();
+
+ });
+
+ });
+
+});
+```
+
+## Legal Mumbo-Jumbo (MIT License)
+
+Copyright &copy;2012 Muted Solutions, LLC. All Rights Reserved.
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the Software, and to permit persons
+to whom the Software is furnished to do so, subject to the
+following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
9 spec/javascripts/helpers/SpecHelper.js
@@ -0,0 +1,9 @@
+beforeEach(function() {
+ this.addMatchers({
+ toBePlaying: function(expectedSong) {
+ var player = this.actual;
+ return player.currentlyPlayingSong === expectedSong &&
+ player.isPlaying;
+ }
+ });
+});
30 spec/javascripts/jasmine.async.spec.js
@@ -0,0 +1,30 @@
+describe("jasmine.async", function(){
+ var wait = 0,
+ beforeEachCompleted;
+
+ var async = new AsyncSpec(this);
+
+ beforeEach(function(){
+ beforeEachCompleted = false;
+ });
+
+ async.beforeEach(function(done){
+ setTimeout(function(){
+ beforeEachCompleted = true;
+
+ done();
+ }, wait);
+ });
+
+ async.it("completes the async test", function(done){
+ setTimeout(function(){
+ done();
+ }, wait);
+ });
+
+ async.afterEach(function(done){
+ setTimeout(function(){
+ done();
+ }, wait);
+ });
+});
73 spec/javascripts/support/jasmine.yml
@@ -0,0 +1,73 @@
+# src_files
+#
+# Return an array of filepaths relative to src_dir to include before jasmine specs.
+# Default: []
+#
+# EXAMPLE:
+#
+# src_files:
+# - lib/source1.js
+# - lib/source2.js
+# - dist/**/*.js
+#
+src_files:
+ - src/jasmine.async.js
+
+# stylesheets
+#
+# Return an array of stylesheet filepaths relative to src_dir to include before jasmine specs.
+# Default: []
+#
+# EXAMPLE:
+#
+# stylesheets:
+# - css/style.css
+# - stylesheets/*.css
+#
+stylesheets:
+
+# helpers
+#
+# Return an array of filepaths relative to spec_dir to include before jasmine specs.
+# Default: ["helpers/**/*.js"]
+#
+# EXAMPLE:
+#
+# helpers:
+# - helpers/**/*.js
+#
+helpers:
+
+# spec_files
+#
+# Return an array of filepaths relative to spec_dir to include.
+# Default: ["**/*[sS]pec.js"]
+#
+# EXAMPLE:
+#
+# spec_files:
+# - **/*[sS]pec.js
+#
+spec_files:
+
+# src_dir
+#
+# Source directory path. Your src_files must be returned relative to this path. Will use root if left blank.
+# Default: project root
+#
+# EXAMPLE:
+#
+# src_dir: public
+#
+src_dir:
+
+# spec_dir
+#
+# Spec directory path. Your spec_files must be returned relative to this path.
+# Default: spec/javascripts
+#
+# EXAMPLE:
+#
+# spec_dir: spec/javascripts
+#
+spec_dir:
47 src/jasmine.async.js
@@ -0,0 +1,47 @@
+AsyncSpec = (function(global){
+
+ // Private Methods
+ // ---------------
+
+ function runAsync(block){
+ return function(){
+ var done = false;
+ var complete = function(){ done = true; }
+
+ runs(function(){
+ block(complete);
+ });
+
+ waitsFor(function(){
+ return done;
+ });
+ }
+ }
+
+ // Constructor Function
+ // --------------------
+
+ function AsyncSpec(spec){
+ this.spec = spec;
+ };
+
+ // Public API
+ // ----------
+
+ AsyncSpec.prototype.beforeEach = function(block){
+ this.spec.beforeEach(runAsync(block));
+ };
+
+ AsyncSpec.prototype.afterEach = function(block){
+ this.spec.afterEach(runAsync(block));
+ };
+
+ AsyncSpec.prototype.it = function(description, block){
+ // For some reason, `it` is not attached to the current
+ // test suite, so it has to be called from the global
+ // context.
+ global.it(description, runAsync(block));
+ };
+
+ return AsyncSpec;
+})(this);
Please sign in to comment.
Something went wrong with that request. Please try again.