oojs 0.0.4 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ # =require_tree ./oojspec_helpers
2
+
3
+ oojspec.assertions.add 'undefined', # simetric to 'toBeDefined'
4
+ assert: (@actual)-> @actual is undefined
5
+ assertMessage: 'Expected ${actual} to be undefined.'
6
+ refuteMessage: 'Expected ${actual} not to be undefined.'
7
+ expectation: 'toBeUndefined'
@@ -0,0 +1,26 @@
1
+ # =require modules
2
+
3
+ TIMEOUT = 500 # ms - Used to be 300, but FF was too slow
4
+ extendClass 'specs.oojspec.AjaxHelpers', ->
5
+ ajaxServer = null
6
+ initialize: (fakeAjaxServer, options = {})->
7
+ ajaxServer = fakeAjaxServer
8
+ ajaxSettings: -> ajaxServer.ajaxSettings()
9
+ waitsForAjaxRequest: (message = "An AJAX call was expected", \
10
+ timeout = @timeout or TIMEOUT, extraCondition)->
11
+ @waitsFor message, timeout, ->
12
+ ajaxServer.ajaxCallbacksQueue.length and (not extraCondition or extraCondition.call this)
13
+ waitsForAjaxRequestAnd: (condition, message, timeout)->
14
+ @waitsForAjaxRequest(message, timeout, condition)
15
+ nextRequest: (url, method, format)->
16
+ @checkRequestSettings(url, method, format)
17
+ ajaxServer.processNextRequest()
18
+ checkRequestSettings: (url, method, format)->
19
+ s = @ajaxSettings()
20
+ @expect(s.url).toBe url unless url is undefined
21
+ @expect(s.type).toBe method unless method is undefined
22
+ @expect(s.dataType).toBe format unless format is undefined
23
+ ignoreRequest: (url, method, format)->
24
+ @checkRequestSettings(url, method, format)
25
+ ajaxServer.ignoreNextRequest()
26
+ ignoreAllRequest: -> ajaxServer.ignoreAllRequest()
@@ -0,0 +1,165 @@
1
+ $ = jQuery # just to make sure
2
+
3
+ assertions = oojspec.assertions
4
+
5
+ addAssertion = (name, assertion)->
6
+ assert = assertion.assert
7
+ assertion.assert = ->
8
+ if arguments.length < assert.length
9
+ msg = "[#{name}] Expected to receive at least #{assert.length} argument"
10
+ msg += 's' if assert.length > 1
11
+ assertions.fail msg
12
+ return
13
+ result = assert.apply this, arguments
14
+ @actual = $toString(@actual) if @actual instanceof jQuery
15
+ result
16
+ assertions.add name, assertion
17
+
18
+ @oojs or= {}
19
+
20
+ $toString = ($element)->
21
+ return toHtml($element) if oojs.debugJQuery
22
+ $element.map((i, el)-> el.toString()).toArray().join '; '
23
+
24
+ toHtml = ($element)->
25
+ $element.map((i, el)-> $('<div/>').append($(el).clone()).html()).toArray().join ';\n\n'
26
+
27
+ browserTagCaseIndependentHtml = (html)-> $('<div/>').append(html).html()
28
+
29
+ addAssertion 'hasClass',
30
+ assert: (@actual, @className)-> $(actual).hasClass className
31
+ assertMessage: 'Expected ${actual} to have class ${className}.'
32
+ refuteMessage: 'Expected ${actual} not to have class ${className}.'
33
+ expectation: 'toHaveClass'
34
+
35
+ addAssertion 'isVisible',
36
+ assert: (@actual)-> $(actual).is(':visible')
37
+ assertMessage: 'Expected ${actual} to be visible.'
38
+ refuteMessage: 'Expected ${actual} not to be visible.'
39
+ expectation: 'toBeVisible'
40
+
41
+ addAssertion 'isHidden',
42
+ assert: (@actual)-> $(actual).is(':hidden')
43
+ assertMessage: 'Expected ${actual} to be hidden.'
44
+ refuteMessage: 'Expected ${actual} not to be hidden.'
45
+ expectation: 'toBeHidden'
46
+
47
+ addAssertion 'isSelected',
48
+ assert: (@actual)-> $(actual).is(':selected')
49
+ assertMessage: 'Expected ${actual} to be selected.'
50
+ refuteMessage: 'Expected ${actual} not to be selected.'
51
+ expectation: 'toBeSelected'
52
+
53
+ addAssertion 'isChecked',
54
+ assert: (@actual)-> $(actual).is(':checked')
55
+ assertMessage: 'Expected ${actual} to be checked.'
56
+ refuteMessage: 'Expected ${actual} not to be checked.'
57
+ expectation: 'toBeChecked'
58
+
59
+ addAssertion 'isEmpty',
60
+ assert: (@actual)-> $(actual).is(':empty')
61
+ assertMessage: 'Expected ${actual} to be empty.'
62
+ refuteMessage: 'Expected ${actual} not to be empty.'
63
+ expectation: 'toBeEmpty'
64
+
65
+ addAssertion 'exists',
66
+ assert: (@actual)-> $(actual).length
67
+ assertMessage: 'Expected ${actual} to exist.'
68
+ refuteMessage: 'Expected ${actual} not to exist.'
69
+ expectation: 'toExist'
70
+
71
+ addAssertion 'hasAttr',
72
+ assert: (@actual, @attribute, @expected)-> hasProperty actual.attr(attribute), expected
73
+ assertMessage: 'Expected attribute ${attribute} to be ${expected} for ${actual}.'
74
+ refuteMessage: 'Expected attribute ${attribute} not to be ${expected} for ${actual}.'
75
+ expectation: 'toHaveAttr'
76
+
77
+ addAssertion 'hasProp',
78
+ assert: (@actual, @property, @expected)-> hasProperty actual.prop(attribute), expected
79
+ assertMessage: 'Expected property ${property} to be ${expected} for ${actual}.'
80
+ refuteMessage: 'Expected property ${property} not to be ${expected} for ${actual}.'
81
+ expectation: 'toHaveProp'
82
+
83
+ addAssertion 'hasCss',
84
+ assert: (@actual, @css)->
85
+ return false for prop, value of css when @actual.css(prop) isnt value
86
+ true
87
+ assertMessage: 'Expected ${actual} to have css ${css}.'
88
+ refuteMessage: 'Expected ${actual} not to have css ${css}.'
89
+ expectation: 'toHaveCss'
90
+
91
+ addAssertion 'hasId',
92
+ assert: (@actual, @id)-> hasProperty actual.attr('id') is id
93
+ assertMessage: 'Expected ${actual} to have id ${id}.'
94
+ refuteMessage: 'Expected ${actual} not to have id ${id}.'
95
+ expectation: 'toHaveId'
96
+
97
+ addAssertion 'hasHtml',
98
+ assert: (@actual, @html)-> actual.html() is browserTagCaseIndependentHtml html
99
+ assertMessage: 'Expected ${actual} to have html ${html}.'
100
+ refuteMessage: 'Expected ${actual} not to have html ${html}.'
101
+ expectation: 'toHaveHtml'
102
+
103
+ addAssertion 'hasText',
104
+ assert: (@actual, @text)->
105
+ trimmedText = $.trim actual.text()
106
+ return text.test trimmedText if text?.test
107
+ trimmedText is text
108
+ assertMessage: 'Expected ${actual} to have text ${text}.'
109
+ refuteMessage: 'Expected ${actual} not to have text ${text}.'
110
+ expectation: 'toHaveText'
111
+
112
+ addAssertion 'hasValue',
113
+ assert: (@actual, @value)-> actual.val() is value
114
+ assertMessage: 'Expected ${actual} to have value ${value}.'
115
+ refuteMessage: 'Expected ${actual} not to have value ${value}.'
116
+ expectation: 'toHaveValue'
117
+
118
+ addAssertion 'hasData',
119
+ assert: (@actual, @key, @value)-> actual.data(key) is value
120
+ assertMessage: 'Expected ${key} data to be ${value} for ${actual}.'
121
+ refuteMessage: 'Expected ${key} data not to be ${value} for ${actual}.'
122
+ expectation: 'toHaveData'
123
+
124
+ addAssertion 'isSelector', # TODO: override toBe?
125
+ assert: (@actual, @selector)-> actual.is selector
126
+ assertMessage: 'Expected ${actual} to be ${selector}.'
127
+ refuteMessage: 'Expected ${actual} not to be ${selector}.'
128
+ expectation: 'toBeSelector'
129
+
130
+ addAssertion 'containsSelector', # TODO: override contains?
131
+ assert: (@actual, @selector)-> actual.find(selector).length
132
+ assertMessage: 'Expected ${actual} to contain ${selector}.'
133
+ refuteMessage: 'Expected ${actual} not to contain ${selector}.'
134
+ expectation: 'toContainSelector'
135
+
136
+ addAssertion 'isDisabled',
137
+ assert: (@actual)-> actual.is ':disabled'
138
+ assertMessage: 'Expected ${actual} to be disabled.'
139
+ refuteMessage: 'Expected ${actual} not to be disabled.'
140
+ expectation: 'toBeDisabled'
141
+
142
+ addAssertion 'isFocused',
143
+ assert: (@actual)-> actual.is ':focus'
144
+ assertMessage: 'Expected ${actual} to be focused.'
145
+ refuteMessage: 'Expected ${actual} not to be focused.'
146
+ expectation: 'toBeFocused'
147
+
148
+ addAssertion 'handle',
149
+ assert: (@actual, @event)-> actual.data('events')?[event].length
150
+ assertMessage: 'Expected ${actual} to handle ${event}.'
151
+ refuteMessage: 'Expected ${actual} not to handle ${event}.'
152
+ expectation: 'toHandle'
153
+
154
+ addAssertion 'handleWith',
155
+ assert: (@actual, @event, @handler)->
156
+ stack = actual.data('events')[event]
157
+ return true for ev in stack when ev.handler is handler
158
+ false
159
+ assertMessage: 'Expected ${actual} to handle ${event} with ${handler}.'
160
+ refuteMessage: 'Expected ${actual} not to handle ${event} with ${handler}.'
161
+ expectation: 'toHandle'
162
+
163
+ hasProperty = (actualValue, expectedValue)->
164
+ return actualValue isnt undefined if expectedValue is undefined
165
+ actualValue is expectedValue
@@ -1,11 +1,11 @@
1
1
  require "oojs/version"
2
- require 'rails_sandbox_jasmine'
2
+ require 'oojspec'
3
3
  require 'fake-ajax-server'
4
4
  require 'jquery-rails'
5
5
  require 'sinon-rails'
6
6
 
7
7
  module Oojs
8
8
  class Engine < Rails::Engine
9
- config.sandbox_assets.template ||= 'jasmine/runner'
9
+ config.sandbox_assets.template ||= 'oojspec/runner'
10
10
  end
11
11
  end
@@ -1,3 +1,3 @@
1
1
  module Oojs
2
- VERSION = "0.0.4"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -17,6 +17,6 @@ Gem::Specification.new do |gem|
17
17
  gem.require_paths = ["lib"]
18
18
  gem.version = Oojs::VERSION
19
19
 
20
- gem.add_dependency 'rails_sandbox_jasmine'
20
+ gem.add_dependency 'oojspec'
21
21
  gem.add_dependency 'fake-ajax-server', '>= 0.0.2'
22
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oojs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,10 +9,10 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-04 00:00:00.000000000 Z
12
+ date: 2012-07-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: rails_sandbox_jasmine
15
+ name: oojspec
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
@@ -58,9 +58,9 @@ files:
58
58
  - LICENSE
59
59
  - README.md
60
60
  - Rakefile
61
- - lib/assets/javascripts/jasmine_helpers.js.coffee
62
- - lib/assets/javascripts/jasmine_helpers/ajax_spec_helpers.js.coffee
63
- - lib/assets/javascripts/jasmine_helpers/extra_matchers.js.coffee
61
+ - lib/assets/javascripts/oojspec_helpers.js.coffee
62
+ - lib/assets/javascripts/oojspec_helpers/ajax_spec_helpers.js.coffee
63
+ - lib/assets/javascripts/oojspec_helpers/oojspec-jquery.js.coffee
64
64
  - lib/generators/oojs/spec/USAGE
65
65
  - lib/generators/oojs/spec/spec_generator.rb
66
66
  - lib/generators/oojs/spec/templates/fake_ajax_server.js.coffee.erb
@@ -71,7 +71,6 @@ files:
71
71
  - lib/oojs.rb
72
72
  - lib/oojs/version.rb
73
73
  - oojs.gemspec
74
- - vendor/assets/javascripts/jasmine-jquery.js
75
74
  - vendor/assets/javascripts/jquery.ba-bbq.js
76
75
  - vendor/assets/javascripts/modules.js.coffee
77
76
  homepage: http://github.com/rosenfeld/oojs
@@ -88,7 +87,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
88
87
  version: '0'
89
88
  segments:
90
89
  - 0
91
- hash: 3524376735705668499
90
+ hash: -1256028454248046243
92
91
  required_rubygems_version: !ruby/object:Gem::Requirement
93
92
  none: false
94
93
  requirements:
@@ -97,10 +96,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
96
  version: '0'
98
97
  segments:
99
98
  - 0
100
- hash: 3524376735705668499
99
+ hash: -1256028454248046243
101
100
  requirements: []
102
101
  rubyforge_project:
103
- rubygems_version: 1.8.21
102
+ rubygems_version: 1.8.24
104
103
  signing_key:
105
104
  specification_version: 3
106
105
  summary: Object-oriented JavaScript (or CoffeeScript) for Rails
@@ -1 +0,0 @@
1
- # =require_tree ./jasmine_helpers
@@ -1,28 +0,0 @@
1
- # =require modules
2
-
3
- TIMEOUT = 500 # ms - Used to be 300, but FF was too slow
4
- extendClass 'specs.jasmine.AjaxHelpers', (self)->
5
- ajaxServer = null
6
- initialize: (fakeAjaxServer, options={})->
7
- ajaxServer = fakeAjaxServer
8
- TIMEOUT = options.timeout if options.timeout
9
- ajaxSettings: -> ajaxServer.ajaxSettings()
10
- waitsFor: (condition, message="waited event didn't happen", timeout=TIMEOUT)->
11
- waitsFor (-> condition.call self), message, timeout
12
- waitsForAjaxRequest: (message = "An AJAX call was expected", timeout=TIMEOUT, extraCondition)->
13
- @waitsFor (-> ajaxServer.ajaxCallbacksQueue.length and
14
- (not extraCondition or extraCondition.call self)), message, timeout
15
- waitsForAjaxRequestAnd: (condition, message, timeout)->
16
- @waitsForAjaxRequest(message, timeout, condition)
17
- nextRequest: (url, method, format)->
18
- @checkRequestSettings(url, method, format)
19
- ajaxServer.processNextRequest()
20
- checkRequestSettings: (url, method, format)->
21
- s = @ajaxSettings()
22
- expect(s.url).toBe url unless url is undefined
23
- expect(s.type).toBe method unless method is undefined
24
- expect(s.dataType).toBe format unless format is undefined
25
- ignoreRequest: (url, method, format)->
26
- @checkRequestSettings(url, method, format)
27
- ajaxServer.ignoreNextRequest()
28
- ignoreAllRequest: -> ajaxServer.ignoreAllRequest()
@@ -1,6 +0,0 @@
1
- # =require jasmine-jquery
2
-
3
- jasmine.JQuery.matchersClass.toHaveCss = (css)->
4
- (return false unless @actual.css(prop) is value) for prop, value of css
5
- true
6
-
@@ -1,315 +0,0 @@
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.makeFixtureUrl_(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.makeFixtureUrl_ = function(relativeUrl){
100
- return this.fixturesPath.match('/$') ? this.fixturesPath + relativeUrl : this.fixturesPath + '/' + relativeUrl;
101
- };
102
-
103
- jasmine.Fixtures.prototype.proxyCallTo_ = function(methodName, passedArguments) {
104
- return this[methodName].apply(this, passedArguments);
105
- };
106
-
107
-
108
- jasmine.JQuery = function() {};
109
-
110
- jasmine.JQuery.browserTagCaseIndependentHtml = function(html) {
111
- return jQuery('<div/>').append(html).html();
112
- };
113
-
114
- jasmine.JQuery.elementToString = function(element) {
115
- var domEl = $(element).get(0)
116
- if (domEl == undefined || domEl.cloneNode)
117
- return jQuery('<div />').append($(element).clone()).html();
118
- else
119
- return element.toString();
120
- };
121
-
122
- jasmine.JQuery.matchersClass = {};
123
-
124
- (function(namespace) {
125
- var data = {
126
- spiedEvents: {},
127
- handlers: []
128
- };
129
-
130
- namespace.events = {
131
- spyOn: function(selector, eventName) {
132
- var handler = function(e) {
133
- data.spiedEvents[[selector, eventName]] = e;
134
- };
135
- jQuery(selector).bind(eventName, handler);
136
- data.handlers.push(handler);
137
- },
138
-
139
- wasTriggered: function(selector, eventName) {
140
- return !!(data.spiedEvents[[selector, eventName]]);
141
- },
142
-
143
- wasPrevented: function(selector, eventName) {
144
- return data.spiedEvents[[selector, eventName]].isDefaultPrevented();
145
- },
146
-
147
- cleanUp: function() {
148
- data.spiedEvents = {};
149
- data.handlers = [];
150
- }
151
- }
152
- })(jasmine.JQuery);
153
-
154
- (function(){
155
- var jQueryMatchers = {
156
- toHaveClass: function(className) {
157
- return this.actual.hasClass(className);
158
- },
159
-
160
- toBeVisible: function() {
161
- return this.actual.is(':visible');
162
- },
163
-
164
- toBeHidden: function() {
165
- return this.actual.is(':hidden');
166
- },
167
-
168
- toBeSelected: function() {
169
- return this.actual.is(':selected');
170
- },
171
-
172
- toBeChecked: function() {
173
- return this.actual.is(':checked');
174
- },
175
-
176
- toBeEmpty: function() {
177
- return this.actual.is(':empty');
178
- },
179
-
180
- toExist: function() {
181
- return $(document).find(this.actual).length;
182
- },
183
-
184
- toHaveAttr: function(attributeName, expectedAttributeValue) {
185
- return hasProperty(this.actual.attr(attributeName), expectedAttributeValue);
186
- },
187
-
188
- toHaveProp: function(propertyName, expectedPropertyValue) {
189
- return hasProperty(this.actual.prop(propertyName), expectedPropertyValue);
190
- },
191
-
192
- toHaveId: function(id) {
193
- return this.actual.attr('id') == id;
194
- },
195
-
196
- toHaveHtml: function(html) {
197
- return this.actual.html() == jasmine.JQuery.browserTagCaseIndependentHtml(html);
198
- },
199
-
200
- toHaveText: function(text) {
201
- var trimmedText = $.trim(this.actual.text());
202
- if (text && jQuery.isFunction(text.test)) {
203
- return text.test(trimmedText);
204
- } else {
205
- return trimmedText == text;
206
- }
207
- },
208
-
209
- toHaveValue: function(value) {
210
- return this.actual.val() == value;
211
- },
212
-
213
- toHaveData: function(key, expectedValue) {
214
- return hasProperty(this.actual.data(key), expectedValue);
215
- },
216
-
217
- toBe: function(selector) {
218
- return this.actual.is(selector);
219
- },
220
-
221
- toContain: function(selector) {
222
- return this.actual.find(selector).length;
223
- },
224
-
225
- toBeDisabled: function(selector){
226
- return this.actual.is(':disabled');
227
- },
228
-
229
- toBeFocused: function(selector) {
230
- return this.actual.is(':focus');
231
- },
232
-
233
- // tests the existence of a specific event binding
234
- toHandle: function(eventName) {
235
- var events = this.actual.data("events");
236
- return events && events[eventName].length > 0;
237
- },
238
-
239
- // tests the existence of a specific event binding + handler
240
- toHandleWith: function(eventName, eventHandler) {
241
- var stack = this.actual.data("events")[eventName];
242
- var i;
243
- for (i = 0; i < stack.length; i++) {
244
- if (stack[i].handler == eventHandler) {
245
- return true;
246
- }
247
- }
248
- return false;
249
- }
250
- };
251
-
252
- var hasProperty = function(actualValue, expectedValue) {
253
- if (expectedValue === undefined) {
254
- return actualValue !== undefined;
255
- }
256
- return actualValue == expectedValue;
257
- };
258
-
259
- var bindMatcher = function(methodName) {
260
- var builtInMatcher = jasmine.Matchers.prototype[methodName];
261
-
262
- jasmine.JQuery.matchersClass[methodName] = function() {
263
- if (this.actual
264
- && (this.actual instanceof jQuery
265
- || jasmine.isDomNode(this.actual))) {
266
- this.actual = $(this.actual);
267
- var result = jQueryMatchers[methodName].apply(this, arguments)
268
- if (this.actual.get && !$.isWindow(this.actual.get()[0]))
269
- this.actual = jasmine.JQuery.elementToString(this.actual)
270
- return result;
271
- }
272
-
273
- if (builtInMatcher) {
274
- return builtInMatcher.apply(this, arguments);
275
- }
276
-
277
- return false;
278
- };
279
- };
280
-
281
- for(var methodName in jQueryMatchers) {
282
- bindMatcher(methodName);
283
- }
284
- })();
285
-
286
- beforeEach(function() {
287
- this.addMatchers(jasmine.JQuery.matchersClass);
288
- this.addMatchers({
289
- toHaveBeenTriggeredOn: function(selector) {
290
- this.message = function() {
291
- return [
292
- "Expected event " + this.actual + " to have been triggered on " + selector,
293
- "Expected event " + this.actual + " not to have been triggered on " + selector
294
- ];
295
- };
296
- return jasmine.JQuery.events.wasTriggered($(selector), this.actual);
297
- }
298
- });
299
- this.addMatchers({
300
- toHaveBeenPreventedOn: function(selector) {
301
- this.message = function() {
302
- return [
303
- "Expected event " + this.actual + " to have been prevented on " + selector,
304
- "Expected event " + this.actual + " not to have been prevented on " + selector
305
- ];
306
- };
307
- return jasmine.JQuery.events.wasPrevented(selector, this.actual);
308
- }
309
- });
310
- });
311
-
312
- afterEach(function() {
313
- jasmine.getFixtures().cleanUp();
314
- jasmine.JQuery.events.cleanUp();
315
- });