Skip to content

Commit

Permalink
Add more specs and bump version to 1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthieu Aussaguel committed Jun 14, 2012
1 parent 0ee9334 commit d38fc5c
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Guardfile
@@ -1,7 +1,7 @@
# A sample Guardfile # A sample Guardfile
# More info at https://github.com/guard/guard#readme # More info at https://github.com/guard/guard#readme


guard 'coffeescript', :output => 'javascripts' do guard 'coffeescript', :output => 'js' do
watch /^js\/.*[.]coffee/ watch /^js\/.*[.]coffee/
end end


Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -4,7 +4,7 @@ jQuery Plugin Boilerplate written in CoffeeScript to help you create plugins in


## Verion ## Verion


v1.2 Stable v1.3 Stable


## Website Url ## Website Url


Expand Down
12 changes: 6 additions & 6 deletions js/plugin.coffee
@@ -1,17 +1,17 @@
# #
# CoffeeScript jQuery Plugin Boilerplace # CoffeeScript jQuery Plugin Boilerplace
# Author: Matthieu Aussaguel, http://www.mynameismatthieu.com, @mattaussaguel # Author: Matthieu Aussaguel, http://www.mynameismatthieu.com, @mattaussaguel
# Version: 1.2 Stable # Version: 1.3 Stable
# Updated: June 11, 2012 # Updated: June 14, 2012
# More info: http://minijs.com/ # Website: http://minijs.github.com/miniBoilerplate/
# #


jQuery -> jQuery ->
$.pluginName = (element, options) -> $.pluginName = (element, options) ->
# default plugin settings # default plugin settings
@defaults = @defaults =
message: 'hellow word' # option description message: 'hello word' # option description
callback: -> # callback description callback: -> # callback description


# current state # current state
@state = '' @state = ''
Expand Down
7 changes: 2 additions & 5 deletions js/plugin.js
@@ -1,12 +1,11 @@
// Generated by CoffeeScript 1.3.3
(function() { (function() {


jQuery(function() { jQuery(function() {
$.pluginName = function(element, options) { $.pluginName = function(element, options) {
var init, setState, var init, setState,
_this = this; _this = this;
this.defaults = { this.defaults = {
message: 'hellow word', message: 'hello word',
callback: function() {} callback: function() {}
}; };
this.state = ''; this.state = '';
Expand All @@ -22,9 +21,7 @@
return this.settings[settingKey]; return this.settings[settingKey];
}; };
this.callSettingFunction = function(functionName, args) { this.callSettingFunction = function(functionName, args) {
if (args == null) { if (args == null) args = [];
args = [];
}
return this.settings[functionName].apply(this, args); return this.settings[functionName].apply(this, args);
}; };
init = function() { init = function() {
Expand Down
32 changes: 24 additions & 8 deletions spec/javascripts/PluginSpec.coffee
@@ -1,26 +1,42 @@
describe "PluginName", -> describe 'PluginName', ->
options = options =
message: 'Hello World' message: 'Hello World'
callback: (element, message) -> $(element).append("#{message}!") callback: (element, text) -> $(element).append("#{text}!")


beforeEach -> beforeEach ->
loadFixtures 'fragment.html' loadFixtures 'fragment.html'
@$element = $('#fixtures') @$element = $('#fixtures')


it "should be available on the jQuery object", -> it 'should be available on the jQuery object', ->
expect($.fn.pluginName).toBeDefined() expect($.fn.pluginName).toBeDefined()


it "should be chainable", -> it 'should be chainable', ->
expect(@$element.pluginName(options)).toBe(@$element) expect(@$element.pluginName(options)).toBe(@$element)


it "should offers default values", -> it 'should offers default values', ->
plugin = new $.pluginName(@$element[0], options) plugin = new $.pluginName(@$element[0], options)

expect(plugin.defaults).toBeDefined() expect(plugin.defaults).toBeDefined()


it "should overwrites the settings", -> it 'should overwrites the settings', ->
plugin = new $.pluginName(@$element[0], options) plugin = new $.pluginName(@$element[0], options)

expect(plugin.settings.message).toBe(options.message) expect(plugin.settings.message).toBe(options.message)
expect(plugin.settings.callback).toBe(options.callback) expect(plugin.settings.callback).toBe(options.callback)


it "should execute the callback method", -> it 'should execute the callback append the hello world! to the element', ->
expect(@$element.pluginName(options)).toHaveText 'Hello World!' @$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"




30 changes: 21 additions & 9 deletions spec/javascripts/PluginSpec.js
@@ -1,36 +1,48 @@
(function() { (function() {


describe("PluginName", function() { describe('PluginName', function() {
var options; var options;
options = { options = {
message: 'Hello World', message: 'Hello World',
callback: function(element, message) { callback: function(element, text) {
return $(element).append("" + message + "!"); return $(element).append("" + text + "!");
} }
}; };
beforeEach(function() { beforeEach(function() {
loadFixtures('fragment.html'); loadFixtures('fragment.html');
return this.$element = $('#fixtures'); 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(); return expect($.fn.pluginName).toBeDefined();
}); });
it("should be chainable", function() { it('should be chainable', function() {
return expect(this.$element.pluginName(options)).toBe(this.$element); return expect(this.$element.pluginName(options)).toBe(this.$element);
}); });
it("should offers default values", function() { it('should offers default values', function() {
var plugin; var plugin;
plugin = new $.pluginName(this.$element[0], options); plugin = new $.pluginName(this.$element[0], options);
return expect(plugin.defaults).toBeDefined(); return expect(plugin.defaults).toBeDefined();
}); });
it("should overwrites the settings", function() { it('should overwrites the settings', function() {
var plugin; var plugin;
plugin = new $.pluginName(this.$element[0], options); plugin = new $.pluginName(this.$element[0], options);
expect(plugin.settings.message).toBe(options.message); expect(plugin.settings.message).toBe(options.message);
return expect(plugin.settings.callback).toBe(options.callback); return expect(plugin.settings.callback).toBe(options.callback);
}); });
return it("should execute the callback method", function() { it('should execute the callback append the hello world! to the element', function() {
return expect(this.$element.pluginName(options)).toHaveText('Hello World!'); 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");
}); });
}); });


Expand Down

0 comments on commit d38fc5c

Please sign in to comment.