jasmine-fixtures 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.
- data/.bundle/config +2 -0
- data/.document +5 -0
- data/.gitignore +22 -0
- data/.pairs +7 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +27 -0
- data/LICENSE +20 -0
- data/README.rdoc +41 -0
- data/Rakefile +46 -0
- data/VERSION +1 -0
- data/generators/jasmine-fixtures/jasmine_fixtures_generator.rb +15 -0
- data/generators/jasmine-fixtures/templates/INSTALL +5 -0
- data/generators/jasmine-fixtures/templates/spec/controllers/jasmine_fixture_creators.rb +29 -0
- data/generators/jasmine-fixtures/templates/spec/javascripts/helpers/jasmine-fixture-helper.js +31 -0
- data/generators/jasmine-fixtures/templates/spec/javascripts/helpers/jasmine-fixture-loader.js +66 -0
- data/generators/jasmine-fixtures/templates/spec/javascripts/helpers/jasmine-fixture-matchers.js +253 -0
- data/generators/jasmine-fixtures/templates/spec/spec_helpers/jasmine_fixture_generator_methods.rb +45 -0
- data/lib/jasmine-fixtures.rb +0 -0
- data/spec/jasmine-fixtures_spec.rb +7 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +9 -0
- metadata +106 -0
data/.bundle/config
ADDED
data/.document
ADDED
data/.gitignore
ADDED
data/.pairs
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
gemcutter (0.6.1)
|
5
|
+
git (1.2.5)
|
6
|
+
jeweler (1.4.0)
|
7
|
+
gemcutter (>= 0.1.0)
|
8
|
+
git (>= 1.2.5)
|
9
|
+
rubyforge (>= 2.0.0)
|
10
|
+
json_pure (1.4.6)
|
11
|
+
rack (1.2.1)
|
12
|
+
rake (0.8.7)
|
13
|
+
rspec (1.3.1)
|
14
|
+
rspec-rails (1.3.3)
|
15
|
+
rack (>= 1.0.0)
|
16
|
+
rspec (= 1.3.1)
|
17
|
+
rubyforge (2.0.4)
|
18
|
+
json_pure (>= 1.1.7)
|
19
|
+
|
20
|
+
PLATFORMS
|
21
|
+
ruby
|
22
|
+
|
23
|
+
DEPENDENCIES
|
24
|
+
bundler (= 1.0.3)
|
25
|
+
jeweler (= 1.4.0)
|
26
|
+
rake (= 0.8.7)
|
27
|
+
rspec-rails (= 1.3.3)
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Jonathan Barnes & Roger Neel
|
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.rdoc
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
= jasmine-fixtures
|
2
|
+
|
3
|
+
Jasmine Fixtures is an add-on for the behavior-driven development framework, Jasmine. If you're using Jasmine to test the JavaScript in your Ruby projects and you want to test your DOM and bindings, you can use Jasmine Fixtures.
|
4
|
+
|
5
|
+
The gem includes 3 major pieces:
|
6
|
+
|
7
|
+
1) The helpers required to loadFixture() within your Jasmine specs
|
8
|
+
|
9
|
+
2) JQuery-based matchers to make your life easier
|
10
|
+
|
11
|
+
3) RSpec-based methods for creating DOM fixtures
|
12
|
+
|
13
|
+
== Installing
|
14
|
+
|
15
|
+
gem install jasmine-fixtures
|
16
|
+
|
17
|
+
script/generate jasmine-fixtures
|
18
|
+
|
19
|
+
If you want to use the fixture generator, you need to load jasmine_fixture_generator_methods.rb. If you load everything in your spec_helpers directory in your spec_helper.rb already, you're good to go. Otherwise, make sure it's required with the rest of your requires in spec_helper.rb.
|
20
|
+
|
21
|
+
== Assumptions
|
22
|
+
|
23
|
+
You haven't messed with the default Jasmine configuration to load everything in the helpers directory. If you have, make sure you get the jasmine-fixture-*.js files loaded.
|
24
|
+
|
25
|
+
All your fixtures should be in /tmp/js_dom_fixtures/FIXTURE_NAME.fixture.html.erb
|
26
|
+
|
27
|
+
You can roll your own fixtures and use the above path/naming convention. Also, be sure to wrap all fixtures in a wrapping <div>{Your content goes here}</div> that we ignore.
|
28
|
+
|
29
|
+
Alternatively, if you use our RSpec-based methods to generate fixtures (the better way), you need RSpec!
|
30
|
+
|
31
|
+
== Note on Patches/Pull Requests
|
32
|
+
|
33
|
+
* Fork the project.
|
34
|
+
* Make your feature addition or bug fix.
|
35
|
+
* Commit, do not mess with rakefile, version, or history.
|
36
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
37
|
+
* Send me a pull request. Bonus points for topic branches.
|
38
|
+
|
39
|
+
== Copyright
|
40
|
+
|
41
|
+
Copyright (c) 2010. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'spec'
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'jeweler'
|
7
|
+
Jeweler::Tasks.new do |gem|
|
8
|
+
gem.name = "jasmine-fixtures"
|
9
|
+
gem.summary = %Q{Jasmine Fixtures allow you to use real DOM to test your JavaScript}
|
10
|
+
gem.description = %Q{Dump out DOM that you want to test. Use jasmine-fixtures to load that DOM into your Jasmine specs. See github.com/mavenlink/jasmine-fixtures for more.}
|
11
|
+
gem.email = "roger@mavenlink.com"
|
12
|
+
gem.homepage = "http://github.com/mavenlink/jasmine-fixtures"
|
13
|
+
gem.authors = ["Roger Neel", "Jonathan Barnes", "JB Steadman"]
|
14
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
15
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
|
+
end
|
17
|
+
Jeweler::GemcutterTasks.new
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler (or a dependency) not available. Do a 'bundle install' to make sure you have all gems/dependencies installed."
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'spec/rake/spectask'
|
23
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
24
|
+
spec.libs << 'lib' << 'spec'
|
25
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
26
|
+
end
|
27
|
+
|
28
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
29
|
+
spec.libs << 'lib' << 'spec'
|
30
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
31
|
+
spec.rcov = true
|
32
|
+
end
|
33
|
+
|
34
|
+
task :spec => :check_dependencies
|
35
|
+
|
36
|
+
task :default => :spec
|
37
|
+
|
38
|
+
require 'rake/rdoctask'
|
39
|
+
Rake::RDocTask.new do |rdoc|
|
40
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
41
|
+
|
42
|
+
rdoc.rdoc_dir = 'rdoc'
|
43
|
+
rdoc.title = "jasmine-fixtures #{version}"
|
44
|
+
rdoc.rdoc_files.include('README*')
|
45
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
46
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class JasmineFixturesGenerator < Rails::Generator::Base
|
2
|
+
def manifest
|
3
|
+
record do |m|
|
4
|
+
m.directory "spec/javascripts/helpers"
|
5
|
+
m.file "spec/javascripts/helpers/jasmine-fixture-helper.js", "spec/javascripts/helpers/jasmine-fixture-helper.js"
|
6
|
+
m.file "spec/javascripts/helpers/jasmine-fixture-loader.js", "spec/javascripts/helpers/jasmine-fixture-loader.js"
|
7
|
+
m.file "spec/javascripts/helpers/jasmine-fixture-matchers.js", "spec/javascripts/helpers/jasmine-fixture-matchers.js"
|
8
|
+
|
9
|
+
m.directory "spec/spec_helpers"
|
10
|
+
m.file "spec/spec_helpers/fixture_generator_methods.rb", "spec/spec_helpers/fixture_generator_methods.rb"
|
11
|
+
|
12
|
+
m.readme "INSTALL"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,5 @@
|
|
1
|
+
Jasmine Fixtures have been installed!
|
2
|
+
|
3
|
+
We copied JasmineFixtureHelper.js and LoadFixture.js into your spec/javascripts/helpers dir. In its default configuration, Jasmine should pick these files up.
|
4
|
+
|
5
|
+
Take a look at https://github.com/mavenlink/jasmine-fixtures for tips & more info.
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
#####
|
4
|
+
# Modify this file to create new Jasmine Fixtures!
|
5
|
+
# We have provided an example for you to crib off.
|
6
|
+
|
7
|
+
# Basically:
|
8
|
+
# 1) Visit a route with your controller action
|
9
|
+
# 2) Make sure it's successful
|
10
|
+
# 3) save_fixture with the response you want and the name of the fixture
|
11
|
+
#####
|
12
|
+
|
13
|
+
##### Using save_fixture
|
14
|
+
# html_for will only take the <body> tag and replace it with a <div>
|
15
|
+
# to avoid nested <body> tags within the jasmine runner
|
16
|
+
|
17
|
+
# If you have custom responses (ajax partials, JSON, etc),
|
18
|
+
# you can subvert this and use response.body or whatever.
|
19
|
+
#####
|
20
|
+
|
21
|
+
|
22
|
+
##### Example
|
23
|
+
describe UsersController do
|
24
|
+
it "generates a new user page" do
|
25
|
+
get :new
|
26
|
+
response.should be_success
|
27
|
+
save_fixture(html_for('body'), 'user-signup-page')
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
beforeEach(function() {
|
2
|
+
$('#jasmine_content').empty();
|
3
|
+
spec.cleanupHooks();
|
4
|
+
});
|
5
|
+
|
6
|
+
afterEach(function() {
|
7
|
+
spec.cleanupHooks();
|
8
|
+
expect(spec.loadFixtureCount).toBeLessThan(2);
|
9
|
+
spec.loadFixtureCount = 0;
|
10
|
+
expect($('.ui-dialog').length).toEqual(0);
|
11
|
+
expect($('.ui-autocomplete-results').length).toEqual(0);
|
12
|
+
});
|
13
|
+
|
14
|
+
spec.cleanupHooks = function() {
|
15
|
+
// clearLiveEventBindings is helpful if using jQuery live events
|
16
|
+
// uncomment if you'd like
|
17
|
+
// spec.clearLiveEventBindings();
|
18
|
+
|
19
|
+
window.onbeforeunload = null;
|
20
|
+
};
|
21
|
+
|
22
|
+
spec.clearLiveEventBindings = function() {
|
23
|
+
var events = jQuery.data(document, "events");
|
24
|
+
for (prop in events) {
|
25
|
+
delete events[prop];
|
26
|
+
}
|
27
|
+
};
|
28
|
+
|
29
|
+
spec.content = function() {
|
30
|
+
return $('#jasmine_content');
|
31
|
+
};
|
@@ -0,0 +1,66 @@
|
|
1
|
+
var uniqueLoadIndicator = null;
|
2
|
+
// Loads fixure markup into the DOM as a child of the jasmine_content div
|
3
|
+
spec.loadFixture = function(fixtureName) {
|
4
|
+
var $destination = $('#jasmine_content');
|
5
|
+
|
6
|
+
uniqueLoadIndicator = null;
|
7
|
+
var indicatorScript = "<script>uniqueLoadIndicator = 'loaded';</s" + "cript>";
|
8
|
+
|
9
|
+
// get the markup, inject it into the dom
|
10
|
+
$destination.html(spec.fixtureHtml(fixtureName) + indicatorScript);
|
11
|
+
while (uniqueLoadIndicator != "loaded") {
|
12
|
+
if (console) console.log("FireFox wasn't ready... sleeping.");
|
13
|
+
spec.retrieveFixture(fixtureName);
|
14
|
+
}
|
15
|
+
uniqueLoadIndicator = null;
|
16
|
+
|
17
|
+
bindBehaviors();
|
18
|
+
|
19
|
+
// keep track of fixture count to fail specs that
|
20
|
+
// call loadFixture() more than once
|
21
|
+
spec.loadFixtureCount++;
|
22
|
+
};
|
23
|
+
|
24
|
+
// Returns fixture markup as a string. Useful for fixtures that
|
25
|
+
// represent the response text of ajax requests.
|
26
|
+
spec.readFixture = function(fixtureName) {
|
27
|
+
return spec.fixtureHtml(fixtureName);
|
28
|
+
};
|
29
|
+
|
30
|
+
spec.readJSON = function(fixtureName) {
|
31
|
+
var data = spec.fixtureHtml(fixtureName);
|
32
|
+
return window.JSON && window.JSON.parse ?
|
33
|
+
window.JSON.parse( data ) :
|
34
|
+
(new Function("return " + data))();
|
35
|
+
};
|
36
|
+
|
37
|
+
spec.fixtureHtml = function(fixtureName) {
|
38
|
+
if (!spec.cachedFixtures[fixtureName]) {
|
39
|
+
spec.cachedFixtures[fixtureName] = spec.retrieveFixture(fixtureName);
|
40
|
+
}
|
41
|
+
return spec.cachedFixtures[fixtureName];
|
42
|
+
};
|
43
|
+
|
44
|
+
spec.retrieveFixture = function(fixtureName) {
|
45
|
+
|
46
|
+
// construct a path to the fixture, including a cache-busting timestamp
|
47
|
+
var path = '/tmp/js_dom_fixtures/' + fixtureName + ".fixture.html.erb?" + new Date().getTime();
|
48
|
+
var xhr;
|
49
|
+
|
50
|
+
// retrieve the fixture markup via xhr request to jasmine server
|
51
|
+
try {
|
52
|
+
xhr = new jasmine.XmlHttpRequest();
|
53
|
+
xhr.open("GET", path, false);
|
54
|
+
xhr.send(null);
|
55
|
+
} catch(e) {
|
56
|
+
throw new Error("couldn't fetch " + path + ": " + e);
|
57
|
+
}
|
58
|
+
if (xhr.status < 200 || xhr.status > 299) {
|
59
|
+
throw new Error("Couldn't load fixture with key: '" + fixtureName + "'. No such file: '" + path + "'.");
|
60
|
+
}
|
61
|
+
|
62
|
+
return xhr.responseText;
|
63
|
+
};
|
64
|
+
|
65
|
+
spec.loadFixtureCount = 0;
|
66
|
+
spec.cachedFixtures = {};
|
data/generators/jasmine-fixtures/templates/spec/javascripts/helpers/jasmine-fixture-matchers.js
ADDED
@@ -0,0 +1,253 @@
|
|
1
|
+
jasmine.Matchers.prototype.toBeSameJqueryObjectAs = function(expected) {
|
2
|
+
var error_message = null;
|
3
|
+
if(!expected || !this.actual || this.actual.length != expected.length) {
|
4
|
+
error_message = "Expected to have same number of matching elements";
|
5
|
+
} else {
|
6
|
+
for(var i = 0; i < expected.length; i++) {
|
7
|
+
if (this.actual.get(i) != expected.get(i)) {
|
8
|
+
error_message = "Expected the elements to be the same but were not";
|
9
|
+
break;
|
10
|
+
}
|
11
|
+
}
|
12
|
+
}
|
13
|
+
return this.report(error_message == null, error_message);
|
14
|
+
};
|
15
|
+
|
16
|
+
jasmine.Matchers.prototype.toNotBeSameJqueryObjectAs = function(expected) {
|
17
|
+
var error_message = null;
|
18
|
+
if(!expected || !this.actual || this.actual.length != expected.length) {
|
19
|
+
error_message = "Expected to have same number of matching elements";
|
20
|
+
} else {
|
21
|
+
for(var i = 0; i < expected.length; i++) {
|
22
|
+
if (this.actual.get(i) == expected.get(i)) {
|
23
|
+
error_message = "Expected the elements to not be the same but they were";
|
24
|
+
break;
|
25
|
+
}
|
26
|
+
}
|
27
|
+
}
|
28
|
+
return this.report(error_message == null, error_message);
|
29
|
+
};
|
30
|
+
|
31
|
+
jasmine.Matchers.prototype.toBeCleared = function() {
|
32
|
+
var $form = this.actual;
|
33
|
+
expect($form).toBeSingleton();
|
34
|
+
var $textfields = $form.find('input[type=text]');
|
35
|
+
$textfields.each(function() {
|
36
|
+
expect($(this).val()).toEqual('');
|
37
|
+
});
|
38
|
+
var $textareas = $form.find('textarea');
|
39
|
+
$textareas.each(function() {
|
40
|
+
expect($(this).val()).toEqual('');
|
41
|
+
});
|
42
|
+
};
|
43
|
+
|
44
|
+
jasmine.Matchers.prototype.toBeSingleton = function() {
|
45
|
+
var $element = this.actual;
|
46
|
+
expect($element.length).toEqual(1);
|
47
|
+
};
|
48
|
+
|
49
|
+
jasmine.Matchers.prototype.toContainText = function(expected) {
|
50
|
+
var actual = $(this.actual);
|
51
|
+
return this.report(
|
52
|
+
actual.text().indexOf(expected) != -1,
|
53
|
+
"Expected $('" + actual.selector + "') to contain text " + expected
|
54
|
+
);
|
55
|
+
};
|
56
|
+
|
57
|
+
jasmine.Matchers.prototype.toNotContainText = function(expected) {
|
58
|
+
var actual = $(this.actual);
|
59
|
+
return this.report(
|
60
|
+
actual.text().indexOf(expected) == -1,
|
61
|
+
"Expected $('" + actual.selector + "') to not contain text " + expected
|
62
|
+
);
|
63
|
+
};
|
64
|
+
|
65
|
+
jasmine.Matchers.prototype.toNotBeChecked = function() {
|
66
|
+
var actual = $(this.actual);
|
67
|
+
return this.report(
|
68
|
+
!actual.is(':checked'),
|
69
|
+
"Expected $('" + actual.selector + "') to not be checked"
|
70
|
+
);
|
71
|
+
};
|
72
|
+
|
73
|
+
jasmine.Matchers.prototype.toBeChecked = function() {
|
74
|
+
var actual = $(this.actual);
|
75
|
+
return this.report(
|
76
|
+
actual.is(':checked'),
|
77
|
+
"Expected $('" + actual.selector + "') to be checked"
|
78
|
+
);
|
79
|
+
};
|
80
|
+
|
81
|
+
jasmine.Matchers.prototype.toExist = function() {
|
82
|
+
var actual = $(this.actual);
|
83
|
+
return this.report(
|
84
|
+
actual.length > 0,
|
85
|
+
"Expected $('" + actual.selector + "') to exist but didn't"
|
86
|
+
);
|
87
|
+
};
|
88
|
+
|
89
|
+
jasmine.Matchers.prototype.toNotExist = function() {
|
90
|
+
var actual = $(this.actual);
|
91
|
+
return this.report(
|
92
|
+
actual.length == 0,
|
93
|
+
"Expected $('" + actual.selector + "') to not exist but it did"
|
94
|
+
);
|
95
|
+
};
|
96
|
+
|
97
|
+
jasmine.Matchers.prototype.toContainSelector = function(expected) {
|
98
|
+
var actual = $(this.actual);
|
99
|
+
var children = actual.find(expected);
|
100
|
+
return this.report(
|
101
|
+
children.length > 0,
|
102
|
+
"Expected [" + jasmine.util.htmlEscape(actual.html()) + "] to contain selector [" + $(expected).selector + "] but didn't"
|
103
|
+
);
|
104
|
+
};
|
105
|
+
|
106
|
+
jasmine.Matchers.prototype.toNotContainSelector = function(expected) {
|
107
|
+
var actual = $(this.actual);
|
108
|
+
var children = actual.find(expected);
|
109
|
+
return this.report(
|
110
|
+
children.length == 0,
|
111
|
+
"Expected [" + jasmine.util.htmlEscape(actual.html()) + "] to not contain selector [" + $(expected).selector + "] but it did"
|
112
|
+
);
|
113
|
+
};
|
114
|
+
|
115
|
+
jasmine.Matchers.prototype.toBeVisible = function() {
|
116
|
+
var actual = $(this.actual);
|
117
|
+
var basicMessage = "be visible";
|
118
|
+
return this._reportWithNonExistant(
|
119
|
+
actual.is(':visible'),
|
120
|
+
basicMessage,
|
121
|
+
"Expected '" + actual.selector + "' to " + basicMessage + " but was not"
|
122
|
+
);
|
123
|
+
};
|
124
|
+
|
125
|
+
jasmine.Matchers.prototype.toNotBeVisible = function() {
|
126
|
+
var actual = $(this.actual);
|
127
|
+
var basicMessage = "be hidden";
|
128
|
+
return this._reportWithNonExistant(
|
129
|
+
!actual.is(':visible'),
|
130
|
+
basicMessage,
|
131
|
+
"Expected '" + actual.selector + "' to " + basicMessage + " but was not"
|
132
|
+
);
|
133
|
+
};
|
134
|
+
|
135
|
+
jasmine.Matchers.prototype.toNotBeDisplayed = function() {
|
136
|
+
var actual = $(this.actual);
|
137
|
+
var basicMessage = "be display none";
|
138
|
+
return this._reportWithNonExistant(
|
139
|
+
actual.css("display") == "none",
|
140
|
+
basicMessage,
|
141
|
+
"Expected '" + actual.selector + "' to " + basicMessage + " but was not"
|
142
|
+
);
|
143
|
+
};
|
144
|
+
|
145
|
+
jasmine.Matchers.prototype.toBeDisplayed = function() {
|
146
|
+
var actual = $(this.actual);
|
147
|
+
var basicMessage = "not be display none";
|
148
|
+
return this._reportWithNonExistant(
|
149
|
+
actual.css("display") != "none",
|
150
|
+
basicMessage,
|
151
|
+
"Expected '" + actual.selector + "' to " + basicMessage + " but was"
|
152
|
+
);
|
153
|
+
};
|
154
|
+
|
155
|
+
jasmine.Matchers.prototype.toBeEmpty= function() {
|
156
|
+
var actual = $(this.actual);
|
157
|
+
var basicMessage = "be empty";
|
158
|
+
return this._reportWithNonExistant(
|
159
|
+
actual.html() == "",
|
160
|
+
basicMessage,
|
161
|
+
"Expected '" + actual.selector + "' to " + basicMessage + " but was not"
|
162
|
+
);
|
163
|
+
};
|
164
|
+
|
165
|
+
jasmine.Matchers.prototype.toNotBeEmpty= function() {
|
166
|
+
var actual = $(this.actual);
|
167
|
+
var basicMessage = "not be empty";
|
168
|
+
return this._reportWithNonExistant(
|
169
|
+
actual.html() != "",
|
170
|
+
basicMessage,
|
171
|
+
"Expected '" + actual.selector + "' to " + basicMessage + " but it was"
|
172
|
+
);
|
173
|
+
};
|
174
|
+
|
175
|
+
jasmine.Matchers.prototype.toHaveClass= function(expected) {
|
176
|
+
var actual = $(this.actual);
|
177
|
+
var basicMessage = "have class " + expected;
|
178
|
+
return this._reportWithNonExistant(
|
179
|
+
actual.hasClass(expected),
|
180
|
+
basicMessage,
|
181
|
+
"Expected '" + actual.selector + "' to " + basicMessage + " but does not"
|
182
|
+
);
|
183
|
+
};
|
184
|
+
|
185
|
+
jasmine.Matchers.prototype.toNotHaveClass= function(expected) {
|
186
|
+
var actual = $(this.actual);
|
187
|
+
var basicMessage = "not have class " + expected;
|
188
|
+
return this._reportWithNonExistant(
|
189
|
+
!actual.hasClass(expected),
|
190
|
+
basicMessage,
|
191
|
+
"Expected '" + actual.selector + "' to " + basicMessage + " but it does"
|
192
|
+
);
|
193
|
+
};
|
194
|
+
|
195
|
+
jasmine.Matchers.prototype.toBeDisabled= function() {
|
196
|
+
var actual = $(this.actual);
|
197
|
+
var basicMessage = "be disabled";
|
198
|
+
return this._reportWithNonExistant(
|
199
|
+
actual.is(":disabled"),
|
200
|
+
basicMessage,
|
201
|
+
"Expected '" + actual.selector + "' to " + basicMessage + " but was not"
|
202
|
+
);
|
203
|
+
};
|
204
|
+
|
205
|
+
jasmine.Matchers.prototype.toBeEnabled= function() {
|
206
|
+
var actual = $(this.actual);
|
207
|
+
var basicMessage = "be enabled";
|
208
|
+
return this._reportWithNonExistant(
|
209
|
+
actual.is(":enabled"),
|
210
|
+
basicMessage,
|
211
|
+
"Expected '" + actual.selector + "' to " + basicMessage + " but was not"
|
212
|
+
);
|
213
|
+
};
|
214
|
+
|
215
|
+
jasmine.Matchers.prototype.toBeTag= function(tagName) {
|
216
|
+
var actual = $(this.actual);
|
217
|
+
var basicMessage = "be a tag of type '" + tagName + "'";
|
218
|
+
var actualTagName = "your element";
|
219
|
+
if(actual.length > 0) {
|
220
|
+
actualTagName = actual.get(0).tagName.toLowerCase();
|
221
|
+
}
|
222
|
+
return this._reportWithNonExistant(
|
223
|
+
actual.is(tagName),
|
224
|
+
basicMessage,
|
225
|
+
"Expected '" + actualTagName + "' to " + basicMessage + " but was not"
|
226
|
+
);
|
227
|
+
};
|
228
|
+
|
229
|
+
jasmine.Matchers.prototype.toHaveAttribute= function(attr, value) {
|
230
|
+
var actual = $(this.actual);
|
231
|
+
var basicMessage = "have attribute '" + attr + "' with value '" + value + "'";
|
232
|
+
var actualValue = actual.attr(attr);
|
233
|
+
return this._reportWithNonExistant(
|
234
|
+
actualValue == value,
|
235
|
+
basicMessage,
|
236
|
+
"Expected '" + actual.selector + "' to " + basicMessage + " but instead had '" + actualValue + "'"
|
237
|
+
);
|
238
|
+
};
|
239
|
+
|
240
|
+
jasmine.Matchers.prototype._reportWithNonExistant = function(test, basicMesage, fullMessage) {
|
241
|
+
var actual = $(this.actual);
|
242
|
+
if(actual.length > 0) {
|
243
|
+
return this.report(
|
244
|
+
test,
|
245
|
+
fullMessage
|
246
|
+
);
|
247
|
+
} else {
|
248
|
+
return this.report(
|
249
|
+
false,
|
250
|
+
"Expected '" + actual.selector + "' to "+ basicMesage +" but the element didn't exist."
|
251
|
+
);
|
252
|
+
}
|
253
|
+
};
|
data/generators/jasmine-fixtures/templates/spec/spec_helpers/jasmine_fixture_generator_methods.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# Add fixture-generation methods to ControllerExampleGroup. We load
|
2
|
+
# this file within our spec_helper.rb
|
3
|
+
|
4
|
+
Spec::Rails::Example::ControllerExampleGroup.class_eval do
|
5
|
+
|
6
|
+
# Saves the markup to a fixture file using the given name
|
7
|
+
def save_fixture(markup, name)
|
8
|
+
fixture_path = File.join(RAILS_ROOT, '/tmp/js_dom_fixtures')
|
9
|
+
Dir.mkdir(fixture_path) unless File.exists?(fixture_path)
|
10
|
+
|
11
|
+
fixture_file = File.join(fixture_path, "#{name}.fixture.html.erb")
|
12
|
+
File.open(fixture_file, 'w') do |file|
|
13
|
+
file.puts(markup)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# From the controller spec response body, extracts html identified
|
18
|
+
# by the css selector.
|
19
|
+
def html_for(selector)
|
20
|
+
doc = Nokogiri::HTML(response.body)
|
21
|
+
|
22
|
+
remove_third_party_scripts(doc)
|
23
|
+
content = doc.css(selector).first.to_s
|
24
|
+
|
25
|
+
return convert_body_tag_to_div(content)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Remove scripts such as Google Analytics to avoid running them
|
29
|
+
# when we load into the dom during js specs.
|
30
|
+
def remove_third_party_scripts(doc)
|
31
|
+
scripts = doc.at('#third-party-scripts')
|
32
|
+
scripts.remove if scripts
|
33
|
+
end
|
34
|
+
|
35
|
+
# Many of our css and jQuery selectors rely on a class attribute we
|
36
|
+
# normally embed in the <body>. For example:
|
37
|
+
#
|
38
|
+
# <body class="workspaces show">
|
39
|
+
#
|
40
|
+
# Here we convert the body tag to a div so that we can load it into
|
41
|
+
# the document running js specs without embedding a <body> within a <body>.
|
42
|
+
def convert_body_tag_to_div(markup)
|
43
|
+
return markup.gsub("<body", '<div').gsub("</body>", "</div>")
|
44
|
+
end
|
45
|
+
end
|
File without changes
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jasmine-fixtures
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Roger Neel
|
14
|
+
- Jonathan Barnes
|
15
|
+
- JB Steadman
|
16
|
+
autorequire:
|
17
|
+
bindir: bin
|
18
|
+
cert_chain: []
|
19
|
+
|
20
|
+
date: 2010-11-07 00:00:00 -07:00
|
21
|
+
default_executable:
|
22
|
+
dependencies:
|
23
|
+
- !ruby/object:Gem::Dependency
|
24
|
+
name: rspec
|
25
|
+
prerelease: false
|
26
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
27
|
+
none: false
|
28
|
+
requirements:
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
hash: 13
|
32
|
+
segments:
|
33
|
+
- 1
|
34
|
+
- 2
|
35
|
+
- 9
|
36
|
+
version: 1.2.9
|
37
|
+
type: :development
|
38
|
+
version_requirements: *id001
|
39
|
+
description: Dump out DOM that you want to test. Use jasmine-fixtures to load that DOM into your Jasmine specs. See github.com/mavenlink/jasmine-fixtures for more.
|
40
|
+
email: roger@mavenlink.com
|
41
|
+
executables: []
|
42
|
+
|
43
|
+
extensions: []
|
44
|
+
|
45
|
+
extra_rdoc_files:
|
46
|
+
- LICENSE
|
47
|
+
- README.rdoc
|
48
|
+
files:
|
49
|
+
- .bundle/config
|
50
|
+
- .document
|
51
|
+
- .gitignore
|
52
|
+
- .pairs
|
53
|
+
- Gemfile
|
54
|
+
- Gemfile.lock
|
55
|
+
- LICENSE
|
56
|
+
- README.rdoc
|
57
|
+
- Rakefile
|
58
|
+
- VERSION
|
59
|
+
- generators/jasmine-fixtures/jasmine_fixtures_generator.rb
|
60
|
+
- generators/jasmine-fixtures/templates/INSTALL
|
61
|
+
- generators/jasmine-fixtures/templates/spec/controllers/jasmine_fixture_creators.rb
|
62
|
+
- generators/jasmine-fixtures/templates/spec/javascripts/helpers/jasmine-fixture-helper.js
|
63
|
+
- generators/jasmine-fixtures/templates/spec/javascripts/helpers/jasmine-fixture-loader.js
|
64
|
+
- generators/jasmine-fixtures/templates/spec/javascripts/helpers/jasmine-fixture-matchers.js
|
65
|
+
- generators/jasmine-fixtures/templates/spec/spec_helpers/jasmine_fixture_generator_methods.rb
|
66
|
+
- lib/jasmine-fixtures.rb
|
67
|
+
- spec/jasmine-fixtures_spec.rb
|
68
|
+
- spec/spec.opts
|
69
|
+
- spec/spec_helper.rb
|
70
|
+
has_rdoc: true
|
71
|
+
homepage: http://github.com/mavenlink/jasmine-fixtures
|
72
|
+
licenses: []
|
73
|
+
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options:
|
76
|
+
- --charset=UTF-8
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
hash: 3
|
85
|
+
segments:
|
86
|
+
- 0
|
87
|
+
version: "0"
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
hash: 3
|
94
|
+
segments:
|
95
|
+
- 0
|
96
|
+
version: "0"
|
97
|
+
requirements: []
|
98
|
+
|
99
|
+
rubyforge_project:
|
100
|
+
rubygems_version: 1.3.7
|
101
|
+
signing_key:
|
102
|
+
specification_version: 3
|
103
|
+
summary: Jasmine Fixtures allow you to use real DOM to test your JavaScript
|
104
|
+
test_files:
|
105
|
+
- spec/jasmine-fixtures_spec.rb
|
106
|
+
- spec/spec_helper.rb
|