Removed Prototype.js support

This commit is contained in:
JR Boyens 2012-12-19 23:18:22 -08:00
parent ae89125d72
commit 302aab3696
24 changed files with 3 additions and 8429 deletions

View File

@ -1,2 +0,0 @@
require 'jasmine'
load 'jasmine/tasks/jasmine.rake'

View File

@ -1,59 +0,0 @@
body {
margin-top: 100px;
text-align: center;
}
#wrap {
width: 800px;
margin: 0 auto;
text-align: left;
}
#twit_search {
margin-bottom: 75px;
}
#twit_search form {
color: #555555;
text-align: center;
font-size: 150%;
}
#twit_search form input[type=text] {
font-size: 100%;
color: #555555;
border: 2px solid black;
-moz-border-radius: 2px;
-webkit-border-radius: 2px;
padding: 4px 6px;
}
#twit_search form input[type=submit] {
font-size: 130%;
}
#results {
margin: 0 auto;
width: 60%;
}
#results li {
margin: 38px 0;
}
#results img {
clear: both;
margin-right: 10px;
float: left;
}
#results img + p {
font-size: 130%;
color: #333333;
}
#results p.user, #results p.timestamp {
margin-top: 5px;
text-align: right;
font-style: italic;
}

View File

@ -1,47 +0,0 @@
/* From http://meyerweb.com/eric/thoughts/2007/05/01/reset-reloaded/ */
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, font, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td {
margin: 0;
padding: 0;
border: 0;
outline: 0;
font-weight: inherit;
font-style: inherit;
font-size: 100%;
font-family: inherit;
vertical-align: baseline;
}
/* remember to define focus styles! */
:focus {
outline: 0;
}
body {
line-height: 1;
color: black;
background: white;
}
ol, ul {
list-style: none;
}
/* tables still need 'cellspacing="0"' in the markup */
table {
border-collapse: separate;
border-spacing: 0;
}
caption, th, td {
text-align: left;
font-weight: normal;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: "";
}
blockquote, q {
quotes: "" "";
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 63 KiB

View File

@ -1,45 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Jasmine BDD</title>
<link rel="stylesheet" type="text/css" href="css/reset.css" />
<link rel="stylesheet" type="text/css" href="css/master.css" />
<script type="text/javascript" src="../../../frameworks/prototype.js"></script>
<script type="text/javascript" src="javascripts/TwitSearch.js"></script>
<script type="text/javascript" src="javascripts/TwitterApi.js"></script>
<script type="text/javascript" src="javascripts/Tweet.js"></script>
</head>
<body>
<div id="wrap">
<div id="twit_search">
<form action="index.html#" method="get">
<input type="text" name="query" id="query" />
<input type="submit" value="Search Twitter" />
</form>
</div>
<ul id="results"></ul>
<script type="text/javascript">
document.observe('dom:loaded', function(){
$$("#twit_search form").first().observe("submit", function(event) {
event.preventDefault();
var search_query = $("query").value
new TwitterApi().search(
search_query, {
onSuccess: TwitSearch.displayResults,
onFailure: TwitSearch.searchFailure,
onComplete: TwitSearch.cleanup,
onFailWhale: TwitSearch.failWhale
}
);
});
});
</script>
</div>
</body>
</html>

View File

@ -1,6 +0,0 @@
function Tweet(tweet){
this.postedAt = tweet.created_at;
this.text = tweet.text;
this.imageUrl = tweet.profile_image_url;
this.user = tweet.from_user;
}

View File

@ -1,32 +0,0 @@
var TwitSearch = function(){
return {
displayResults: function(tweets){
var update_str = "";
tweets.each(function(tweet) {
update_str += "<li><img src='" + tweet.imageUrl + "' alt='" + tweet.user + " profile image' />" +
"<p>" + tweet.text + "</p>" +
"<p class='user'>" + tweet.user + "</p>" +
"<p class='timestamp'>" + tweet.postedAt + "</p>";
});
$("results").update(update_str);
},
searchFailure: function(response){
$("results").update("<h2>Oops. Something went wrong.</h2>");
},
cleanup: function(){},
rateLimitReached: function(){
console.log("rate limited");
},
failWhale: function(){
$("results").update("<img src='images/fail-whale.png' />");
}
}
}();

View File

@ -1,24 +0,0 @@
function TwitterApi () {
this.baseUrl = "http://search.twitter.com/search.json"
}
TwitterApi.prototype.search = function(query, callbacks) {
this.currentRequest = new Ajax.Request(this.baseUrl, {
method: 'get',
parameters: {
q: query
},
onSuccess: function(response){
var tweets = [];
response.responseJSON.results.each(function(result){
tweets.push(new Tweet(result));
});
callbacks.onSuccess(tweets);
},
onFailure: callbacks.onFailure,
onComplete: callbacks.onComplete,
on503: callbacks.onFailWhale
});
};

View File

@ -1,32 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Jasmine Test Runner</title>
<link rel="stylesheet" type="text/css" href="javascripts/jasmine-0.11.1/jasmine.css" />
<script type="text/javascript" src="javascripts/jasmine-0.11.1/jasmine.js"></script>
<script type="text/javascript" src="javascripts/jasmine-0.11.1/jasmine-html.js"></script>
<!-- include source files here... -->
<script type="text/javascript" src="../../../frameworks/prototype.js"></script>
<script type="text/javascript" src="../public/javascripts/Tweet.js"></script>
<script type="text/javascript" src="../public/javascripts/TwitSearch.js"></script>
<script type="text/javascript" src="../public/javascripts/TwitterApi.js"></script>
<!-- include spec files here... -->
<script type="text/javascript" src="../../../lib/mock-ajax.js"></script>
<script type="text/javascript" src="../../../lib/spec-helper.js"></script>
<script type="text/javascript" src="javascripts/helpers/test_responses/search.js"></script>
<script type="text/javascript" src="javascripts/helpers/tweets.js"></script>
<script type="text/javascript" src="javascripts/TweetSpec.js"></script>
<script type="text/javascript" src="javascripts/TwitterApiSpec.js"></script>
</head>
<body>
<script type="text/javascript">
jasmine.getEnv().addReporter(new jasmine.TrivialReporter());
jasmine.getEnv().execute();
</script>
</body>
</html>

View File

@ -1,24 +0,0 @@
describe("Tweet", function(){
var tweet;
beforeEach(function(){
tweet = new Tweet(eval('(' + Tweets.noAtReply + ')'));
});
it("should create a pretty date", function(){
expect(tweet.postedAt).toEqual("Thu, 29 Jul 2010 02:18:53 +0000");
});
it("should store the users messages", function(){
expect(tweet.text).toEqual("Pres Obama on stage with the Foo fighters, jonas brothers and a whole lot of ppl..nice..");
});
it("should store the username", function(){
expect(tweet.user).toEqual("_wbrodrigues");
});
it("stores the users messages", function(){
expect(tweet.imageUrl).toEqual("http://a2.twimg.com/profile_images/1014111170/06212010155_normal.jpg");
});
});

View File

@ -1,89 +0,0 @@
describe("TwitterApi#search", function(){
var twitter, request;
var onSuccess, onFailure, onComplete, onFailWhale;
beforeEach(function(){
jasmine.Ajax.useMock();
onSuccess = jasmine.createSpy('onSuccess');
onFailure = jasmine.createSpy('onFailure');
onComplete = jasmine.createSpy('onComplete');
onFailWhale = jasmine.createSpy('onFailWhale');
twitter = new TwitterApi();
twitter.search('basketball', {
onSuccess: onSuccess,
onFailure: onFailure,
onComplete: onComplete,
onFailWhale: onFailWhale
});
request = mostRecentAjaxRequest();
});
it("calls Twitter with the correct url", function(){
expect(request.url).toEqual("http://search.twitter.com/search.json?q=basketball")
});
describe("on success", function(){
beforeEach(function(){
request.response(TestResponses.search.success);
});
it("should call the provided success callback", function() {
expect(onSuccess).toHaveBeenCalled();
});
it("calls onComplete", function(){
expect(onComplete).toHaveBeenCalled();
});
it("does not call onFailure", function(){
expect(onFailure).not.toHaveBeenCalled();
});
it("call convert the server response to Tweet objects", function(){
var results = onSuccess.mostRecentCall.args[0];
expect(results.length).toEqual(15);
expect(results[0]).toEqual(jasmine.any(Tweet));
});
});
describe('on failure', function(){
beforeEach(function(){
request.response(TestResponses.search.failure);
});
it("calls onFailure", function() {
expect(onFailure).toHaveBeenCalled();
});
it("call onComplete", function(){
expect(onComplete).toHaveBeenCalled();
});
it("does not call onSuccess", function(){
expect(onSuccess).not.toHaveBeenCalled();
});
});
describe("on fail whale", function(){
beforeEach(function(){
request.response(TestResponses.search.failWhale);
});
it("calls onFailWhale", function(){
expect(onFailWhale).toHaveBeenCalled();
});
it("does not call onSuccess", function(){
expect(onSuccess).not.toHaveBeenCalled();
});
it("calls onComplete", function(){
expect(onComplete).toHaveBeenCalled();
});
});
});

File diff suppressed because one or more lines are too long

View File

@ -1,3 +0,0 @@
var Tweets = {
noAtReply: '{"profile_image_url":"http://a2.twimg.com/profile_images/1014111170/06212010155_normal.jpg","created_at":"Thu, 29 Jul 2010 02:18:53 +0000","from_user":"_wbrodrigues","metadata":{"result_type":"recent"},"to_user_id":null,"text":"Pres Obama on stage with the Foo fighters, jonas brothers and a whole lot of ppl..nice..","id":19789985947,"from_user_id":139732299,"geo":null,"iso_language_code":"en","source":"&lt;a href=&quot;http://www.tweetdeck.com&quot; rel=&quot;nofollow&quot;&gt;TweetDeck&lt;/a&gt;"}'
}

View File

@ -1,182 +0,0 @@
jasmine.TrivialReporter = function(doc) {
this.document = doc || document;
this.suiteDivs = {};
this.logRunningSpecs = false;
};
jasmine.TrivialReporter.prototype.createDom = function(type, attrs, childrenVarArgs) {
var el = document.createElement(type);
for (var i = 2; i < arguments.length; i++) {
var child = arguments[i];
if (typeof child === 'string') {
el.appendChild(document.createTextNode(child));
} else {
if (child) { el.appendChild(child); }
}
}
for (var attr in attrs) {
if (attr == "className") {
el[attr] = attrs[attr];
} else {
el.setAttribute(attr, attrs[attr]);
}
}
return el;
};
jasmine.TrivialReporter.prototype.reportRunnerStarting = function(runner) {
var showPassed, showSkipped;
this.outerDiv = this.createDom('div', { className: 'jasmine_reporter' },
this.createDom('div', { className: 'banner' },
this.createDom('div', { className: 'logo' },
"Jasmine",
this.createDom('span', { className: 'version' }, runner.env.versionString())),
this.createDom('div', { className: 'options' },
"Show ",
showPassed = this.createDom('input', { id: "__jasmine_TrivialReporter_showPassed__", type: 'checkbox' }),
this.createDom('label', { "for": "__jasmine_TrivialReporter_showPassed__" }, " passed "),
showSkipped = this.createDom('input', { id: "__jasmine_TrivialReporter_showSkipped__", type: 'checkbox' }),
this.createDom('label', { "for": "__jasmine_TrivialReporter_showSkipped__" }, " skipped")
)
),
this.runnerDiv = this.createDom('div', { className: 'runner running' },
this.createDom('a', { className: 'run_spec', href: '?' }, "run all"),
this.runnerMessageSpan = this.createDom('span', {}, "Running..."),
this.finishedAtSpan = this.createDom('span', { className: 'finished-at' }, ""))
);
this.document.body.appendChild(this.outerDiv);
var suites = runner.suites();
for (var i = 0; i < suites.length; i++) {
var suite = suites[i];
var suiteDiv = this.createDom('div', { className: 'suite' },
this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, "run"),
this.createDom('a', { className: 'description', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, suite.description));
this.suiteDivs[suite.id] = suiteDiv;
var parentDiv = this.outerDiv;
if (suite.parentSuite) {
parentDiv = this.suiteDivs[suite.parentSuite.id];
}
parentDiv.appendChild(suiteDiv);
}
this.startedAt = new Date();
var self = this;
showPassed.onchange = function(evt) {
if (evt.target.checked) {
self.outerDiv.className += ' show-passed';
} else {
self.outerDiv.className = self.outerDiv.className.replace(/ show-passed/, '');
}
};
showSkipped.onchange = function(evt) {
if (evt.target.checked) {
self.outerDiv.className += ' show-skipped';
} else {
self.outerDiv.className = self.outerDiv.className.replace(/ show-skipped/, '');
}
};
};
jasmine.TrivialReporter.prototype.reportRunnerResults = function(runner) {
var results = runner.results();
var className = (results.failedCount > 0) ? "runner failed" : "runner passed";
this.runnerDiv.setAttribute("class", className);
//do it twice for IE
this.runnerDiv.setAttribute("className", className);
var specs = runner.specs();
var specCount = 0;
for (var i = 0; i < specs.length; i++) {
if (this.specFilter(specs[i])) {
specCount++;
}
}
var message = "" + specCount + " spec" + (specCount == 1 ? "" : "s" ) + ", " + results.failedCount + " failure" + ((results.failedCount == 1) ? "" : "s");
message += " in " + ((new Date().getTime() - this.startedAt.getTime()) / 1000) + "s";
this.runnerMessageSpan.replaceChild(this.createDom('a', { className: 'description', href: '?'}, message), this.runnerMessageSpan.firstChild);
this.finishedAtSpan.appendChild(document.createTextNode("Finished at " + new Date().toString()));
};
jasmine.TrivialReporter.prototype.reportSuiteResults = function(suite) {
var results = suite.results();
var status = results.passed() ? 'passed' : 'failed';
if (results.totalCount == 0) { // todo: change this to check results.skipped
status = 'skipped';
}
this.suiteDivs[suite.id].className += " " + status;
};
jasmine.TrivialReporter.prototype.reportSpecStarting = function(spec) {
if (this.logRunningSpecs) {
this.log('>> Jasmine Running ' + spec.suite.description + ' ' + spec.description + '...');
}
};
jasmine.TrivialReporter.prototype.reportSpecResults = function(spec) {
var results = spec.results();
var status = results.passed() ? 'passed' : 'failed';
if (results.skipped) {
status = 'skipped';
}
var specDiv = this.createDom('div', { className: 'spec ' + status },
this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(spec.getFullName()) }, "run"),
this.createDom('a', {
className: 'description',
href: '?spec=' + encodeURIComponent(spec.getFullName()),
title: spec.getFullName()
}, spec.description));
var resultItems = results.getItems();
var messagesDiv = this.createDom('div', { className: 'messages' });
for (var i = 0; i < resultItems.length; i++) {
var result = resultItems[i];
if (result.type == 'log') {
messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage log'}, result.toString()));
} else if (result.type == 'expect' && result.passed && !result.passed()) {
messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage fail'}, result.message));
if (result.trace.stack) {
messagesDiv.appendChild(this.createDom('div', {className: 'stackTrace'}, result.trace.stack));
}
}
}
if (messagesDiv.childNodes.length > 0) {
specDiv.appendChild(messagesDiv);
}
this.suiteDivs[spec.suite.id].appendChild(specDiv);
};
jasmine.TrivialReporter.prototype.log = function() {
var console = jasmine.getGlobal().console;
if (console && console.log) console.log.apply(console, arguments);
};
jasmine.TrivialReporter.prototype.getLocation = function() {
return this.document.location;
};
jasmine.TrivialReporter.prototype.specFilter = function(spec) {
var paramMap = {};
var params = this.getLocation().search.substring(1).split('&');
for (var i = 0; i < params.length; i++) {
var p = params[i].split('=');
paramMap[decodeURIComponent(p[0])] = decodeURIComponent(p[1]);
}
if (!paramMap["spec"]) return true;
return spec.getFullName().indexOf(paramMap["spec"]) == 0;
};

View File

@ -1,166 +0,0 @@
body {
font-family: "Helvetica Neue Light", "Lucida Grande", "Calibri", "Arial", sans-serif;
}
.jasmine_reporter a:visited, .jasmine_reporter a {
color: #303;
}
.jasmine_reporter a:hover, .jasmine_reporter a:active {
color: blue;
}
.run_spec {
float:right;
padding-right: 5px;
font-size: .8em;
text-decoration: none;
}
.jasmine_reporter {
margin: 0 5px;
}
.banner {
color: #303;
background-color: #fef;
padding: 5px;
}
.logo {
float: left;
font-size: 1.1em;
padding-left: 5px;
}
.logo .version {
font-size: .6em;
padding-left: 1em;
}
.runner.running {
background-color: yellow;
}
.options {
text-align: right;
font-size: .8em;
}
.suite {
border: 1px outset gray;
margin: 5px 0;
padding-left: 1em;
}
.suite .suite {
margin: 5px;
}
.suite.passed {
background-color: #dfd;
}
.suite.failed {
background-color: #fdd;
}
.spec {
margin: 5px;
padding-left: 1em;
clear: both;
}
.spec.failed, .spec.passed, .spec.skipped {
padding-bottom: 5px;
border: 1px solid gray;
}
.spec.failed {
background-color: #fbb;
border-color: red;
}
.spec.passed {
background-color: #bfb;
border-color: green;
}
.spec.skipped {
background-color: #bbb;
}
.messages {
border-left: 1px dashed gray;
padding-left: 1em;
padding-right: 1em;
}
.passed {
background-color: #cfc;
display: none;
}
.failed {
background-color: #fbb;
}
.skipped {
color: #777;
background-color: #eee;
display: none;
}
/*.resultMessage {*/
/*white-space: pre;*/
/*}*/
.resultMessage span.result {
display: block;
line-height: 2em;
color: black;
}
.resultMessage .mismatch {
color: black;
}
.stackTrace {
white-space: pre;
font-size: .8em;
margin-left: 10px;
max-height: 5em;
overflow: auto;
border: 1px inset red;
padding: 1em;
background: #eef;
}
.finished-at {
padding-left: 1em;
font-size: .6em;
}
.show-passed .passed,
.show-skipped .skipped {
display: block;
}
#jasmine_content {
position:fixed;
right: 100%;
}
.runner {
border: 1px solid gray;
display: block;
margin: 5px 0;
padding: 2px 0 2px 10px;
}

File diff suppressed because it is too large Load Diff

View File

@ -1,78 +0,0 @@
# src_files
#
# Return an array of filepaths relative to src_dir to include before jasmine specs.
# Default: []
#
# EXAMPLE:
#
# src_files:
# - lib/source1.js
# - lib/source2.js
# - dist/**/*.js
#
src_files:
- frameworks/prototype.js
- examples/prototype/public/javascripts/**/*.js
# stylesheets
#
# Return an array of stylesheet filepaths relative to src_dir to include before jasmine specs.
# Default: []
#
# EXAMPLE:
#
# stylesheets:
# - css/style.css
# - stylesheets/*.css
#
stylesheets:
# helpers
#
# Return an array of filepaths relative to spec_dir to include before jasmine specs.
# Default: ["helpers/**/*.js"]
#
# EXAMPLE:
#
# helpers:
# - helpers/**/*.js
#
helpers:
- lib/spec-helper.js
- examples/prototype/spec/javascripts/helpers/**/*.js
# spec_files
#
# Return an array of filepaths relative to spec_dir to include.
# Default: ["**/*[sS]pec.js"]
#
# EXAMPLE:
#
# spec_files:
# - **/*[sS]pec.js
#
spec_files:
- lib/mock-ajax.js
- examples/prototype/spec/javascripts/*.js
# src_dir
#
# Source directory path. Your src_files must be returned relative to this path. Will use root if left blank.
# Default: project root
#
# EXAMPLE:
#
# src_dir: public
#
src_dir: ../..
# spec_dir
#
# Spec directory path. Your spec_files must be returned relative to this path.
# Default: spec/javascripts
#
# EXAMPLE:
#
# spec_dir: spec/javascripts
#
spec_dir: ../..

View File

@ -1,21 +0,0 @@
$:.unshift(ENV['JASMINE_GEM_PATH']) if ENV['JASMINE_GEM_PATH'] # for gem testing purposes
require 'rubygems'
require 'jasmine'
jasmine_config_overrides = File.expand_path(File.join(File.dirname(__FILE__), 'jasmine_config.rb'))
require jasmine_config_overrides if File.exists?(jasmine_config_overrides)
jasmine_config = Jasmine::Config.new
spec_builder = Jasmine::SpecBuilder.new(jasmine_config)
should_stop = false
Spec::Runner.configure do |config|
config.after(:suite) do
spec_builder.stop if should_stop
end
end
spec_builder.start
should_stop = true
spec_builder.declare_suites

4874
frameworks/prototype.js vendored

File diff suppressed because it is too large Load Diff

View File

@ -2,7 +2,7 @@
Jasmine-Ajax : a set of helpers for testing AJAX requests under the Jasmine Jasmine-Ajax : a set of helpers for testing AJAX requests under the Jasmine
BDD framework for JavaScript. BDD framework for JavaScript.
Supports both Prototype.js and jQuery. Supports both jQuery.
http://github.com/pivotal/jasmine-ajax http://github.com/pivotal/jasmine-ajax
@ -155,10 +155,8 @@ jasmine.Ajax = {
installMock: function() { installMock: function() {
if (typeof jQuery != 'undefined') { if (typeof jQuery != 'undefined') {
jasmine.Ajax.installJquery(); jasmine.Ajax.installJquery();
} else if (typeof Prototype != 'undefined') {
jasmine.Ajax.installPrototype();
} else { } else {
throw new Error("jasmine.Ajax currently only supports jQuery and Prototype"); throw new Error("jasmine.Ajax currently only supports jQuery");
} }
jasmine.Ajax.installed = true; jasmine.Ajax.installed = true;
}, },
@ -170,19 +168,10 @@ jasmine.Ajax = {
}, },
installPrototype: function() {
jasmine.Ajax.mode = 'Prototype';
jasmine.Ajax.real = Ajax.getTransport;
Ajax.getTransport = jasmine.Ajax.prototypeMock;
},
uninstallMock: function() { uninstallMock: function() {
jasmine.Ajax.assertInstalled(); jasmine.Ajax.assertInstalled();
if (jasmine.Ajax.mode == 'jQuery') { if (jasmine.Ajax.mode == 'jQuery') {
jQuery.ajaxSettings.xhr = jasmine.Ajax.real; jQuery.ajaxSettings.xhr = jasmine.Ajax.real;
} else if (jasmine.Ajax.mode == 'Prototype') {
Ajax.getTransport = jasmine.Ajax.real;
} }
jasmine.Ajax.reset(); jasmine.Ajax.reset();
}, },
@ -199,24 +188,6 @@ jasmine.Ajax = {
return newXhr; return newXhr;
}, },
prototypeMock: function() {
return new FakeXMLHttpRequest();
},
installed: false, installed: false,
mode: null mode: null
}; };
// Jasmine-Ajax Glue code for Prototype.js
if (typeof Prototype != 'undefined' && Ajax && Ajax.Request) {
Ajax.Request.prototype.originalRequest = Ajax.Request.prototype.request;
Ajax.Request.prototype.request = function(url) {
this.originalRequest(url);
ajaxRequests.push(this);
};
Ajax.Request.prototype.response = function(responseOptions) {
return this.transport.response(responseOptions);
};
}

View File

@ -2,10 +2,8 @@ describe("Jasmine Mock Ajax (for jQuery)", function() {
var request, anotherRequest, response; var request, anotherRequest, response;
var success, error, complete; var success, error, complete;
var sharedContext = {}; var sharedContext = {};
var prototype = Prototype;
beforeEach(function() { beforeEach(function() {
Prototype = undefined;
jasmine.Ajax.useMock(); jasmine.Ajax.useMock();
success = jasmine.createSpy("onSuccess"); success = jasmine.createSpy("onSuccess");
@ -13,10 +11,6 @@ describe("Jasmine Mock Ajax (for jQuery)", function() {
complete = jasmine.createSpy("onComplete"); complete = jasmine.createSpy("onComplete");
}); });
afterEach(function() {
Prototype = prototype;
});
describe("when making a request", function () { describe("when making a request", function () {
beforeEach(function() { beforeEach(function() {
jQuery.ajax({ jQuery.ajax({

View File

@ -1,287 +0,0 @@
describe("Jasmine Mock Ajax (for Prototype.js)", function() {
var request, anotherRequest, onSuccess, onFailure, onComplete;
var sharedContext = {};
var jquery = jQuery;
beforeEach(function() {
jQuery = undefined;
jasmine.Ajax.useMock();
onSuccess = jasmine.createSpy("onSuccess");
onFailure = jasmine.createSpy("onFailure");
onComplete = jasmine.createSpy("onComplete");
});
afterEach(function() {
jQuery = jquery;
});
describe("when making a request", function () {
beforeEach(function() {
request = new Ajax.Request("example.com/someApi", {
onSuccess: onSuccess,
onFailure: onFailure,
onComplete: onComplete
});
});
it("should store URL and transport", function() {
expect(request.url).toEqual("example.com/someApi");
expect(request.transport).toBeTruthy();
});
it("should queue the request", function() {
expect(ajaxRequests.length).toEqual(1);
});
it("should allow access to the queued request", function() {
expect(ajaxRequests[0]).toEqual(request);
});
describe("and then another request", function () {
beforeEach(function() {
anotherRequest = new Ajax.Request("example.com/someApi", {
onSuccess: onSuccess,
onFailure: onFailure,
onComplete: onComplete
});
});
it("should queue the next request", function() {
expect(ajaxRequests.length).toEqual(2);
});
it("should allow access to the other queued request", function() {
expect(ajaxRequests[1]).toEqual(anotherRequest);
});
});
describe("mostRecentAjaxRequest", function () {
describe("when there is one request queued", function () {
it("should return the request", function() {
expect(mostRecentAjaxRequest()).toEqual(request);
});
});
describe("when there is more than one request", function () {
beforeEach(function() {
anotherRequest = new Ajax.Request("balthazarurl", {
onSuccess: onSuccess,
onFailure: onFailure,
onComplete: onComplete
});
});
it("should return the most recent request", function() {
expect(mostRecentAjaxRequest()).toEqual(anotherRequest);
});
});
describe("when there are no requests", function () {
beforeEach(function() {
clearAjaxRequests();
});
it("should return null", function() {
expect(mostRecentAjaxRequest()).toEqual(null);
});
});
});
describe("clearAjaxRequests()", function () {
beforeEach(function() {
clearAjaxRequests();
});
it("should remove all requests", function() {
expect(ajaxRequests.length).toEqual(0);
expect(mostRecentAjaxRequest()).toEqual(null);
});
});
});
describe("when simulating a response with request.response", function () {
beforeEach(function() {
request = new Ajax.Request("idontcare", {
method: 'get',
onSuccess: onSuccess,
onFailure: onFailure,
onComplete: onComplete
});
});
describe("and the response is Success", function () {
beforeEach(function() {
var response = {status: 200, contentType: "text/html", responseText: "OK!"};
request.response(response);
sharedContext.responseCallback = onSuccess;
sharedContext.status = response.status;
sharedContext.contentType = response.contentType;
sharedContext.responseText = response.responseText;
});
it("should call the success handler", function() {
expect(onSuccess).toHaveBeenCalled();
});
it("should not call the failure handler", function() {
expect(onFailure).not.toHaveBeenCalled();
});
it("should call the complete handler", function() {
expect(onComplete).toHaveBeenCalled();
});
sharedAjaxResponseBehavior(sharedContext);
});
describe("and the response is Failure", function () {
beforeEach(function() {
var response = {status: 500, contentType: "text/html", responseText: "(._){"};
request.response(response);
sharedContext.responseCallback = onFailure;
sharedContext.status = response.status;
sharedContext.contentType = response.contentType;
sharedContext.responseText = response.responseText;
});
it("should not call the success handler", function() {
expect(onSuccess).not.toHaveBeenCalled();
});
it("should call the failure handler", function() {
expect(onFailure).toHaveBeenCalled();
});
it("should call the complete handler", function() {
expect(onComplete).toHaveBeenCalled();
});
sharedAjaxResponseBehavior(sharedContext);
});
describe("and the response is Success, but with JSON", function () {
var response;
beforeEach(function() {
var responseObject = {status: 200, contentType: "application/json", responseText: "{'foo':'bar'}"};
request.response(responseObject);
sharedContext.responseCallback = onSuccess;
sharedContext.status = responseObject.status;
sharedContext.contentType = responseObject.contentType;
sharedContext.responseText = responseObject.responseText;
response = onSuccess.mostRecentCall.args[0];
});
it("should call the success handler", function() {
expect(onSuccess).toHaveBeenCalled();
});
it("should not call the failure handler", function() {
expect(onFailure).not.toHaveBeenCalled();
});
it("should call the complete handler", function() {
expect(onComplete).toHaveBeenCalled();
});
it("should return a JavaScript object", function() {
window.response = response;
expect(response.responseJSON).toEqual({foo: "bar"});
});
sharedAjaxResponseBehavior(sharedContext);
});
describe("the content type defaults to application/json", function () {
beforeEach(function() {
var response = {status: 200, responseText: "OK!"};
request.response(response);
sharedContext.responseCallback = onSuccess;
sharedContext.status = response.status;
sharedContext.contentType = "application/json";
sharedContext.responseText = response.responseText;
});
it("should call the success handler", function() {
expect(onSuccess).toHaveBeenCalled();
});
it("should not call the failure handler", function() {
expect(onFailure).not.toHaveBeenCalled();
});
it("should call the complete handler", function() {
expect(onComplete).toHaveBeenCalled();
});
sharedAjaxResponseBehavior(sharedContext);
});
describe("and the status/response code is null", function () {
var on0;
beforeEach(function() {
on0 = jasmine.createSpy('on0');
request = new Ajax.Request("idontcare", {
method: 'get',
on0: on0,
onSuccess: onSuccess,
onFailure: onFailure,
onComplete: onComplete
});
var response = {status: null, responseText: "whoops!"};
request.response(response);
sharedContext.responseCallback = on0;
sharedContext.status = 0;
sharedContext.contentType = 'application/json';
sharedContext.responseText = response.responseText;
});
it("should not call the success handler", function() {
expect(onSuccess).not.toHaveBeenCalled();
});
it("should not call the failure handler", function() {
expect(onFailure).not.toHaveBeenCalled();
});
it("should call the on0 handler", function() {
expect(on0).toHaveBeenCalled();
});
it("should call the complete handler", function() {
expect(onComplete).toHaveBeenCalled();
});
sharedAjaxResponseBehavior(sharedContext);
});
});
});
function sharedAjaxResponseBehavior(context) {
describe("the response", function () {
var response;
beforeEach(function() {
response = context.responseCallback.mostRecentCall.args[0];
});
it("should have the expected status code", function() {
expect(response.status).toEqual(context.status);
});
it("should have the expected content type", function() {
expect(response.getHeader('Content-type')).toEqual(context.contentType);
});
it("should have the expected response text", function() {
expect(response.responseText).toEqual(context.responseText);
});
});
}

View File

@ -37,64 +37,30 @@ describe("jasmine.Ajax", function() {
describe("when using jQuery", function() { describe("when using jQuery", function() {
it("installs the mock", function() { it("installs the mock", function() {
withoutPrototype(function() {
jasmine.Ajax.installMock(); jasmine.Ajax.installMock();
expect(jQuery.ajaxSettings.xhr).toBe(jasmine.Ajax.jQueryMock); expect(jQuery.ajaxSettings.xhr).toBe(jasmine.Ajax.jQueryMock);
});
}); });
it("saves a reference to jQuery.ajaxSettings.xhr", function() { it("saves a reference to jQuery.ajaxSettings.xhr", function() {
withoutPrototype(function() {
var jqueryAjax = jQuery.ajaxSettings.xhr; var jqueryAjax = jQuery.ajaxSettings.xhr;
jasmine.Ajax.installMock(); jasmine.Ajax.installMock();
expect(jasmine.Ajax.real).toBe(jqueryAjax); expect(jasmine.Ajax.real).toBe(jqueryAjax);
});
}); });
it("sets mode to 'jQuery'", function() { it("sets mode to 'jQuery'", function() {
withoutPrototype(function() {
jasmine.Ajax.installMock(); jasmine.Ajax.installMock();
expect(jasmine.Ajax.mode).toEqual("jQuery"); expect(jasmine.Ajax.mode).toEqual("jQuery");
});
});
});
describe("when using Prototype", function() {
it("installs the mock", function() {
withoutJquery(function() {
jasmine.Ajax.installMock();
expect(Ajax.getTransport).toBe(jasmine.Ajax.prototypeMock);
});
});
it("stores a reference to Ajax.getTransport", function() {
withoutJquery(function(){
var prototypeAjax = Ajax.getTransport;
jasmine.Ajax.installMock();
expect(jasmine.Ajax.real).toBe(prototypeAjax);
});
});
it("sets mode to 'Prototype'", function() {
withoutJquery(function() {
jasmine.Ajax.installMock();
expect(jasmine.Ajax.mode).toEqual("Prototype");
});
}); });
}); });
describe("when using any other library", function() { describe("when using any other library", function() {
it("raises an exception", function() { it("raises an exception", function() {
var jquery = jQuery; var jquery = jQuery;
var prototype = Prototype;
jQuery = undefined; jQuery = undefined;
Prototype = undefined;
expect(function(){ jasmine.Ajax.installMock(); }).toThrow("jasmine.Ajax currently only supports jQuery and Prototype"); expect(function(){ jasmine.Ajax.installMock(); }).toThrow("jasmine.Ajax currently only supports jQuery");
jQuery = jquery; jQuery = jquery;
Prototype = prototype;
}); });
}); });
@ -108,31 +74,12 @@ describe("jasmine.Ajax", function() {
describe("uninstallMock", function() { describe("uninstallMock", function() {
describe("when using jQuery", function() { describe("when using jQuery", function() {
it("returns ajax control to jQuery", function() { it("returns ajax control to jQuery", function() {
withoutPrototype(function() {
var jqueryAjax = jQuery.ajaxSettings.xhr; var jqueryAjax = jQuery.ajaxSettings.xhr;
jasmine.Ajax.installMock(); jasmine.Ajax.installMock();
jasmine.Ajax.uninstallMock(); jasmine.Ajax.uninstallMock();
expect(jQuery.ajaxSettings.xhr).toBe(jqueryAjax); expect(jQuery.ajaxSettings.xhr).toBe(jqueryAjax);
});
});
});
describe("when using Prototype", function() {
it("returns Ajax control to Ajax.getTransport", function() {
withoutJquery(function() {
var prototypeAjax = Ajax.getTransport;
jasmine.Ajax.installMock();
jasmine.Ajax.uninstallMock();
expect(Ajax.getTransport).toBe(prototypeAjax);
});
// so uninstallMock doesn't throw error when spec.after runs
jasmine.Ajax.installMock();
}); });
}); });
@ -184,10 +131,3 @@ function withoutJquery(spec) {
spec.apply(this); spec.apply(this);
jQuery = jqueryRef; jQuery = jqueryRef;
} }
function withoutPrototype(spec) {
var prototypeRef = Prototype;
Prototype = undefined;
spec.apply(this);
Prototype = prototypeRef;
}

View File

@ -1,7 +1,6 @@
src_dir: . src_dir: .
src_files: src_files:
- frameworks/prototype.js
- frameworks/jquery.js - frameworks/jquery.js
- lib/mock-ajax.js - lib/mock-ajax.js