Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add more specs and bump version to 1.3

  • Loading branch information...
commit d38fc5c6d2fc8782e6cc7abc2e3de11b8f70648b 1 parent 0ee9334
Matthieu Aussaguel authored
View
2  Guardfile
@@ -1,7 +1,7 @@
# A sample Guardfile
# More info at https://github.com/guard/guard#readme
-guard 'coffeescript', :output => 'javascripts' do
+guard 'coffeescript', :output => 'js' do
watch /^js\/.*[.]coffee/
end
View
2  README.md
@@ -4,7 +4,7 @@ jQuery Plugin Boilerplate written in CoffeeScript to help you create plugins in
## Verion
-v1.2 Stable
+v1.3 Stable
## Website Url
View
12 js/plugin.coffee
@@ -1,17 +1,17 @@
#
# CoffeeScript jQuery Plugin Boilerplace
-# Author: Matthieu Aussaguel, http://www.mynameismatthieu.com, @mattaussaguel
-# Version: 1.2 Stable
-# Updated: June 11, 2012
-# More info: http://minijs.com/
+# Author: Matthieu Aussaguel, http://www.mynameismatthieu.com, @mattaussaguel
+# Version: 1.3 Stable
+# Updated: June 14, 2012
+# Website: http://minijs.github.com/miniBoilerplate/
#
jQuery ->
$.pluginName = (element, options) ->
# default plugin settings
@defaults =
- message: 'hellow word' # option description
- callback: -> # callback description
+ message: 'hello word' # option description
+ callback: -> # callback description
# current state
@state = ''
View
7 js/plugin.js
@@ -1,4 +1,3 @@
-// Generated by CoffeeScript 1.3.3
(function() {
jQuery(function() {
@@ -6,7 +5,7 @@
var init, setState,
_this = this;
this.defaults = {
- message: 'hellow word',
+ message: 'hello word',
callback: function() {}
};
this.state = '';
@@ -22,9 +21,7 @@
return this.settings[settingKey];
};
this.callSettingFunction = function(functionName, args) {
- if (args == null) {
- args = [];
- }
+ if (args == null) args = [];
return this.settings[functionName].apply(this, args);
};
init = function() {
View
32 spec/javascripts/PluginSpec.coffee
@@ -1,26 +1,42 @@
-describe "PluginName", ->
+describe 'PluginName', ->
options =
message: 'Hello World'
- callback: (element, message) -> $(element).append("#{message}!")
+ callback: (element, text) -> $(element).append("#{text}!")
beforeEach ->
loadFixtures 'fragment.html'
@$element = $('#fixtures')
- it "should be available on the jQuery object", ->
+ it 'should be available on the jQuery object', ->
expect($.fn.pluginName).toBeDefined()
- it "should be chainable", ->
+ it 'should be chainable', ->
expect(@$element.pluginName(options)).toBe(@$element)
- it "should offers default values", ->
+ it 'should offers default values', ->
plugin = new $.pluginName(@$element[0], options)
+
expect(plugin.defaults).toBeDefined()
- it "should overwrites the settings", ->
+ it 'should overwrites the settings', ->
plugin = new $.pluginName(@$element[0], options)
+
expect(plugin.settings.message).toBe(options.message)
expect(plugin.settings.callback).toBe(options.callback)
- it "should execute the callback method", ->
- expect(@$element.pluginName(options)).toHaveText 'Hello World!'
+ it 'should execute the callback append the hello world! to the element', ->
+ @$element.pluginName(options)
+
+ expect(@$element).toHaveText 'Hello World!'
+
+ it 'should execute the callback the right arguments', ->
+ foo = jasmine.createSpy('foo')
+ plugin = new $.pluginName(@$element, {message: 'Hello World', callback: foo})
+
+ expect(foo).toHaveBeenCalled()
+ expect(foo.mostRecentCall.args[0]).toBe @$element
+ expect(foo.mostRecentCall.args[1]).toBe "Hello World"
+
+
+
+
View
30 spec/javascripts/PluginSpec.js
@@ -1,36 +1,48 @@
(function() {
- describe("PluginName", function() {
+ describe('PluginName', function() {
var options;
options = {
message: 'Hello World',
- callback: function(element, message) {
- return $(element).append("" + message + "!");
+ callback: function(element, text) {
+ return $(element).append("" + text + "!");
}
};
beforeEach(function() {
loadFixtures('fragment.html');
return this.$element = $('#fixtures');
});
- it("should be available on the jQuery object", function() {
+ it('should be available on the jQuery object', function() {
return expect($.fn.pluginName).toBeDefined();
});
- it("should be chainable", function() {
+ it('should be chainable', function() {
return expect(this.$element.pluginName(options)).toBe(this.$element);
});
- it("should offers default values", function() {
+ it('should offers default values', function() {
var plugin;
plugin = new $.pluginName(this.$element[0], options);
return expect(plugin.defaults).toBeDefined();
});
- it("should overwrites the settings", function() {
+ it('should overwrites the settings', function() {
var plugin;
plugin = new $.pluginName(this.$element[0], options);
expect(plugin.settings.message).toBe(options.message);
return expect(plugin.settings.callback).toBe(options.callback);
});
- return it("should execute the callback method", function() {
- return expect(this.$element.pluginName(options)).toHaveText('Hello World!');
+ it('should execute the callback append the hello world! to the element', function() {
+ this.$element.pluginName(options);
+ return expect(this.$element).toHaveText('Hello World!');
+ });
+ return it('should execute the callback the right arguments', function() {
+ var foo, plugin;
+ foo = jasmine.createSpy('foo');
+ plugin = new $.pluginName(this.$element, {
+ message: 'Hello World',
+ callback: foo
+ });
+ expect(foo).toHaveBeenCalled();
+ expect(foo.mostRecentCall.args[0]).toBe(this.$element);
+ return expect(foo.mostRecentCall.args[1]).toBe("Hello World");
});
});
Please sign in to comment.
Something went wrong with that request. Please try again.