jasminerice 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -16,3 +16,4 @@ Session.vim
16
16
  err.txt
17
17
  .sass-cache
18
18
  public/stylesheets/*.css
19
+ .rvmrc
data/README.md CHANGED
@@ -14,9 +14,11 @@ your Gemfile so
14
14
 
15
15
  gem "jasminerice"
16
16
 
17
- Now add a route to the end of your config.routes
17
+ Now add a route to the end of your config.routes but only for development and test
18
18
 
19
- mount Jasminerice::Engine => "/jasmine"
19
+ if ["development", "test"].include? Rails.env
20
+ mount Jasminerice::Engine => "/jasmine"
21
+ end
20
22
 
21
23
  Create a single file called
22
24
 
@@ -65,7 +67,7 @@ Now start your server
65
67
 
66
68
  Goto
67
69
 
68
- http://localhost:3000/jasminerice
70
+ http://localhost:3000/jasmine
69
71
 
70
72
  and there are your specs.
71
73
 
@@ -1,5 +1,6 @@
1
1
  #=require jasmine
2
2
  #=require jasmine-html
3
+ #=require jasmine-jquery-1.2.0
3
4
 
4
5
  (->
5
6
  execJasmine = ->
@@ -1,7 +1,12 @@
1
1
  module Jasminerice
2
2
  class SpecController < ApplicationController
3
+ layout false
4
+
3
5
  def index
4
- render :layout => false
6
+ end
7
+
8
+ def fixtures
9
+ render "spec/javascripts/fixtures/#{params[:filename]}"
5
10
  end
6
11
  end
7
12
  end
@@ -1,13 +1,8 @@
1
- !!!
2
1
  %html
3
2
  %head
4
3
  %title Jasmine Spec Runner
5
-
6
4
  = stylesheet_link_tag "jasmine"
7
5
  = javascript_include_tag "jasminerice", :debug => Rails.env.development?
8
6
  = javascript_include_tag "spec", :debug => Rails.env.development?
9
-
10
-
11
- / include source files here...
7
+ = csrf_meta_tags
12
8
  %body
13
-
data/config/routes.rb CHANGED
@@ -1,4 +1,8 @@
1
1
  Jasminerice::Engine.routes.draw do
2
- resources :spec, :controller => 'spec'
2
+ resources :spec, :controller => 'spec', :only => [:index] do
3
+ get "fixtures/:filename", :action => :fixtures
4
+ end
5
+ match "fixtures/:filename", :to => "spec#fixtures#:filename"
6
+
3
7
  root :to => "spec#index"
4
8
  end
data/jasminerice.gemspec CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
6
6
  s.description = "Full support for the Rails 3.1 asset pipeline when bdd'ing your coffeescript or javascript using jasmine"
7
7
  s.files = `git ls-files`.split "\n"
8
8
  s.authors = ["Brad Phelan"]
9
- s.version = "0.0.4"
9
+ s.version = "0.0.5"
10
10
  s.platform = Gem::Platform::RUBY
11
11
  s.add_dependency( 'haml' )
12
12
  end
@@ -0,0 +1,256 @@
1
+ var readFixtures = function() {
2
+ return jasmine.getFixtures().proxyCallTo_('read', arguments);
3
+ };
4
+
5
+ var loadFixtures = function() {
6
+ jasmine.getFixtures().proxyCallTo_('load', arguments);
7
+ };
8
+
9
+ var setFixtures = function(html) {
10
+ jasmine.getFixtures().set(html);
11
+ };
12
+
13
+ var sandbox = function(attributes) {
14
+ return jasmine.getFixtures().sandbox(attributes);
15
+ };
16
+
17
+ var spyOnEvent = function(selector, eventName) {
18
+ jasmine.JQuery.events.spyOn(selector, eventName);
19
+ }
20
+
21
+ jasmine.getFixtures = function() {
22
+ return jasmine.currentFixtures_ = jasmine.currentFixtures_ || new jasmine.Fixtures();
23
+ };
24
+
25
+ jasmine.Fixtures = function() {
26
+ this.containerId = 'jasmine-fixtures';
27
+ this.fixturesCache_ = {};
28
+ // Changed in jasminerice to support the normal path
29
+ //this.fixturesPath = 'spec/javascripts/fixtures';
30
+ this.fixturesPath = 'jasmine/fixtures';
31
+ };
32
+
33
+ jasmine.Fixtures.prototype.set = function(html) {
34
+ this.cleanUp();
35
+ this.createContainer_(html);
36
+ };
37
+
38
+ jasmine.Fixtures.prototype.load = function() {
39
+ this.cleanUp();
40
+ this.createContainer_(this.read.apply(this, arguments));
41
+ };
42
+
43
+ jasmine.Fixtures.prototype.read = function() {
44
+ var htmlChunks = [];
45
+
46
+ var fixtureUrls = arguments;
47
+ for(var urlCount = fixtureUrls.length, urlIndex = 0; urlIndex < urlCount; urlIndex++) {
48
+ htmlChunks.push(this.getFixtureHtml_(fixtureUrls[urlIndex]));
49
+ }
50
+
51
+ return htmlChunks.join('');
52
+ };
53
+
54
+ jasmine.Fixtures.prototype.clearCache = function() {
55
+ this.fixturesCache_ = {};
56
+ };
57
+
58
+ jasmine.Fixtures.prototype.cleanUp = function() {
59
+ $('#' + this.containerId).remove();
60
+ };
61
+
62
+ jasmine.Fixtures.prototype.sandbox = function(attributes) {
63
+ var attributesToSet = attributes || {};
64
+ return $('<div id="sandbox" />').attr(attributesToSet);
65
+ };
66
+
67
+ jasmine.Fixtures.prototype.createContainer_ = function(html) {
68
+ var container = $('<div id="' + this.containerId + '" />');
69
+ container.html(html);
70
+ $('body').append(container);
71
+ };
72
+
73
+ jasmine.Fixtures.prototype.getFixtureHtml_ = function(url) {
74
+ if (typeof this.fixturesCache_[url] == 'undefined') {
75
+ this.loadFixtureIntoCache_(url);
76
+ }
77
+ return this.fixturesCache_[url];
78
+ };
79
+
80
+ jasmine.Fixtures.prototype.loadFixtureIntoCache_ = function(relativeUrl) {
81
+ var self = this;
82
+ var url = this.fixturesPath.match('/$') ? this.fixturesPath + relativeUrl : this.fixturesPath + '/' + relativeUrl;
83
+ $.ajax({
84
+ async: false, // must be synchronous to guarantee that no tests are run before fixture is loaded
85
+ cache: false,
86
+ dataType: 'html',
87
+ url: url,
88
+ success: function(data) {
89
+ self.fixturesCache_[relativeUrl] = data;
90
+ }
91
+ });
92
+ };
93
+
94
+ jasmine.Fixtures.prototype.proxyCallTo_ = function(methodName, passedArguments) {
95
+ return this[methodName].apply(this, passedArguments);
96
+ };
97
+
98
+
99
+ jasmine.JQuery = function() {};
100
+
101
+ jasmine.JQuery.browserTagCaseIndependentHtml = function(html) {
102
+ return $('<div/>').append(html).html();
103
+ };
104
+
105
+ jasmine.JQuery.elementToString = function(element) {
106
+ return $('<div />').append(element.clone()).html();
107
+ };
108
+
109
+ jasmine.JQuery.matchersClass = {};
110
+
111
+ (function(namespace) {
112
+ var data = {
113
+ spiedEvents: {},
114
+ handlers: []
115
+ };
116
+
117
+ namespace.events = {
118
+ spyOn: function(selector, eventName) {
119
+ var handler = function(e) {
120
+ data.spiedEvents[[selector, eventName]] = e;
121
+ };
122
+ $(selector).bind(eventName, handler);
123
+ data.handlers.push(handler);
124
+ },
125
+
126
+ wasTriggered: function(selector, eventName) {
127
+ return !!(data.spiedEvents[[selector, eventName]]);
128
+ },
129
+
130
+ cleanUp: function() {
131
+ data.spiedEvents = {};
132
+ data.handlers = [];
133
+ }
134
+ }
135
+ })(jasmine.JQuery);
136
+
137
+ (function(){
138
+ var jQueryMatchers = {
139
+ toHaveClass: function(className) {
140
+ return this.actual.hasClass(className);
141
+ },
142
+
143
+ toBeVisible: function() {
144
+ return this.actual.is(':visible');
145
+ },
146
+
147
+ toBeHidden: function() {
148
+ return this.actual.is(':hidden');
149
+ },
150
+
151
+ toBeSelected: function() {
152
+ return this.actual.is(':selected');
153
+ },
154
+
155
+ toBeChecked: function() {
156
+ return this.actual.is(':checked');
157
+ },
158
+
159
+ toBeEmpty: function() {
160
+ return this.actual.is(':empty');
161
+ },
162
+
163
+ toExist: function() {
164
+ return this.actual.size() > 0;
165
+ },
166
+
167
+ toHaveAttr: function(attributeName, expectedAttributeValue) {
168
+ return hasProperty(this.actual.attr(attributeName), expectedAttributeValue);
169
+ },
170
+
171
+ toHaveId: function(id) {
172
+ return this.actual.attr('id') == id;
173
+ },
174
+
175
+ toHaveHtml: function(html) {
176
+ return this.actual.html() == jasmine.JQuery.browserTagCaseIndependentHtml(html);
177
+ },
178
+
179
+ toHaveText: function(text) {
180
+ if (text && jQuery.isFunction(text.test)) {
181
+ return text.test(this.actual.text());
182
+ } else {
183
+ return this.actual.text() == text;
184
+ }
185
+ },
186
+
187
+ toHaveValue: function(value) {
188
+ return this.actual.val() == value;
189
+ },
190
+
191
+ toHaveData: function(key, expectedValue) {
192
+ return hasProperty(this.actual.data(key), expectedValue);
193
+ },
194
+
195
+ toBe: function(selector) {
196
+ return this.actual.is(selector);
197
+ },
198
+
199
+ toContain: function(selector) {
200
+ return this.actual.find(selector).size() > 0;
201
+ },
202
+
203
+ toBeDisabled: function(selector){
204
+ return this.actual.attr("disabled") == true;
205
+ }
206
+ };
207
+
208
+ var hasProperty = function(actualValue, expectedValue) {
209
+ if (expectedValue === undefined) {
210
+ return actualValue !== undefined;
211
+ }
212
+ return actualValue == expectedValue;
213
+ };
214
+
215
+ var bindMatcher = function(methodName) {
216
+ var builtInMatcher = jasmine.Matchers.prototype[methodName];
217
+
218
+ jasmine.JQuery.matchersClass[methodName] = function() {
219
+ if (this.actual instanceof jQuery) {
220
+ var result = jQueryMatchers[methodName].apply(this, arguments);
221
+ this.actual = jasmine.JQuery.elementToString(this.actual);
222
+ return result;
223
+ }
224
+
225
+ if (builtInMatcher) {
226
+ return builtInMatcher.apply(this, arguments);
227
+ }
228
+
229
+ return false;
230
+ };
231
+ };
232
+
233
+ for(var methodName in jQueryMatchers) {
234
+ bindMatcher(methodName);
235
+ }
236
+ })();
237
+
238
+ beforeEach(function() {
239
+ this.addMatchers(jasmine.JQuery.matchersClass);
240
+ this.addMatchers({
241
+ toHaveBeenTriggeredOn: function(selector) {
242
+ this.message = function() {
243
+ return [
244
+ "Expected event " + this.actual + " to have been triggered on" + selector,
245
+ "Expected event " + this.actual + " not to have been triggered on" + selector
246
+ ];
247
+ };
248
+ return jasmine.JQuery.events.wasTriggered(selector, this.actual);
249
+ }
250
+ })
251
+ });
252
+
253
+ afterEach(function() {
254
+ jasmine.getFixtures().cleanUp();
255
+ jasmine.JQuery.events.cleanUp();
256
+ });
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: jasminerice
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.4
5
+ version: 0.0.5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Brad Phelan
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-07-14 00:00:00 +02:00
13
+ date: 2011-07-18 00:00:00 +02:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -47,7 +47,6 @@ files:
47
47
  - app/controllers/jasminerice/spec_controller.rb
48
48
  - app/helpers/jasminerice/application_helper.rb
49
49
  - app/views/jasminerice/spec/index.html.haml
50
- - app/views/layouts/jasminerice/application.html.erb
51
50
  - config/initializers/jasminerice.rb
52
51
  - config/routes.rb
53
52
  - jasminerice.gemspec
@@ -57,6 +56,7 @@ files:
57
56
  - script/rails
58
57
  - vendor/assets/images/jasmine_favicon.png
59
58
  - vendor/assets/javascripts/jasmine-html.js
59
+ - vendor/assets/javascripts/jasmine-jquery-1.2.0.js
60
60
  - vendor/assets/javascripts/jasmine.js
61
61
  - vendor/assets/stylesheets/jasmine.css
62
62
  has_rdoc: true
@@ -1,14 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>Jasminerice</title>
5
- <%= stylesheet_link_tag "application" %>
6
- <%= javascript_include_tag "application" %>
7
- <%= csrf_meta_tags %>
8
- </head>
9
- <body>
10
-
11
- <%= yield %>
12
-
13
- </body>
14
- </html>