Skip to content

Commit a6c56e5

Browse files
committed
Adding Jasmine test framework and basic test example
1 parent 17e8301 commit a6c56e5

9 files changed

+179
-13
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
*.rbc
33
.bundle
44
.config
5+
.grunt
56
.yardoc
67
.idea
78
InstalledFiles
@@ -17,6 +18,7 @@ test/tmp
1718
test/version_tmp
1819
test/css
1920
test/scss/output-test
21+
vendor/
2022
tmp
2123
*.DS_Store
2224
marketing/.sass-cache/*

Gemfile.lock

+29
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,42 @@ PATH
77
GEM
88
remote: https://rubygems.org/
99
specs:
10+
childprocess (0.3.9)
11+
ffi (~> 1.0, >= 1.0.11)
12+
diff-lcs (1.2.4)
13+
ffi (1.9.0)
14+
ffi (1.9.0-x86-mingw32)
15+
jasmine (1.3.2)
16+
jasmine-core (~> 1.3.1)
17+
rack (~> 1.0)
18+
rspec (>= 1.3.1)
19+
selenium-webdriver (>= 0.1.3)
20+
jasmine-core (1.3.1)
21+
multi_json (1.7.9)
22+
rack (1.5.2)
1023
rake (10.0.3)
24+
rspec (2.14.1)
25+
rspec-core (~> 2.14.0)
26+
rspec-expectations (~> 2.14.0)
27+
rspec-mocks (~> 2.14.0)
28+
rspec-core (2.14.5)
29+
rspec-expectations (2.14.2)
30+
diff-lcs (>= 1.1.3, < 2.0)
31+
rspec-mocks (2.14.3)
32+
rubyzip (0.9.9)
1133
sass (3.2.9)
34+
selenium-webdriver (2.35.1)
35+
childprocess (>= 0.2.5)
36+
multi_json (~> 1.0)
37+
rubyzip (< 1.0.0)
38+
websocket (~> 1.0.4)
39+
websocket (1.0.7)
1240

1341
PLATFORMS
1442
ruby
1543
x86-mingw32
1644

1745
DEPENDENCIES
46+
jasmine
1847
rake
1948
zurb-foundation!

Gruntfile.js

+54-10
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,71 @@
11
module.exports = function(grunt) {
22

3-
grunt.loadNpmTasks('grunt-contrib-qunit');
3+
grunt.loadNpmTasks('grunt-contrib-jasmine');
44
grunt.loadNpmTasks('grunt-contrib-watch');
5+
grunt.loadNpmTasks('grunt-contrib-sass');
56

67
grunt.initConfig({
7-
qunit: {
8-
all: ['test/javascripts/tests/**/*.html']
8+
jasmine: {
9+
src: [
10+
'js/foundation/foundation.js',
11+
'js/foundation/*.js'
12+
],
13+
options: {
14+
specs: 'spec/**/*Spec.js',
15+
helpers: 'spec/**/*Helper.js',
16+
keepRunner: true,
17+
styles: ['test/stylesheets/normalize.css', 'test/stylesheets/foundation.css']
18+
},
19+
20+
zepto: {
21+
src: '<%= jasmine.src %>',
22+
options: {
23+
outfile: 'test/_SpecRunner_zepto.html',
24+
vendor: [
25+
'js/vendor/custom.modernizr.js',
26+
'js/vendor/zepto.js'
27+
],
28+
}
29+
},
30+
31+
jquery: {
32+
src: '<%= jasmine.src %>',
33+
options: {
34+
outfile: 'test/_SpecRunner_jquery.html',
35+
vendor: [
36+
'js/vendor/custom.modernizr.js',
37+
'js/vendor/jquery.js'
38+
]
39+
}
40+
}
41+
},
42+
sass: {
43+
test: {
44+
files: {
45+
'test/stylesheets/normalize.css' : 'scss/normalize.scss',
46+
'test/stylesheets/foundation.css' : 'scss/foundation.scss'
47+
}
48+
}
949
},
1050
watch: {
11-
all: {
51+
css: {
52+
files: 'scss/**/*.scss',
53+
tasks: ['sass']
54+
},
55+
tests: {
1256
files: [
13-
'test/javascripts/tests/**/*.html',
14-
'test/javascripts/tests/**/*.js',
15-
'lib/assets/javascripts/foundation/*.js'
57+
'js/**/*.js',
58+
'spec/**/*.js'
1659
],
17-
tasks: 'default',
60+
tasks: 'test',
1861
options: {
1962
interrupt: true
2063
}
2164
}
2265
}
2366
});
2467

25-
// Default task.
26-
grunt.registerTask('default', ['qunit']);
68+
grunt.registerTask('test', ['sass:test', 'jasmine:zepto', 'jasmine:jquery']);
69+
70+
grunt.registerTask('default', ['test']);
2771
};

Rakefile

+9
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,11 @@
11
#!/usr/bin/env rake
22
require "bundler/gem_tasks"
3+
4+
begin
5+
require 'jasmine'
6+
load 'jasmine/tasks/jasmine.rake'
7+
rescue LoadError
8+
task :jasmine do
9+
abort "Jasmine is not available. In order to run jasmine, you must: (sudo) gem install jasmine"
10+
end
11+
end

foundation.gemspec

+1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ Gem::Specification.new do |gem|
1717

1818
gem.add_dependency "sass", [">= 3.2.0"]
1919
gem.add_development_dependency "rake"
20+
gem.add_development_dependency "jasmine"
2021
end

package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
"name": "zurb-foundation",
33
"version": "4.0.0-wip",
44
"devDependencies": {
5-
"grunt": "~0.4.0",
6-
"grunt-contrib-watch": "~0.1.0",
7-
"grunt-contrib-qunit": "~0.1.1"
5+
"grunt": "~0.4.1",
6+
"grunt-contrib-watch": "~0.5.3",
7+
"grunt-contrib-jasmine": "~0.5.1",
8+
"grunt-contrib-sass": "~0.5.0"
89
},
910
"licenses": [
1011
{

spec/js/SectionSpec.js

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
describe('Section', function() {
2+
var template = {
3+
auto: '\
4+
<div class="section-container auto" data-section> \
5+
</div>'
6+
};
7+
8+
var settings = Foundation.libs.section.settings;
9+
10+
describe('auto with defaults', function() {
11+
12+
beforeEach(function() {
13+
$('#htmlFixture').append(template.auto);
14+
});
15+
16+
it('should be tabs at small breakpoint', function() {
17+
setDocumentWidth(settings.small_breakpoint);
18+
19+
$(document).foundation('section');
20+
jasmine.Clock.tick(1000); // Let things settle...
21+
22+
var section = $(settings.section_selector)
23+
expect(section).isAuto();
24+
expect(section).not.isAccordion();
25+
expect(section).isHorizontalTabs();
26+
});
27+
28+
it('should be accordion below small breakpoint', function() {
29+
setDocumentWidth(settings.small_breakpoint - 1);
30+
31+
$(document).foundation('section');
32+
jasmine.Clock.tick(1000); // Let things settle...
33+
34+
var section = $(settings.section_selector)
35+
expect(section).isAuto();
36+
expect(section).isAccordion();
37+
});
38+
});
39+
});

spec/js/helpers/SectionSpecHelper.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
beforeEach(function() {
2+
this.addMatchers({
3+
isAccordion: function() {
4+
var sectionLib = Foundation.libs.section;
5+
var settings = sectionLib.settings;
6+
return sectionLib.is_accordion(this.actual) ||
7+
(sectionLib.is_auto(this.actual) &&
8+
this.actual.is("[" + settings.small_style_data_attr + "]"));
9+
},
10+
isAuto: function() {
11+
var sectionLib = Foundation.libs.section;
12+
var settings = sectionLib.settings;
13+
return sectionLib.is_auto(this.actual);
14+
},
15+
isHorizontalTabs: function() {
16+
var sectionLib = Foundation.libs.section;
17+
var settings = sectionLib.settings;
18+
return sectionLib.is_horizontal_tabs(this.actual) ||
19+
(sectionLib.is_auto(this.actual) && !this.actual.is("[" + settings.small_style_data_attr + "]"));
20+
}
21+
});
22+
});

spec/js/helpers/SpecHelper.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
beforeEach(function() {
2+
jasmine.Clock.useMock();
3+
$('body').append('<div id="htmlFixture"></div>');
4+
});
5+
6+
afterEach(function() {
7+
$('#htmlFixture').remove();
8+
});
9+
10+
function setDocumentWidth(width) {
11+
var origWidthFunc = $.fn.width;
12+
var widthSpy = spyOn($.fn, 'width').andCallFake(function() {
13+
if(this[0].nodeName === '#document') {
14+
return width;
15+
} else {
16+
return origWidthFunc.apply(this);
17+
}
18+
});
19+
}

0 commit comments

Comments
 (0)