jasmine-jquery-rails 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in jasmine-jquery-rails.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Travis Jeffery
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,33 @@
1
+ # jasmine-jquery for Rails
2
+
3
+ jasmine-jquery via asset pipeline
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'jasmine-jquery-rails'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Add this line to your test manifest file:
16
+
17
+ //=require jasmine-jquery
18
+
19
+ Or directly include at `/assets/jasmine-jquery.js`
20
+
21
+ ## Usage
22
+
23
+ Read about jasmine-jquery [here](http://github.com/velesin/jasmine-jquery)
24
+
25
+ ## Contributing
26
+
27
+ jasmine-jquery-rails and jasmine-jquery are maintained by [Travis Jeffery](http://github.com/travisjeffery)
28
+
29
+ 1. Fork it
30
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
31
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
32
+ 4. Push to the branch (`git push origin my-new-feature`)
33
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,16 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/jasmine-jquery-rails/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Travis Jeffery"]
6
+ gem.email = ["travisjeffery@gmail.com"]
7
+ gem.summary = %q{jasmine-jquery via asset pipeline}
8
+ gem.homepage = "http://github.com/travisjeffery/jasmine-jquery-rails"
9
+
10
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
11
+ gem.files = `git ls-files`.split("\n")
12
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
13
+ gem.name = "jasmine-jquery-rails"
14
+ gem.require_paths = ["lib"]
15
+ gem.version = Jasmine::Jquery::Rails::VERSION
16
+ end
@@ -0,0 +1,10 @@
1
+ require "jasmine-jquery-rails/engine"
2
+ require "jasmine-jquery-rails/version"
3
+
4
+ module Jasmine
5
+ module Jquery
6
+ module Rails
7
+ # Your code goes here...
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ module Jasmine
2
+ module Jquery
3
+ module Rails
4
+ class Engine < ::Rails::Engine
5
+ # making class enables assets pipeline
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ module Jasmine
2
+ module Jquery
3
+ module Rails
4
+ VERSION = "1.3.1"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,306 @@
1
+ var readFixtures = function() {
2
+ return jasmine.getFixtures().proxyCallTo_('read', arguments);
3
+ };
4
+
5
+ var preloadFixtures = function() {
6
+ jasmine.getFixtures().proxyCallTo_('preload', arguments);
7
+ };
8
+
9
+ var loadFixtures = function() {
10
+ jasmine.getFixtures().proxyCallTo_('load', arguments);
11
+ };
12
+
13
+ var setFixtures = function(html) {
14
+ jasmine.getFixtures().set(html);
15
+ };
16
+
17
+ var sandbox = function(attributes) {
18
+ return jasmine.getFixtures().sandbox(attributes);
19
+ };
20
+
21
+ var spyOnEvent = function(selector, eventName) {
22
+ jasmine.JQuery.events.spyOn(selector, eventName);
23
+ };
24
+
25
+ jasmine.getFixtures = function() {
26
+ return jasmine.currentFixtures_ = jasmine.currentFixtures_ || new jasmine.Fixtures();
27
+ };
28
+
29
+ jasmine.Fixtures = function() {
30
+ this.containerId = 'jasmine-fixtures';
31
+ this.fixturesCache_ = {};
32
+ this.fixturesPath = 'spec/javascripts/fixtures';
33
+ };
34
+
35
+ jasmine.Fixtures.prototype.set = function(html) {
36
+ this.cleanUp();
37
+ this.createContainer_(html);
38
+ };
39
+
40
+ jasmine.Fixtures.prototype.preload = function() {
41
+ this.read.apply(this, arguments);
42
+ };
43
+
44
+ jasmine.Fixtures.prototype.load = function() {
45
+ this.cleanUp();
46
+ this.createContainer_(this.read.apply(this, arguments));
47
+ };
48
+
49
+ jasmine.Fixtures.prototype.read = function() {
50
+ var htmlChunks = [];
51
+
52
+ var fixtureUrls = arguments;
53
+ for(var urlCount = fixtureUrls.length, urlIndex = 0; urlIndex < urlCount; urlIndex++) {
54
+ htmlChunks.push(this.getFixtureHtml_(fixtureUrls[urlIndex]));
55
+ }
56
+
57
+ return htmlChunks.join('');
58
+ };
59
+
60
+ jasmine.Fixtures.prototype.clearCache = function() {
61
+ this.fixturesCache_ = {};
62
+ };
63
+
64
+ jasmine.Fixtures.prototype.cleanUp = function() {
65
+ jQuery('#' + this.containerId).remove();
66
+ };
67
+
68
+ jasmine.Fixtures.prototype.sandbox = function(attributes) {
69
+ var attributesToSet = attributes || {};
70
+ return jQuery('<div id="sandbox" />').attr(attributesToSet);
71
+ };
72
+
73
+ jasmine.Fixtures.prototype.createContainer_ = function(html) {
74
+ var container;
75
+ if(html instanceof jQuery) {
76
+ container = jQuery('<div id="' + this.containerId + '" />');
77
+ container.html(html);
78
+ } else {
79
+ container = '<div id="' + this.containerId + '">' + html + '</div>'
80
+ }
81
+ jQuery('body').append(container);
82
+ };
83
+
84
+ jasmine.Fixtures.prototype.getFixtureHtml_ = function(url) {
85
+ if (typeof this.fixturesCache_[url] == 'undefined') {
86
+ this.loadFixtureIntoCache_(url);
87
+ }
88
+ return this.fixturesCache_[url];
89
+ };
90
+
91
+ jasmine.Fixtures.prototype.loadFixtureIntoCache_ = function(relativeUrl) {
92
+ var url = this.fixturesPath.match('/$') ? this.fixturesPath + relativeUrl : this.fixturesPath + '/' + relativeUrl;
93
+ var request = new XMLHttpRequest();
94
+ request.open("GET", url + "?" + new Date().getTime(), false);
95
+ request.send(null);
96
+ this.fixturesCache_[relativeUrl] = request.responseText;
97
+ };
98
+
99
+ jasmine.Fixtures.prototype.proxyCallTo_ = function(methodName, passedArguments) {
100
+ return this[methodName].apply(this, passedArguments);
101
+ };
102
+
103
+
104
+ jasmine.JQuery = function() {};
105
+
106
+ jasmine.JQuery.browserTagCaseIndependentHtml = function(html) {
107
+ return jQuery('<div/>').append(html).html();
108
+ };
109
+
110
+ jasmine.JQuery.elementToString = function(element) {
111
+ return jQuery('<div />').append($(element).clone()).html();
112
+ };
113
+
114
+ jasmine.JQuery.matchersClass = {};
115
+
116
+ (function(namespace) {
117
+ var data = {
118
+ spiedEvents: {},
119
+ handlers: []
120
+ };
121
+
122
+ namespace.events = {
123
+ spyOn: function(selector, eventName) {
124
+ var handler = function(e) {
125
+ data.spiedEvents[[selector, eventName]] = e;
126
+ };
127
+ jQuery(selector).bind(eventName, handler);
128
+ data.handlers.push(handler);
129
+ },
130
+
131
+ wasTriggered: function(selector, eventName) {
132
+ return !!(data.spiedEvents[[selector, eventName]]);
133
+ },
134
+
135
+ wasPrevented: function(selector, eventName) {
136
+ return data.spiedEvents[[selector, eventName]].isDefaultPrevented();
137
+ },
138
+
139
+ cleanUp: function() {
140
+ data.spiedEvents = {};
141
+ data.handlers = [];
142
+ }
143
+ }
144
+ })(jasmine.JQuery);
145
+
146
+ (function(){
147
+ var jQueryMatchers = {
148
+ toHaveClass: function(className) {
149
+ return this.actual.hasClass(className);
150
+ },
151
+
152
+ toBeVisible: function() {
153
+ return this.actual.is(':visible');
154
+ },
155
+
156
+ toBeHidden: function() {
157
+ return this.actual.is(':hidden');
158
+ },
159
+
160
+ toBeSelected: function() {
161
+ return this.actual.is(':selected');
162
+ },
163
+
164
+ toBeChecked: function() {
165
+ return this.actual.is(':checked');
166
+ },
167
+
168
+ toBeEmpty: function() {
169
+ return this.actual.is(':empty');
170
+ },
171
+
172
+ toExist: function() {
173
+ return this.actual.size() > 0;
174
+ },
175
+
176
+ toHaveAttr: function(attributeName, expectedAttributeValue) {
177
+ return hasProperty(this.actual.attr(attributeName), expectedAttributeValue);
178
+ },
179
+
180
+ toHaveProp: function(propertyName, expectedPropertyValue) {
181
+ return hasProperty(this.actual.prop(propertyName), expectedPropertyValue);
182
+ },
183
+
184
+ toHaveId: function(id) {
185
+ return this.actual.attr('id') == id;
186
+ },
187
+
188
+ toHaveHtml: function(html) {
189
+ return this.actual.html() == jasmine.JQuery.browserTagCaseIndependentHtml(html);
190
+ },
191
+
192
+ toHaveText: function(text) {
193
+ var trimmedText = $.trim(this.actual.text());
194
+ if (text && jQuery.isFunction(text.test)) {
195
+ return text.test(trimmedText);
196
+ } else {
197
+ return trimmedText == text;
198
+ }
199
+ },
200
+
201
+ toHaveValue: function(value) {
202
+ return this.actual.val() == value;
203
+ },
204
+
205
+ toHaveData: function(key, expectedValue) {
206
+ return hasProperty(this.actual.data(key), expectedValue);
207
+ },
208
+
209
+ toBe: function(selector) {
210
+ return this.actual.is(selector);
211
+ },
212
+
213
+ toContain: function(selector) {
214
+ return this.actual.find(selector).size() > 0;
215
+ },
216
+
217
+ toBeDisabled: function(selector){
218
+ return this.actual.is(':disabled');
219
+ },
220
+
221
+ toBeFocused: function(selector) {
222
+ return this.actual.is(':focus');
223
+ },
224
+
225
+ // tests the existence of a specific event binding
226
+ toHandle: function(eventName) {
227
+ var events = this.actual.data("events");
228
+ return events && events[eventName].length > 0;
229
+ },
230
+
231
+ // tests the existence of a specific event binding + handler
232
+ toHandleWith: function(eventName, eventHandler) {
233
+ var stack = this.actual.data("events")[eventName];
234
+ var i;
235
+ for (i = 0; i < stack.length; i++) {
236
+ if (stack[i].handler == eventHandler) {
237
+ return true;
238
+ }
239
+ }
240
+ return false;
241
+ }
242
+ };
243
+
244
+ var hasProperty = function(actualValue, expectedValue) {
245
+ if (expectedValue === undefined) {
246
+ return actualValue !== undefined;
247
+ }
248
+ return actualValue == expectedValue;
249
+ };
250
+
251
+ var bindMatcher = function(methodName) {
252
+ var builtInMatcher = jasmine.Matchers.prototype[methodName];
253
+
254
+ jasmine.JQuery.matchersClass[methodName] = function() {
255
+ if (this.actual
256
+ && (this.actual instanceof jQuery
257
+ || jasmine.isDomNode(this.actual))) {
258
+ this.actual = $(this.actual);
259
+ var result = jQueryMatchers[methodName].apply(this, arguments);
260
+ this.actual = jasmine.JQuery.elementToString(this.actual);
261
+ return result;
262
+ }
263
+
264
+ if (builtInMatcher) {
265
+ return builtInMatcher.apply(this, arguments);
266
+ }
267
+
268
+ return false;
269
+ };
270
+ };
271
+
272
+ for(var methodName in jQueryMatchers) {
273
+ bindMatcher(methodName);
274
+ }
275
+ })();
276
+
277
+ beforeEach(function() {
278
+ this.addMatchers(jasmine.JQuery.matchersClass);
279
+ this.addMatchers({
280
+ toHaveBeenTriggeredOn: function(selector) {
281
+ this.message = function() {
282
+ return [
283
+ "Expected event " + this.actual + " to have been triggered on " + selector,
284
+ "Expected event " + this.actual + " not to have been triggered on " + selector
285
+ ];
286
+ };
287
+ return jasmine.JQuery.events.wasTriggered($(selector), this.actual);
288
+ }
289
+ });
290
+ this.addMatchers({
291
+ toHaveBeenPreventedOn: function(selector) {
292
+ this.message = function() {
293
+ return [
294
+ "Expected event " + this.actual + " to have been prevented on " + selector,
295
+ "Expected event " + this.actual + " not to have been prevented on " + selector
296
+ ];
297
+ };
298
+ return jasmine.JQuery.events.wasPrevented(selector, this.actual);
299
+ }
300
+ });
301
+ });
302
+
303
+ afterEach(function() {
304
+ jasmine.getFixtures().cleanUp();
305
+ jasmine.JQuery.events.cleanUp();
306
+ });
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jasmine-jquery-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.3.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Travis Jeffery
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-15 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description:
15
+ email:
16
+ - travisjeffery@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE
24
+ - README.md
25
+ - Rakefile
26
+ - jasmine-jquery-rails.gemspec
27
+ - lib/jasmine-jquery-rails.rb
28
+ - lib/jasmine-jquery-rails/engine.rb
29
+ - lib/jasmine-jquery-rails/version.rb
30
+ - vendor/assets/javascripts/jasmine-jquery.js
31
+ homepage: http://github.com/travisjeffery/jasmine-jquery-rails
32
+ licenses: []
33
+ post_install_message:
34
+ rdoc_options: []
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ! '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ requirements: []
50
+ rubyforge_project:
51
+ rubygems_version: 1.8.19
52
+ signing_key:
53
+ specification_version: 3
54
+ summary: jasmine-jquery via asset pipeline
55
+ test_files: []