Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

initial test suite

  • Loading branch information...
commit 20c97b1c227119a20881a9b354fb441f6fc16d5a 1 parent 313e103
Jonathan Vingiano authored October 05, 2011
2  Gemfile
... ...
@@ -1,3 +1,3 @@
1 1
 source :rubygems
2 2
 
3  
-gem 'jasmine', :group => :development
  3
+gem 'jasmine'
35  Gemfile.lock
... ...
@@ -0,0 +1,35 @@
  1
+GEM
  2
+  remote: http://rubygems.org/
  3
+  specs:
  4
+    childprocess (0.2.2)
  5
+      ffi (~> 1.0.6)
  6
+    diff-lcs (1.1.3)
  7
+    ffi (1.0.9)
  8
+    jasmine (1.1.0)
  9
+      jasmine-core (>= 1.1.0)
  10
+      rack (>= 1.1)
  11
+      rspec (>= 1.3.1)
  12
+      selenium-webdriver (>= 0.1.3)
  13
+    jasmine-core (1.1.0)
  14
+    json_pure (1.6.1)
  15
+    rack (1.3.4)
  16
+    rspec (2.6.0)
  17
+      rspec-core (~> 2.6.0)
  18
+      rspec-expectations (~> 2.6.0)
  19
+      rspec-mocks (~> 2.6.0)
  20
+    rspec-core (2.6.4)
  21
+    rspec-expectations (2.6.0)
  22
+      diff-lcs (~> 1.1.2)
  23
+    rspec-mocks (2.6.0)
  24
+    rubyzip (0.9.4)
  25
+    selenium-webdriver (2.7.0)
  26
+      childprocess (>= 0.2.1)
  27
+      ffi (>= 1.0.7)
  28
+      json_pure
  29
+      rubyzip
  30
+
  31
+PLATFORMS
  32
+  ruby
  33
+
  34
+DEPENDENCIES
  35
+  jasmine
9  Rakefile
... ...
@@ -0,0 +1,9 @@
  1
+
  2
+begin
  3
+  require 'jasmine'
  4
+  load 'jasmine/tasks/jasmine.rake'
  5
+rescue LoadError
  6
+  task :jasmine do
  7
+    abort "Jasmine is not available. In order to run jasmine, you must: (sudo) gem install jasmine"
  8
+  end
  9
+end
4  spec/css/testSuite.css
... ...
@@ -0,0 +1,4 @@
  1
+p:hover {
  2
+    color: red !important;
  3
+    text-shadow: none !important;
  4
+  }
289  spec/javascripts/helpers/jasmine-jquery-1.3.1.js
... ...
@@ -0,0 +1,289 @@
  1
+
  2
+var readFixtures = function() {
  3
+  return jasmine.getFixtures().proxyCallTo_('read', arguments);
  4
+};
  5
+
  6
+var preloadFixtures = function() {
  7
+  jasmine.getFixtures().proxyCallTo_('preload', arguments);
  8
+};
  9
+
  10
+var loadFixtures = function() {
  11
+  jasmine.getFixtures().proxyCallTo_('load', arguments);
  12
+};
  13
+
  14
+var setFixtures = function(html) {
  15
+  jasmine.getFixtures().set(html);
  16
+};
  17
+
  18
+var sandbox = function(attributes) {
  19
+  return jasmine.getFixtures().sandbox(attributes);
  20
+};
  21
+
  22
+var spyOnEvent = function(selector, eventName) {
  23
+  jasmine.JQuery.events.spyOn(selector, eventName);
  24
+}
  25
+
  26
+jasmine.getFixtures = function() {
  27
+  return jasmine.currentFixtures_ = jasmine.currentFixtures_ || new jasmine.Fixtures();
  28
+};
  29
+
  30
+jasmine.Fixtures = function() {
  31
+  this.containerId = 'jasmine-fixtures';
  32
+  this.fixturesCache_ = {};
  33
+  this.fixturesPath = 'spec/javascripts/fixtures';
  34
+};
  35
+
  36
+jasmine.Fixtures.prototype.set = function(html) {
  37
+  this.cleanUp();
  38
+  this.createContainer_(html);
  39
+};
  40
+
  41
+jasmine.Fixtures.prototype.preload = function() {
  42
+  this.read.apply(this, arguments);
  43
+};
  44
+
  45
+jasmine.Fixtures.prototype.load = function() {
  46
+  this.cleanUp();
  47
+  this.createContainer_(this.read.apply(this, arguments));
  48
+};
  49
+
  50
+jasmine.Fixtures.prototype.read = function() {
  51
+  var htmlChunks = [];
  52
+
  53
+  var fixtureUrls = arguments;
  54
+  for(var urlCount = fixtureUrls.length, urlIndex = 0; urlIndex < urlCount; urlIndex++) {
  55
+    htmlChunks.push(this.getFixtureHtml_(fixtureUrls[urlIndex]));
  56
+  }
  57
+
  58
+  return htmlChunks.join('');
  59
+};
  60
+
  61
+jasmine.Fixtures.prototype.clearCache = function() {
  62
+  this.fixturesCache_ = {};
  63
+};
  64
+
  65
+jasmine.Fixtures.prototype.cleanUp = function() {
  66
+  jQuery('#' + this.containerId).remove();
  67
+};
  68
+
  69
+jasmine.Fixtures.prototype.sandbox = function(attributes) {
  70
+  var attributesToSet = attributes || {};
  71
+  return jQuery('<div id="sandbox" />').attr(attributesToSet);
  72
+};
  73
+
  74
+jasmine.Fixtures.prototype.createContainer_ = function(html) {
  75
+  var container;
  76
+  if(html instanceof jQuery) {
  77
+    container = jQuery('<div id="' + this.containerId + '" />');
  78
+    container.html(html);
  79
+  } else {
  80
+    container = '<div id="' + this.containerId + '">' + html + '</div>'
  81
+  }
  82
+  jQuery('body').append(container);
  83
+};
  84
+
  85
+jasmine.Fixtures.prototype.getFixtureHtml_ = function(url) {  
  86
+  if (typeof this.fixturesCache_[url] == 'undefined') {
  87
+    this.loadFixtureIntoCache_(url);
  88
+  }
  89
+  return this.fixturesCache_[url];
  90
+};
  91
+
  92
+jasmine.Fixtures.prototype.loadFixtureIntoCache_ = function(relativeUrl) {
  93
+  var self = this;
  94
+  var url = this.fixturesPath.match('/$') ? this.fixturesPath + relativeUrl : this.fixturesPath + '/' + relativeUrl;
  95
+  jQuery.ajax({
  96
+    async: false, // must be synchronous to guarantee that no tests are run before fixture is loaded
  97
+    cache: false,
  98
+    dataType: 'html',
  99
+    url: url,
  100
+    success: function(data) {
  101
+      self.fixturesCache_[relativeUrl] = data;
  102
+    },
  103
+    error: function(jqXHR, status, errorThrown) {
  104
+        throw Error('Fixture could not be loaded: ' + url + ' (status: ' + status + ', message: ' + errorThrown.message + ')');
  105
+    }
  106
+  });
  107
+};
  108
+
  109
+jasmine.Fixtures.prototype.proxyCallTo_ = function(methodName, passedArguments) {
  110
+  return this[methodName].apply(this, passedArguments);
  111
+};
  112
+
  113
+
  114
+jasmine.JQuery = function() {};
  115
+
  116
+jasmine.JQuery.browserTagCaseIndependentHtml = function(html) {
  117
+  return jQuery('<div/>').append(html).html();
  118
+};
  119
+
  120
+jasmine.JQuery.elementToString = function(element) {
  121
+  return jQuery('<div />').append(element.clone()).html();
  122
+};
  123
+
  124
+jasmine.JQuery.matchersClass = {};
  125
+
  126
+(function(namespace) {
  127
+  var data = {
  128
+    spiedEvents: {},
  129
+    handlers:    []
  130
+  };
  131
+
  132
+  namespace.events = {
  133
+    spyOn: function(selector, eventName) {
  134
+      var handler = function(e) {
  135
+        data.spiedEvents[[selector, eventName]] = e;
  136
+      };
  137
+      jQuery(selector).bind(eventName, handler);
  138
+      data.handlers.push(handler);
  139
+    },
  140
+
  141
+    wasTriggered: function(selector, eventName) {
  142
+      return !!(data.spiedEvents[[selector, eventName]]);
  143
+    },
  144
+
  145
+    cleanUp: function() {
  146
+      data.spiedEvents = {};
  147
+      data.handlers    = [];
  148
+    }
  149
+  }
  150
+})(jasmine.JQuery);
  151
+
  152
+(function(){
  153
+  var jQueryMatchers = {
  154
+    toHaveClass: function(className) {
  155
+      return this.actual.hasClass(className);
  156
+    },
  157
+
  158
+    toBeVisible: function() {
  159
+      return this.actual.is(':visible');
  160
+    },
  161
+
  162
+    toBeHidden: function() {
  163
+      return this.actual.is(':hidden');
  164
+    },
  165
+
  166
+    toBeSelected: function() {
  167
+      return this.actual.is(':selected');
  168
+    },
  169
+
  170
+    toBeChecked: function() {
  171
+      return this.actual.is(':checked');
  172
+    },
  173
+
  174
+    toBeEmpty: function() {
  175
+      return this.actual.is(':empty');
  176
+    },
  177
+
  178
+    toExist: function() {
  179
+      return this.actual.size() > 0;
  180
+    },
  181
+
  182
+    toHaveAttr: function(attributeName, expectedAttributeValue) {
  183
+      return hasProperty(this.actual.attr(attributeName), expectedAttributeValue);
  184
+    },
  185
+
  186
+    toHaveId: function(id) {
  187
+      return this.actual.attr('id') == id;
  188
+    },
  189
+
  190
+    toHaveHtml: function(html) {
  191
+      return this.actual.html() == jasmine.JQuery.browserTagCaseIndependentHtml(html);
  192
+    },
  193
+
  194
+    toHaveText: function(text) {
  195
+      if (text && jQuery.isFunction(text.test)) {
  196
+        return text.test(this.actual.text());
  197
+      } else {
  198
+        return this.actual.text() == text;
  199
+      }
  200
+    },
  201
+
  202
+    toHaveValue: function(value) {
  203
+      return this.actual.val() == value;
  204
+    },
  205
+
  206
+    toHaveData: function(key, expectedValue) {
  207
+      return hasProperty(this.actual.data(key), expectedValue);
  208
+    },
  209
+
  210
+    toBe: function(selector) {
  211
+      return this.actual.is(selector);
  212
+    },
  213
+
  214
+    toContain: function(selector) {
  215
+      return this.actual.find(selector).size() > 0;
  216
+    },
  217
+
  218
+    toBeDisabled: function(selector){
  219
+      return this.actual.is(':disabled');
  220
+    },
  221
+
  222
+    // tests the existence of a specific event binding
  223
+    toHandle: function(eventName) {
  224
+      var events = this.actual.data("events");
  225
+      return events && events[eventName].length > 0;
  226
+    },
  227
+    
  228
+    // tests the existence of a specific event binding + handler
  229
+    toHandleWith: function(eventName, eventHandler) {
  230
+      var stack = this.actual.data("events")[eventName];
  231
+      var i;
  232
+      for (i = 0; i < stack.length; i++) {
  233
+        if (stack[i].handler == eventHandler) {
  234
+          return true;
  235
+        }
  236
+      }
  237
+      return false;
  238
+    }
  239
+  };
  240
+
  241
+  var hasProperty = function(actualValue, expectedValue) {
  242
+    if (expectedValue === undefined) {
  243
+      return actualValue !== undefined;
  244
+    }
  245
+    return actualValue == expectedValue;
  246
+  };
  247
+
  248
+  var bindMatcher = function(methodName) {
  249
+    var builtInMatcher = jasmine.Matchers.prototype[methodName];
  250
+
  251
+    jasmine.JQuery.matchersClass[methodName] = function() {
  252
+      if (this.actual instanceof jQuery) {
  253
+        var result = jQueryMatchers[methodName].apply(this, arguments);
  254
+        this.actual = jasmine.JQuery.elementToString(this.actual);
  255
+        return result;
  256
+      }
  257
+
  258
+      if (builtInMatcher) {
  259
+        return builtInMatcher.apply(this, arguments);
  260
+      }
  261
+
  262
+      return false;
  263
+    };
  264
+  };
  265
+
  266
+  for(var methodName in jQueryMatchers) {
  267
+    bindMatcher(methodName);
  268
+  }
  269
+})();
  270
+
  271
+beforeEach(function() {
  272
+  this.addMatchers(jasmine.JQuery.matchersClass);
  273
+  this.addMatchers({
  274
+    toHaveBeenTriggeredOn: function(selector) {
  275
+      this.message = function() {
  276
+        return [
  277
+          "Expected event " + this.actual + " to have been triggered on" + selector,
  278
+          "Expected event " + this.actual + " not to have been triggered on" + selector
  279
+        ];
  280
+      };
  281
+      return jasmine.JQuery.events.wasTriggered(selector, this.actual);
  282
+    }
  283
+  })
  284
+});
  285
+
  286
+afterEach(function() {
  287
+  jasmine.getFixtures().cleanUp();
  288
+  jasmine.JQuery.events.cleanUp();
  289
+});
61  spec/javascripts/okshadowSpec.js
... ...
@@ -0,0 +1,61 @@
  1
+ describe('okshadow', function() {
  2
+     var testDiv;
  3
+     
  4
+     beforeEach(function(){
  5
+         
  6
+         this.addMatchers({
  7
+             toHaveBoxShadow: function() {
  8
+                 if (this.actual.css('boxShadow') && this.actual.css('boxShadow') !== 'none') return true;
  9
+             },
  10
+             toHaveTextShadow: function() {
  11
+                 if (this.actual.css('text-shadow') && this.actual.css('textShadow') !== 'none') return true;
  12
+             }
  13
+         });
  14
+     });
  15
+     
  16
+     describe('with default options', function () {        
  17
+         beforeEach(function(){
  18
+             jasmine.getFixtures().set('<div id="test"></div>');
  19
+             testDiv = $('#test').okshadow();
  20
+         });
  21
+         
  22
+         it('adds box-shadow', function () {
  23
+             expect(testDiv).toHaveBoxShadow();
  24
+         });
  25
+
  26
+     });
  27
+     
  28
+     describe('allows developers to control options', function() {
  29
+         beforeEach(function(){
  30
+             jasmine.getFixtures().set('<div id="test"><p>OKFocus.</p></div>');
  31
+         });
  32
+         
  33
+         it('text shadow', function() {
  34
+             testDiv = $('#test p').okshadow({
  35
+                 textShadow: true
  36
+             });
  37
+             expect(testDiv).toHaveTextShadow();
  38
+         });         
  39
+
  40
+
  41
+         it('color', function(){
  42
+             testText = $('#test p').okshadow({
  43
+                 color: 'rgb(4,2,0)'
  44
+             });
  45
+             expect(/4, 2, 0/.test(testText.css('box-shadow'))).toBe(true);
  46
+         });
  47
+         
  48
+         it('transparency', function(){
  49
+             testText = $('#test p').okshadow({
  50
+                 transparent: true
  51
+             });
  52
+
  53
+             expect(/0, 0, 0, 0/.test(testText.css('color'))).toBe(true);
  54
+
  55
+         });
  56
+
  57
+
  58
+
  59
+     });
  60
+     
  61
+ });
76  spec/javascripts/support/jasmine.yml
... ...
@@ -0,0 +1,76 @@
  1
+# src_files
  2
+#
  3
+# Return an array of filepaths relative to src_dir to include before jasmine specs.
  4
+# Default: []
  5
+#
  6
+# EXAMPLE:
  7
+#
  8
+# src_files:
  9
+#   - lib/source1.js
  10
+#   - lib/source2.js
  11
+#   - dist/**/*.js
  12
+#
  13
+src_files:
  14
+    - spec/javascripts/vendor/jquery.js
  15
+    - src/okshadow-1.0.js
  16
+    
  17
+
  18
+# stylesheets
  19
+#
  20
+# Return an array of stylesheet filepaths relative to src_dir to include before jasmine specs.
  21
+# Default: []
  22
+#
  23
+# EXAMPLE:
  24
+#
  25
+# stylesheets:
  26
+#   - css/style.css
  27
+#   - stylesheets/*.css
  28
+#
  29
+stylesheets:
  30
+    - spec/css/testSuite.css
  31
+
  32
+# helpers
  33
+#
  34
+# Return an array of filepaths relative to spec_dir to include before jasmine specs.
  35
+# Default: ["helpers/**/*.js"]
  36
+#
  37
+# EXAMPLE:
  38
+#
  39
+# helpers:
  40
+#   - helpers/**/*.js
  41
+#
  42
+helpers:
  43
+
  44
+# spec_files
  45
+#
  46
+#  Return an array of filepaths relative to spec_dir to include.
  47
+# Default: ["**/*[sS]pec.js"]
  48
+#
  49
+# EXAMPLE:
  50
+#
  51
+# spec_files:
  52
+#   - **/*[sS]pec.js
  53
+#
  54
+spec_files:
  55
+
  56
+# src_dir
  57
+#
  58
+# Source directory path. Your src_files must be returned relative to this path. Will use root if left blank.
  59
+# Default: project root
  60
+#
  61
+# EXAMPLE:
  62
+#
  63
+# src_dir: public
  64
+#
  65
+src_dir: 
  66
+
  67
+# spec_dir
  68
+#
  69
+# Spec directory path. Your spec_files must be returned relative to this path.
  70
+# Default: spec/javascripts
  71
+#
  72
+# EXAMPLE:
  73
+#
  74
+# spec_dir: spec/javascripts
  75
+#
  76
+spec_dir:
23  spec/javascripts/support/jasmine_config.rb
... ...
@@ -0,0 +1,23 @@
  1
+module Jasmine
  2
+  class Config
  3
+
  4
+    # Add your overrides or custom config code here
  5
+
  6
+  end
  7
+end
  8
+
  9
+
  10
+# Note - this is necessary for rspec2, which has removed the backtrace
  11
+module Jasmine
  12
+  class SpecBuilder
  13
+    def declare_spec(parent, spec)
  14
+      me = self
  15
+      example_name = spec["name"]
  16
+      @spec_ids << spec["id"]
  17
+      backtrace = @example_locations[parent.description + " " + example_name]
  18
+      parent.it example_name, {} do
  19
+        me.report_spec(spec["id"])
  20
+      end
  21
+    end
  22
+  end
  23
+end
32  spec/javascripts/support/jasmine_runner.rb
... ...
@@ -0,0 +1,32 @@
  1
+$:.unshift(ENV['JASMINE_GEM_PATH']) if ENV['JASMINE_GEM_PATH'] # for gem testing purposes
  2
+
  3
+require 'rubygems'
  4
+require 'jasmine'
  5
+jasmine_config_overrides = File.expand_path(File.join(File.dirname(__FILE__), 'jasmine_config.rb'))
  6
+require jasmine_config_overrides if File.exist?(jasmine_config_overrides)
  7
+if Jasmine::rspec2?
  8
+  require 'rspec'
  9
+else
  10
+  require 'spec'
  11
+end
  12
+
  13
+jasmine_config = Jasmine::Config.new
  14
+spec_builder = Jasmine::SpecBuilder.new(jasmine_config)
  15
+
  16
+should_stop = false
  17
+
  18
+if Jasmine::rspec2?
  19
+  RSpec.configuration.after(:suite) do
  20
+    spec_builder.stop if should_stop
  21
+  end
  22
+else
  23
+  Spec::Runner.configure do |config|
  24
+    config.after(:suite) do
  25
+      spec_builder.stop if should_stop
  26
+    end
  27
+  end
  28
+end
  29
+
  30
+spec_builder.start
  31
+should_stop = true
  32
+spec_builder.declare_suites
9,047  spec/javascripts/vendor/jquery.js
9047 additions, 0 deletions not shown

0 notes on commit 20c97b1

Please sign in to comment.
Something went wrong with that request. Please try again.