jasmine-fixtures-generator 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/.travis.yml +6 -0
- data/Gemfile +4 -0
- data/MIT-LICENSE +20 -0
- data/README.md +36 -0
- data/Rakefile +13 -0
- data/jasmine-fixtures-generator.gemspec +24 -0
- data/lib/generators/jasmine-fixtures.rb +27 -0
- data/lib/generators/templates/spec/controllers/jasmine_fixture_creators_spec.rb +51 -0
- data/lib/generators/templates/spec/javascripts/example_users_spec.js +21 -0
- data/lib/generators/templates/spec/support/fixture_helper_methods.rb +50 -0
- data/lib/jasmine-fixtures-generator.rb +7 -0
- data/test/fixture_helper_methods_test.rb +13 -0
- data/test/jasmine-fixture-generator_test.rb +16 -0
- data/test/support/rails_stub.rb +5 -0
- data/test/test_helper.rb +8 -0
- data/vendor/jasmine-jquery.js +283 -0
- metadata +103 -0
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Luis Porras, Guillermo Iguaran
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# Jasmine Fixtures Generator [![Build Status](http://travis-ci.org/lporras/jasmine-fixtures-generator.png)](http://travis-ci.org/lporras/jasmine-fixtures-generator)
|
2
|
+
Fixtures Generator for Jasmine under Rails 3.x (largelly based in [jasmine-fixtures](https://github.com/mavenlink/jasmine-fixtures) for Rails 2.x)
|
3
|
+
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Install the gem:
|
8
|
+
|
9
|
+
gem install jasmine-fixtures-generator
|
10
|
+
|
11
|
+
Add it to your Gemfile:
|
12
|
+
|
13
|
+
gem "jasmine-fixtures-generator", :group => :development
|
14
|
+
|
15
|
+
|
16
|
+
## Usage
|
17
|
+
|
18
|
+
Run the generator:
|
19
|
+
|
20
|
+
rails generate jasmine_fixtures
|
21
|
+
|
22
|
+
## Contributing to Jasmine Fixtures Generator
|
23
|
+
|
24
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
25
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
26
|
+
* Fork the project
|
27
|
+
* Start a feature/bugfix branch
|
28
|
+
* Commit and push until you are happy with your contribution
|
29
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
30
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
31
|
+
|
32
|
+
|
33
|
+
## Copyright
|
34
|
+
|
35
|
+
Copyright (c) 2011 Luis Porras, Guillermo Iguaran. See MIT-LICENSE for
|
36
|
+
further details.
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "jasmine-fixtures-generator"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "jasmine-fixtures-generator"
|
7
|
+
s.version = Jasmine::Fixtures::Generator::VERSION
|
8
|
+
s.authors = ["Luis Porras", "Guillermo Iguaran"]
|
9
|
+
s.email = ["lporras16@gmail.com", "guilleiguaran@gmail.com"]
|
10
|
+
s.homepage = "https://github.com/lporras/jasmine-fixtures-generator"
|
11
|
+
s.summary = %q{Fixtures Generator for Jasmine under Rails 3.x}
|
12
|
+
s.description = %q{Fixtures Generator for Jasmine BDD framework under Rails 3.x}
|
13
|
+
|
14
|
+
s.rubyforge_project = "jasmine-fixtures-generator"
|
15
|
+
|
16
|
+
s.add_runtime_dependency "jasmine", ">= 1.0.0"
|
17
|
+
s.add_runtime_dependency "railties", ">= 3.0.0"
|
18
|
+
s.add_runtime_dependency "nokogiri", ">= 1.4.0"
|
19
|
+
|
20
|
+
s.files = `git ls-files`.split("\n")
|
21
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
22
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
23
|
+
s.require_paths = ["lib"]
|
24
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "rails/generators/base"
|
2
|
+
|
3
|
+
class JasmineFixturesGenerator < ::Rails::Generators::Base
|
4
|
+
|
5
|
+
desc "This generator install jasmine-jquery and add fixture_helper_methods.rb"
|
6
|
+
source_root File.expand_path('../templates', __FILE__)
|
7
|
+
|
8
|
+
def copy_jasmine_jquery
|
9
|
+
say_status("copying", "jasmine-jquery", :green)
|
10
|
+
copy_file "../../../vendor/jasmine-jquery.js", "spec/javascripts/helpers/jasmine-jquery.js"
|
11
|
+
end
|
12
|
+
|
13
|
+
def copy_fixture_helper_methods
|
14
|
+
say_status("copying", "fixture_helper_methods.rb", :green)
|
15
|
+
copy_file "spec/support/fixture_helper_methods.rb", "spec/support/fixture_helper_methods.rb"
|
16
|
+
end
|
17
|
+
|
18
|
+
def copy_jasmine_fixture_creators_spec
|
19
|
+
say_status("copying", "jasmine_fixture_creators_spec.rb", :green)
|
20
|
+
copy_file "spec/controllers/jasmine_fixture_creators_spec.rb", "spec/controllers/jasmine_fixture_creators_spec.rb"
|
21
|
+
end
|
22
|
+
|
23
|
+
def copy_jasmine_spec_example
|
24
|
+
say_status("copying", "jasmine spec example", :green)
|
25
|
+
copy_file "spec/javascripts/example_users_spec.js", "spec/javascripts/example_users_spec.js"
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
=begin
|
4
|
+
|
5
|
+
You can use this file to define new Jasmine Fixtures
|
6
|
+
or
|
7
|
+
You can add jasmine fixtures spec on your controllers spec
|
8
|
+
|
9
|
+
We have provided an example for you to crib off.
|
10
|
+
|
11
|
+
Basically:
|
12
|
+
1) Visit a route with your controller action
|
13
|
+
2) Make sure response.body has the content you want become fixture
|
14
|
+
3) save_fixture with the response you want and give a name to your fixture
|
15
|
+
|
16
|
+
|
17
|
+
Using save_fixture method
|
18
|
+
-------------------------
|
19
|
+
|
20
|
+
html_for('body') => will take only the content of <body> tag and will rename <body> to <div>
|
21
|
+
to avoid nested <body> tags within the Jasmine runner
|
22
|
+
|
23
|
+
If you have custom responses (ajax partials, JSON, etc),
|
24
|
+
you can subvert this and use response.body or whatever is appropriate.
|
25
|
+
|
26
|
+
=end
|
27
|
+
|
28
|
+
####Examples
|
29
|
+
|
30
|
+
describe UsersController do
|
31
|
+
#You need to render_views in each of your describes to get the content of the response
|
32
|
+
render_views
|
33
|
+
|
34
|
+
describe "user signup" do
|
35
|
+
#Example of a standard request that would use html_for to strip <body>
|
36
|
+
it "generates a new user signup page" do
|
37
|
+
get :new
|
38
|
+
response.should be_success
|
39
|
+
save_fixture(html_for('body'), 'user-signup-page')
|
40
|
+
end
|
41
|
+
|
42
|
+
#Example of an ajax request that doesn't have a body tag to strip out
|
43
|
+
describe "a user's profile" do
|
44
|
+
it "generates successful signup xhr response" do
|
45
|
+
xhr :post, :create, :user => { :name => 'Bob', :password => 'something', :password_confirmation => 'something' }
|
46
|
+
response.should be_success
|
47
|
+
save_fixture(response.body, 'user-success-ajax-response')
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
// Here is an example of how you might use the fixtures in your jasmine tests.
|
2
|
+
// Obviously this test won't actually work in your project.
|
3
|
+
describe('User pages', function () {
|
4
|
+
describe('the signup page', function() {
|
5
|
+
it('looks correct', function() {
|
6
|
+
loadFixtures('user-signup-page.html');
|
7
|
+
expect(jQuery("#some_id")).toExist();
|
8
|
+
});
|
9
|
+
});
|
10
|
+
|
11
|
+
describe('user signup success page load over ajax', function() {
|
12
|
+
it('inserts the returned content into the page', function() {
|
13
|
+
loadFixtures('user-signup-page');
|
14
|
+
var fixtureData = readFixtures('user-success-ajax-response.html');
|
15
|
+
doSomethingInvolvingAnAjaxCallThatReceivesHTML();
|
16
|
+
jQuery.ajax.mostRecentCall.args[0].success(fixtureData);
|
17
|
+
expect(jQuery("#some_id_in_the_ajax_response")).toExist();
|
18
|
+
expect(somethingExcitingToHaveHappened()).toBeTruthy();
|
19
|
+
});
|
20
|
+
});
|
21
|
+
});
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module FixtureHelperMethods
|
2
|
+
# Saves the content to a fixture file using the given name
|
3
|
+
def save_fixture(content, name)
|
4
|
+
fixture_path = File.join(Rails.root, '/spec/javascripts/fixtures')
|
5
|
+
FileUtils.mkdir_p(fixture_path) unless File.exists?(fixture_path)
|
6
|
+
|
7
|
+
content = convert_body_tag_to_div(content)
|
8
|
+
|
9
|
+
fixture_file = File.join(fixture_path, "#{name}")
|
10
|
+
|
11
|
+
File.open(fixture_file, 'w') do |file|
|
12
|
+
file.puts(content)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# From the controller spec response body, extracts html identified
|
17
|
+
# by the css selector.
|
18
|
+
def html_for(selector)
|
19
|
+
doc = Nokogiri::HTML(response.body)
|
20
|
+
|
21
|
+
remove_third_party_scripts(doc)
|
22
|
+
content = doc.css(selector).first.to_s
|
23
|
+
|
24
|
+
convert_body_tag_to_div(content)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
# Recommended that you add all body-level third party scripts inside a div called #third-party-scripts
|
30
|
+
# so that they can be removed during testing.
|
31
|
+
def remove_third_party_scripts(doc)
|
32
|
+
scripts = doc.at('#third-party-scripts')
|
33
|
+
scripts.remove if scripts
|
34
|
+
end
|
35
|
+
|
36
|
+
# Many of our css and jQuery selectors rely on a class attribute we
|
37
|
+
# normally embed in the <body>. For example:
|
38
|
+
#
|
39
|
+
# <body class="workspaces show">
|
40
|
+
#
|
41
|
+
# Here we convert the body tag to a div so that we can load it into
|
42
|
+
# the document running js specs without embedding a <body> within a <body>.
|
43
|
+
def convert_body_tag_to_div(markup)
|
44
|
+
markup.gsub("<body", '<div').gsub("</body>", "</div>")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# Add fixture-generation methods to ControllerExampleGroup. We load
|
49
|
+
# this file within our spec_helper.rb
|
50
|
+
RSpec::Rails::ControllerExampleGroup.extend(FixtureHelperMethods) if defined?(RSpec)
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'generators/templates/spec/support/fixture_helper_methods'
|
3
|
+
|
4
|
+
class FixtureHelperMethodsTest < ActiveSupport::TestCase
|
5
|
+
include FixtureHelperMethods
|
6
|
+
|
7
|
+
test "#save_fixture creates an html file with the given name" do
|
8
|
+
save_fixture("<p>prueba</p>", "test_file.html")
|
9
|
+
fixture_path = File.join(Rails.root, '/spec/javascripts/fixtures')
|
10
|
+
fixture_file = File.join(fixture_path, "test_file.html")
|
11
|
+
assert_equal true, File.exists?(fixture_file)
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require "generators/jasmine-fixtures"
|
3
|
+
|
4
|
+
class JasmineFixturesGeneratorTest < Rails::Generators::TestCase
|
5
|
+
tests JasmineFixturesGenerator
|
6
|
+
destination File.expand_path("../tmp", File.dirname(__FILE__))
|
7
|
+
setup :prepare_destination
|
8
|
+
|
9
|
+
test "Assert all files are properly created" do
|
10
|
+
run_generator
|
11
|
+
assert_file "spec/support/fixture_helper_methods.rb"
|
12
|
+
assert_file "spec/javascripts/helpers/jasmine-jquery.js"
|
13
|
+
assert_file "spec/controllers/jasmine_fixture_creators_spec.rb"
|
14
|
+
assert_file "spec/javascripts/example_users_spec.js"
|
15
|
+
end
|
16
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,283 @@
|
|
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 = jQuery('<div id="' + this.containerId + '" />');
|
75
|
+
container.html(html);
|
76
|
+
jQuery('body').append(container);
|
77
|
+
};
|
78
|
+
|
79
|
+
jasmine.Fixtures.prototype.getFixtureHtml_ = function(url) {
|
80
|
+
if (typeof this.fixturesCache_[url] == 'undefined') {
|
81
|
+
this.loadFixtureIntoCache_(url);
|
82
|
+
}
|
83
|
+
return this.fixturesCache_[url];
|
84
|
+
};
|
85
|
+
|
86
|
+
jasmine.Fixtures.prototype.loadFixtureIntoCache_ = function(relativeUrl) {
|
87
|
+
var self = this;
|
88
|
+
var url = this.fixturesPath.match('/$') ? this.fixturesPath + relativeUrl : this.fixturesPath + '/' + relativeUrl;
|
89
|
+
jQuery.ajax({
|
90
|
+
async: false, // must be synchronous to guarantee that no tests are run before fixture is loaded
|
91
|
+
cache: false,
|
92
|
+
dataType: 'html',
|
93
|
+
url: url,
|
94
|
+
success: function(data) {
|
95
|
+
self.fixturesCache_[relativeUrl] = data;
|
96
|
+
},
|
97
|
+
error: function(jqXHR, status, errorThrown) {
|
98
|
+
throw Error('Fixture could not be loaded: ' + url + ' (status: ' + status + ', message: ' + errorThrown.message + ')');
|
99
|
+
}
|
100
|
+
});
|
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
|
+
return jQuery('<div />').append(element.clone()).html();
|
116
|
+
};
|
117
|
+
|
118
|
+
jasmine.JQuery.matchersClass = {};
|
119
|
+
|
120
|
+
(function(namespace) {
|
121
|
+
var data = {
|
122
|
+
spiedEvents: {},
|
123
|
+
handlers: []
|
124
|
+
};
|
125
|
+
|
126
|
+
namespace.events = {
|
127
|
+
spyOn: function(selector, eventName) {
|
128
|
+
var handler = function(e) {
|
129
|
+
data.spiedEvents[[selector, eventName]] = e;
|
130
|
+
};
|
131
|
+
jQuery(selector).bind(eventName, handler);
|
132
|
+
data.handlers.push(handler);
|
133
|
+
},
|
134
|
+
|
135
|
+
wasTriggered: function(selector, eventName) {
|
136
|
+
return !!(data.spiedEvents[[selector, eventName]]);
|
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
|
+
toHaveId: function(id) {
|
181
|
+
return this.actual.attr('id') == id;
|
182
|
+
},
|
183
|
+
|
184
|
+
toHaveHtml: function(html) {
|
185
|
+
return this.actual.html() == jasmine.JQuery.browserTagCaseIndependentHtml(html);
|
186
|
+
},
|
187
|
+
|
188
|
+
toHaveText: function(text) {
|
189
|
+
if (text && jQuery.isFunction(text.test)) {
|
190
|
+
return text.test(this.actual.text());
|
191
|
+
} else {
|
192
|
+
return this.actual.text() == text;
|
193
|
+
}
|
194
|
+
},
|
195
|
+
|
196
|
+
toHaveValue: function(value) {
|
197
|
+
return this.actual.val() == value;
|
198
|
+
},
|
199
|
+
|
200
|
+
toHaveData: function(key, expectedValue) {
|
201
|
+
return hasProperty(this.actual.data(key), expectedValue);
|
202
|
+
},
|
203
|
+
|
204
|
+
toBe: function(selector) {
|
205
|
+
return this.actual.is(selector);
|
206
|
+
},
|
207
|
+
|
208
|
+
toContain: function(selector) {
|
209
|
+
return this.actual.find(selector).size() > 0;
|
210
|
+
},
|
211
|
+
|
212
|
+
toBeDisabled: function(selector){
|
213
|
+
return this.actual.is(':disabled');
|
214
|
+
},
|
215
|
+
|
216
|
+
// tests the existence of a specific event binding
|
217
|
+
toHandle: function(eventName) {
|
218
|
+
var events = this.actual.data("events");
|
219
|
+
return events && events[eventName].length > 0;
|
220
|
+
},
|
221
|
+
|
222
|
+
// tests the existence of a specific event binding + handler
|
223
|
+
toHandleWith: function(eventName, eventHandler) {
|
224
|
+
var stack = this.actual.data("events")[eventName];
|
225
|
+
var i;
|
226
|
+
for (i = 0; i < stack.length; i++) {
|
227
|
+
if (stack[i].handler == eventHandler) {
|
228
|
+
return true;
|
229
|
+
}
|
230
|
+
}
|
231
|
+
return false;
|
232
|
+
}
|
233
|
+
};
|
234
|
+
|
235
|
+
var hasProperty = function(actualValue, expectedValue) {
|
236
|
+
if (expectedValue === undefined) {
|
237
|
+
return actualValue !== undefined;
|
238
|
+
}
|
239
|
+
return actualValue == expectedValue;
|
240
|
+
};
|
241
|
+
|
242
|
+
var bindMatcher = function(methodName) {
|
243
|
+
var builtInMatcher = jasmine.Matchers.prototype[methodName];
|
244
|
+
|
245
|
+
jasmine.JQuery.matchersClass[methodName] = function() {
|
246
|
+
if (this.actual instanceof jQuery) {
|
247
|
+
var result = jQueryMatchers[methodName].apply(this, arguments);
|
248
|
+
this.actual = jasmine.JQuery.elementToString(this.actual);
|
249
|
+
return result;
|
250
|
+
}
|
251
|
+
|
252
|
+
if (builtInMatcher) {
|
253
|
+
return builtInMatcher.apply(this, arguments);
|
254
|
+
}
|
255
|
+
|
256
|
+
return false;
|
257
|
+
};
|
258
|
+
};
|
259
|
+
|
260
|
+
for(var methodName in jQueryMatchers) {
|
261
|
+
bindMatcher(methodName);
|
262
|
+
}
|
263
|
+
})();
|
264
|
+
|
265
|
+
beforeEach(function() {
|
266
|
+
this.addMatchers(jasmine.JQuery.matchersClass);
|
267
|
+
this.addMatchers({
|
268
|
+
toHaveBeenTriggeredOn: function(selector) {
|
269
|
+
this.message = function() {
|
270
|
+
return [
|
271
|
+
"Expected event " + this.actual + " to have been triggered on" + selector,
|
272
|
+
"Expected event " + this.actual + " not to have been triggered on" + selector
|
273
|
+
];
|
274
|
+
};
|
275
|
+
return jasmine.JQuery.events.wasTriggered(selector, this.actual);
|
276
|
+
}
|
277
|
+
})
|
278
|
+
});
|
279
|
+
|
280
|
+
afterEach(function() {
|
281
|
+
jasmine.getFixtures().cleanUp();
|
282
|
+
jasmine.JQuery.events.cleanUp();
|
283
|
+
});
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jasmine-fixtures-generator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Luis Porras
|
9
|
+
- Guillermo Iguaran
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2011-07-31 00:00:00.000000000 -05:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: jasmine
|
18
|
+
requirement: &2157521960 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ! '>='
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.0.0
|
24
|
+
type: :runtime
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: *2157521960
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: railties
|
29
|
+
requirement: &2157521460 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ! '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 3.0.0
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: *2157521460
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: nokogiri
|
40
|
+
requirement: &2157521000 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.4.0
|
46
|
+
type: :runtime
|
47
|
+
prerelease: false
|
48
|
+
version_requirements: *2157521000
|
49
|
+
description: Fixtures Generator for Jasmine BDD framework under Rails 3.x
|
50
|
+
email:
|
51
|
+
- lporras16@gmail.com
|
52
|
+
- guilleiguaran@gmail.com
|
53
|
+
executables: []
|
54
|
+
extensions: []
|
55
|
+
extra_rdoc_files: []
|
56
|
+
files:
|
57
|
+
- .gitignore
|
58
|
+
- .travis.yml
|
59
|
+
- Gemfile
|
60
|
+
- MIT-LICENSE
|
61
|
+
- README.md
|
62
|
+
- Rakefile
|
63
|
+
- jasmine-fixtures-generator.gemspec
|
64
|
+
- lib/generators/jasmine-fixtures.rb
|
65
|
+
- lib/generators/templates/spec/controllers/jasmine_fixture_creators_spec.rb
|
66
|
+
- lib/generators/templates/spec/javascripts/example_users_spec.js
|
67
|
+
- lib/generators/templates/spec/support/fixture_helper_methods.rb
|
68
|
+
- lib/jasmine-fixtures-generator.rb
|
69
|
+
- test/fixture_helper_methods_test.rb
|
70
|
+
- test/jasmine-fixture-generator_test.rb
|
71
|
+
- test/support/rails_stub.rb
|
72
|
+
- test/test_helper.rb
|
73
|
+
- vendor/jasmine-jquery.js
|
74
|
+
has_rdoc: true
|
75
|
+
homepage: https://github.com/lporras/jasmine-fixtures-generator
|
76
|
+
licenses: []
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ! '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ! '>='
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubyforge_project: jasmine-fixtures-generator
|
95
|
+
rubygems_version: 1.6.2
|
96
|
+
signing_key:
|
97
|
+
specification_version: 3
|
98
|
+
summary: Fixtures Generator for Jasmine under Rails 3.x
|
99
|
+
test_files:
|
100
|
+
- test/fixture_helper_methods_test.rb
|
101
|
+
- test/jasmine-fixture-generator_test.rb
|
102
|
+
- test/support/rails_stub.rb
|
103
|
+
- test/test_helper.rb
|