Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Phoenix #70

Open
wants to merge 5 commits into
base: phoenix
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
*.swo
*.orig
Gemfile.lock
.jhw-cache
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ gem 'rake'

group :development do
gem 'jasmine', '~>1.0'
gem 'jasmine-headless-webkit'
gem 'guard-jasmine-headless-webkit'
end

7 changes: 7 additions & 0 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
spec_location = "spec/javascripts/%s.spec"

guard 'jasmine-headless-webkit' do
watch(%r{^public/javascripts/(.*)\.js$}) { |m| newest_js_file(spec_location % m[1]) }
watch(%r{^spec/javascripts/helpers*})
watch(%r{^spec/javascripts/(.*)\.spec\..*}) { |m| newest_js_file(spec_location % m[1]) }
end
5 changes: 5 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
require 'jasmine'
load 'jasmine/tasks/jasmine.rake'

require 'jasmine-headless-webkit'
Jasmine::Headless::Task.new('jasmine:headless') do |t|
t.colors = true
end
16 changes: 16 additions & 0 deletions spec/javascripts/attributeHandlers.spec.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class View extends Backbone.View
render: ->
@$el.html("<div data-bind='text fn:foo|fn-test'/>")
Backbone.Phoenix.bind(this)

describe "attribute handlers", ->

context "registering an attribute handler", ->
Given -> Backbone.Phoenix.addAttributeHandler "fn", @handler = jasmine.createSpy()
Given -> @model = new Backbone.Model()
Given -> new View(model: @model).render()

When -> @model.set("fn-test": "foo bar")

Then -> expect(@handler).toHaveBeenCalledWith("foo", "foo bar")

32 changes: 0 additions & 32 deletions spec/javascripts/attributeHandlers.spec.js

This file was deleted.

3 changes: 3 additions & 0 deletions spec/javascripts/helpers/SpecHelper.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
window.context = window.describe;
window.xcontext = window.xdescribe;

beforeEach(function() {
this.addMatchers({
})
Expand Down
108 changes: 108 additions & 0 deletions spec/javascripts/helpers/jasmine-given-0.0.6.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
(function() {

(function(jasmine) {
var mostRecentlyUsed, o, stringifyExpectation;
stringifyExpectation = function(expectation) {
var matches;
matches = expectation.toString().replace(/\n/g, '').match(/function\s?\(\)\s?{\s*(return\s+)?(.*?)(;)?\s*}/i);
if (matches && matches.length >= 3) {
return matches[2];
} else {
return "";
}
};
beforeEach(function() {
return this.addMatchers({
toHaveReturnedFalseFromThen: function(context, n) {
var exception, result;
result = false;
exception = void 0;
try {
result = this.actual.call(context);
} catch (e) {
exception = e;
}
this.message = function() {
var msg;
msg = "Then clause " + (n > 1 ? " #" + n : "") + " `" + (stringifyExpectation(this.actual)) + "` failed by ";
if (exception) {
msg += "throwing: " + exception.toString();
} else {
msg += "returning false";
}
return msg;
};
return result === false;
}
});
});
window.When = window.Given = function() {
var assignResultTo, mostRecentlyUsed, setupFunction;
setupFunction = o(arguments).firstThat(function(arg) {
return o(arg).isFunction();
});
assignResultTo = o(arguments).firstThat(function(arg) {
return o(arg).isString();
});
mostRecentlyUsed = window.Given;
return beforeEach(function() {
var context, result;
context = jasmine.getEnv().currentSpec;
result = setupFunction.call(context);
if (assignResultTo) {
if (!context[assignResultTo]) {
return context[assignResultTo] = result;
} else {
throw new Error("Unfortunately, the variable '" + assignResultTo + "' is already assigned to: " + context[assignResultTo]);
}
}
});
};
window.Then = function(expectationFunction) {
var expectations, mostRecentlyUsed, subsequentThen;
mostRecentlyUsed = window.Then;
expectations = [expectationFunction];
subsequentThen = function(additionalExpectation) {
expectations.push(additionalExpectation);
return this;
};
it("then " + (stringifyExpectation(expectations)), function() {
var i, _results;
i = 0;
_results = [];
while (i < expectations.length) {
expect(expectations[i]).not.toHaveReturnedFalseFromThen(jasmine.getEnv().currentSpec, i + 1);
_results.push(i++);
}
return _results;
});
return {
Then: subsequentThen,
And: subsequentThen
};
};
mostRecentlyUsed = window.Given;
window.And = function() {
return mostRecentlyUsed.apply(this, jasmine.util.argsToArray(arguments));
};
return o = function(thing) {
return {
isFunction: function() {
return Object.prototype.toString.call(thing) === "[object Function]";
},
isString: function() {
return Object.prototype.toString.call(thing) === "[object String]";
},
firstThat: function(test) {
var i;
i = 0;
while (i < thing.length) {
if (test(thing[i]) === true) return thing[i];
i++;
}
}
};
};
})(jasmine);

}).call(this);
1 change: 1 addition & 0 deletions spec/javascripts/support/jasmine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ helpers:
# - **/*[sS]pec.js
#
spec_files:
- "**/*[sS]pec.{js,coffee}"

# src_dir
#
Expand Down