jasmine-ajax 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +2 -0
- data/.pairs +6 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +35 -0
- data/MIT.LICENSE +20 -0
- data/README.markdown +168 -0
- data/Rakefile +3 -0
- data/examples/jquery/Rakefile +2 -0
- data/examples/jquery/public/css/master.css +59 -0
- data/examples/jquery/public/css/reset.css +47 -0
- data/examples/jquery/public/images/fail-whale.png +0 -0
- data/examples/jquery/public/index.html +60 -0
- data/examples/jquery/public/javascripts/Tweet.js +6 -0
- data/examples/jquery/public/javascripts/TwitSearch.js +32 -0
- data/examples/jquery/public/javascripts/TwitterApi.js +31 -0
- data/examples/jquery/spec/SpecRunner.html +32 -0
- data/examples/jquery/spec/javascripts/TweetSpec.js +24 -0
- data/examples/jquery/spec/javascripts/TwitterApiSpec.js +88 -0
- data/examples/jquery/spec/javascripts/helpers/test_responses/search.js +16 -0
- data/examples/jquery/spec/javascripts/helpers/tweets.js +3 -0
- data/examples/jquery/spec/javascripts/jasmine-0.11.1/jasmine-html.js +182 -0
- data/examples/jquery/spec/javascripts/jasmine-0.11.1/jasmine.css +166 -0
- data/examples/jquery/spec/javascripts/jasmine-0.11.1/jasmine.js +2343 -0
- data/examples/jquery/spec/javascripts/support/jasmine.yml +78 -0
- data/examples/jquery/spec/javascripts/support/jasmine_runner.rb +21 -0
- data/examples/prototype/Rakefile +2 -0
- data/examples/prototype/public/css/master.css +59 -0
- data/examples/prototype/public/css/reset.css +47 -0
- data/examples/prototype/public/images/fail-whale.png +0 -0
- data/examples/prototype/public/index.html +45 -0
- data/examples/prototype/public/javascripts/Tweet.js +6 -0
- data/examples/prototype/public/javascripts/TwitSearch.js +32 -0
- data/examples/prototype/public/javascripts/TwitterApi.js +24 -0
- data/examples/prototype/spec/SpecRunner.html +32 -0
- data/examples/prototype/spec/javascripts/TweetSpec.js +24 -0
- data/examples/prototype/spec/javascripts/TwitterApiSpec.js +89 -0
- data/examples/prototype/spec/javascripts/helpers/test_responses/search.js +16 -0
- data/examples/prototype/spec/javascripts/helpers/tweets.js +3 -0
- data/examples/prototype/spec/javascripts/jasmine-0.11.1/jasmine-html.js +182 -0
- data/examples/prototype/spec/javascripts/jasmine-0.11.1/jasmine.css +166 -0
- data/examples/prototype/spec/javascripts/jasmine-0.11.1/jasmine.js +2343 -0
- data/examples/prototype/spec/javascripts/support/jasmine.yml +78 -0
- data/examples/prototype/spec/javascripts/support/jasmine_runner.rb +21 -0
- data/frameworks/jquery.js +8176 -0
- data/frameworks/prototype.js +4874 -0
- data/lib/assets/javascripts/mock-ajax.js +207 -0
- data/lib/spec-helper.js +0 -0
- data/lib/version.rb +5 -0
- data/spec/javascripts/fake-xml-http-request-spec.js +45 -0
- data/spec/javascripts/helpers/spec-helper.js +5 -0
- data/spec/javascripts/mock-ajax-jquery-spec.js +374 -0
- data/spec/javascripts/mock-ajax-prototypejs-spec.js +287 -0
- data/spec/javascripts/mock-ajax-spec.js +193 -0
- data/spec/javascripts/support/jasmine.yml +81 -0
- data/spec/javascripts/support/jasmine_runner.rb +21 -0
- metadata +108 -0
@@ -0,0 +1,78 @@
|
|
1
|
+
# src_files
|
2
|
+
#
|
3
|
+
# Return an array of filepaths relative to src_dir to include before jasmine specs.
|
4
|
+
# Default: []
|
5
|
+
#
|
6
|
+
# EXAMPLE:
|
7
|
+
#
|
8
|
+
# src_files:
|
9
|
+
# - lib/source1.js
|
10
|
+
# - lib/source2.js
|
11
|
+
# - dist/**/*.js
|
12
|
+
#
|
13
|
+
src_files:
|
14
|
+
- frameworks/jquery.js
|
15
|
+
- examples/jquery/public/javascripts/**/*.js
|
16
|
+
|
17
|
+
# stylesheets
|
18
|
+
#
|
19
|
+
# Return an array of stylesheet filepaths relative to src_dir to include before jasmine specs.
|
20
|
+
# Default: []
|
21
|
+
#
|
22
|
+
# EXAMPLE:
|
23
|
+
#
|
24
|
+
# stylesheets:
|
25
|
+
# - css/style.css
|
26
|
+
# - stylesheets/*.css
|
27
|
+
#
|
28
|
+
stylesheets:
|
29
|
+
|
30
|
+
# helpers
|
31
|
+
#
|
32
|
+
# Return an array of filepaths relative to spec_dir to include before jasmine specs.
|
33
|
+
# Default: ["helpers/**/*.js"]
|
34
|
+
#
|
35
|
+
# EXAMPLE:
|
36
|
+
#
|
37
|
+
# helpers:
|
38
|
+
# - helpers/**/*.js
|
39
|
+
#
|
40
|
+
helpers:
|
41
|
+
- lib/spec-helper.js
|
42
|
+
- examples/jquery/spec/javascripts/helpers/**/*.js
|
43
|
+
|
44
|
+
# spec_files
|
45
|
+
#
|
46
|
+
# Return an array of filepaths relative to spec_dir to include.
|
47
|
+
# Default: ["**/*[sS]pec.js"]
|
48
|
+
#
|
49
|
+
# EXAMPLE:
|
50
|
+
#
|
51
|
+
# spec_files:
|
52
|
+
# - **/*[sS]pec.js
|
53
|
+
#
|
54
|
+
spec_files:
|
55
|
+
- lib/mock-ajax.js
|
56
|
+
- examples/jquery/spec/javascripts/*.js
|
57
|
+
|
58
|
+
# src_dir
|
59
|
+
#
|
60
|
+
# Source directory path. Your src_files must be returned relative to this path. Will use root if left blank.
|
61
|
+
# Default: project root
|
62
|
+
#
|
63
|
+
# EXAMPLE:
|
64
|
+
#
|
65
|
+
# src_dir: public
|
66
|
+
#
|
67
|
+
src_dir: ../..
|
68
|
+
|
69
|
+
# spec_dir
|
70
|
+
#
|
71
|
+
# Spec directory path. Your spec_files must be returned relative to this path.
|
72
|
+
# Default: spec/javascripts
|
73
|
+
#
|
74
|
+
# EXAMPLE:
|
75
|
+
#
|
76
|
+
# spec_dir: spec/javascripts
|
77
|
+
#
|
78
|
+
spec_dir: ../..
|
@@ -0,0 +1,21 @@
|
|
1
|
+
$:.unshift(ENV['JASMINE_GEM_PATH']) if ENV['JASMINE_GEM_PATH'] # for gem testing purposes
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'jasmine'
|
5
|
+
jasmine_config_overrides = File.expand_path(File.join(File.dirname(__FILE__), 'jasmine_config.rb'))
|
6
|
+
require jasmine_config_overrides if File.exists?(jasmine_config_overrides)
|
7
|
+
|
8
|
+
jasmine_config = Jasmine::Config.new
|
9
|
+
spec_builder = Jasmine::SpecBuilder.new(jasmine_config)
|
10
|
+
|
11
|
+
should_stop = false
|
12
|
+
|
13
|
+
Spec::Runner.configure do |config|
|
14
|
+
config.after(:suite) do
|
15
|
+
spec_builder.stop if should_stop
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
spec_builder.start
|
20
|
+
should_stop = true
|
21
|
+
spec_builder.declare_suites
|
@@ -0,0 +1,59 @@
|
|
1
|
+
body {
|
2
|
+
margin-top: 100px;
|
3
|
+
text-align: center;
|
4
|
+
}
|
5
|
+
|
6
|
+
#wrap {
|
7
|
+
width: 800px;
|
8
|
+
margin: 0 auto;
|
9
|
+
text-align: left;
|
10
|
+
}
|
11
|
+
|
12
|
+
#twit_search {
|
13
|
+
margin-bottom: 75px;
|
14
|
+
}
|
15
|
+
|
16
|
+
#twit_search form {
|
17
|
+
color: #555555;
|
18
|
+
text-align: center;
|
19
|
+
font-size: 150%;
|
20
|
+
}
|
21
|
+
|
22
|
+
#twit_search form input[type=text] {
|
23
|
+
font-size: 100%;
|
24
|
+
color: #555555;
|
25
|
+
border: 2px solid black;
|
26
|
+
-moz-border-radius: 2px;
|
27
|
+
-webkit-border-radius: 2px;
|
28
|
+
padding: 4px 6px;
|
29
|
+
}
|
30
|
+
|
31
|
+
#twit_search form input[type=submit] {
|
32
|
+
font-size: 130%;
|
33
|
+
}
|
34
|
+
|
35
|
+
#results {
|
36
|
+
margin: 0 auto;
|
37
|
+
width: 60%;
|
38
|
+
}
|
39
|
+
|
40
|
+
#results li {
|
41
|
+
margin: 38px 0;
|
42
|
+
}
|
43
|
+
|
44
|
+
#results img {
|
45
|
+
clear: both;
|
46
|
+
margin-right: 10px;
|
47
|
+
float: left;
|
48
|
+
}
|
49
|
+
|
50
|
+
#results img + p {
|
51
|
+
font-size: 130%;
|
52
|
+
color: #333333;
|
53
|
+
}
|
54
|
+
|
55
|
+
#results p.user, #results p.timestamp {
|
56
|
+
margin-top: 5px;
|
57
|
+
text-align: right;
|
58
|
+
font-style: italic;
|
59
|
+
}
|
@@ -0,0 +1,47 @@
|
|
1
|
+
/* From http://meyerweb.com/eric/thoughts/2007/05/01/reset-reloaded/ */
|
2
|
+
html, body, div, span, applet, object, iframe,
|
3
|
+
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
|
4
|
+
a, abbr, acronym, address, big, cite, code,
|
5
|
+
del, dfn, em, font, img, ins, kbd, q, s, samp,
|
6
|
+
small, strike, strong, sub, sup, tt, var,
|
7
|
+
dl, dt, dd, ol, ul, li,
|
8
|
+
fieldset, form, label, legend,
|
9
|
+
table, caption, tbody, tfoot, thead, tr, th, td {
|
10
|
+
margin: 0;
|
11
|
+
padding: 0;
|
12
|
+
border: 0;
|
13
|
+
outline: 0;
|
14
|
+
font-weight: inherit;
|
15
|
+
font-style: inherit;
|
16
|
+
font-size: 100%;
|
17
|
+
font-family: inherit;
|
18
|
+
vertical-align: baseline;
|
19
|
+
}
|
20
|
+
/* remember to define focus styles! */
|
21
|
+
:focus {
|
22
|
+
outline: 0;
|
23
|
+
}
|
24
|
+
body {
|
25
|
+
line-height: 1;
|
26
|
+
color: black;
|
27
|
+
background: white;
|
28
|
+
}
|
29
|
+
ol, ul {
|
30
|
+
list-style: none;
|
31
|
+
}
|
32
|
+
/* tables still need 'cellspacing="0"' in the markup */
|
33
|
+
table {
|
34
|
+
border-collapse: separate;
|
35
|
+
border-spacing: 0;
|
36
|
+
}
|
37
|
+
caption, th, td {
|
38
|
+
text-align: left;
|
39
|
+
font-weight: normal;
|
40
|
+
}
|
41
|
+
blockquote:before, blockquote:after,
|
42
|
+
q:before, q:after {
|
43
|
+
content: "";
|
44
|
+
}
|
45
|
+
blockquote, q {
|
46
|
+
quotes: "" "";
|
47
|
+
}
|
Binary file
|
@@ -0,0 +1,45 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
5
|
+
<head>
|
6
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
7
|
+
|
8
|
+
<title>Jasmine BDD</title>
|
9
|
+
<link rel="stylesheet" type="text/css" href="css/reset.css" />
|
10
|
+
<link rel="stylesheet" type="text/css" href="css/master.css" />
|
11
|
+
<script type="text/javascript" src="../../../frameworks/prototype.js"></script>
|
12
|
+
<script type="text/javascript" src="javascripts/TwitSearch.js"></script>
|
13
|
+
<script type="text/javascript" src="javascripts/TwitterApi.js"></script>
|
14
|
+
<script type="text/javascript" src="javascripts/Tweet.js"></script>
|
15
|
+
</head>
|
16
|
+
|
17
|
+
<body>
|
18
|
+
<div id="wrap">
|
19
|
+
<div id="twit_search">
|
20
|
+
<form action="index.html#" method="get">
|
21
|
+
<input type="text" name="query" id="query" />
|
22
|
+
<input type="submit" value="Search Twitter" />
|
23
|
+
</form>
|
24
|
+
</div>
|
25
|
+
<ul id="results"></ul>
|
26
|
+
<script type="text/javascript">
|
27
|
+
|
28
|
+
document.observe('dom:loaded', function(){
|
29
|
+
$$("#twit_search form").first().observe("submit", function(event) {
|
30
|
+
event.preventDefault();
|
31
|
+
var search_query = $("query").value
|
32
|
+
new TwitterApi().search(
|
33
|
+
search_query, {
|
34
|
+
onSuccess: TwitSearch.displayResults,
|
35
|
+
onFailure: TwitSearch.searchFailure,
|
36
|
+
onComplete: TwitSearch.cleanup,
|
37
|
+
onFailWhale: TwitSearch.failWhale
|
38
|
+
}
|
39
|
+
);
|
40
|
+
});
|
41
|
+
});
|
42
|
+
</script>
|
43
|
+
</div>
|
44
|
+
</body>
|
45
|
+
</html>
|
@@ -0,0 +1,32 @@
|
|
1
|
+
var TwitSearch = function(){
|
2
|
+
|
3
|
+
return {
|
4
|
+
displayResults: function(tweets){
|
5
|
+
var update_str = "";
|
6
|
+
|
7
|
+
tweets.each(function(tweet) {
|
8
|
+
update_str += "<li><img src='" + tweet.imageUrl + "' alt='" + tweet.user + " profile image' />" +
|
9
|
+
"<p>" + tweet.text + "</p>" +
|
10
|
+
"<p class='user'>" + tweet.user + "</p>" +
|
11
|
+
"<p class='timestamp'>" + tweet.postedAt + "</p>";
|
12
|
+
|
13
|
+
});
|
14
|
+
|
15
|
+
$("results").update(update_str);
|
16
|
+
},
|
17
|
+
|
18
|
+
searchFailure: function(response){
|
19
|
+
$("results").update("<h2>Oops. Something went wrong.</h2>");
|
20
|
+
},
|
21
|
+
|
22
|
+
cleanup: function(){},
|
23
|
+
|
24
|
+
rateLimitReached: function(){
|
25
|
+
console.log("rate limited");
|
26
|
+
},
|
27
|
+
|
28
|
+
failWhale: function(){
|
29
|
+
$("results").update("<img src='images/fail-whale.png' />");
|
30
|
+
}
|
31
|
+
}
|
32
|
+
}();
|
@@ -0,0 +1,24 @@
|
|
1
|
+
function TwitterApi () {
|
2
|
+
this.baseUrl = "http://search.twitter.com/search.json"
|
3
|
+
}
|
4
|
+
|
5
|
+
TwitterApi.prototype.search = function(query, callbacks) {
|
6
|
+
this.currentRequest = new Ajax.Request(this.baseUrl, {
|
7
|
+
method: 'get',
|
8
|
+
parameters: {
|
9
|
+
q: query
|
10
|
+
},
|
11
|
+
|
12
|
+
onSuccess: function(response){
|
13
|
+
var tweets = [];
|
14
|
+
response.responseJSON.results.each(function(result){
|
15
|
+
tweets.push(new Tweet(result));
|
16
|
+
});
|
17
|
+
|
18
|
+
callbacks.onSuccess(tweets);
|
19
|
+
},
|
20
|
+
onFailure: callbacks.onFailure,
|
21
|
+
onComplete: callbacks.onComplete,
|
22
|
+
on503: callbacks.onFailWhale
|
23
|
+
});
|
24
|
+
};
|
@@ -0,0 +1,32 @@
|
|
1
|
+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/html4/loose.dtd">
|
3
|
+
<html>
|
4
|
+
<head>
|
5
|
+
<title>Jasmine Test Runner</title>
|
6
|
+
<link rel="stylesheet" type="text/css" href="javascripts/jasmine-0.11.1/jasmine.css" />
|
7
|
+
<script type="text/javascript" src="javascripts/jasmine-0.11.1/jasmine.js"></script>
|
8
|
+
<script type="text/javascript" src="javascripts/jasmine-0.11.1/jasmine-html.js"></script>
|
9
|
+
|
10
|
+
<!-- include source files here... -->
|
11
|
+
<script type="text/javascript" src="../../../frameworks/prototype.js"></script>
|
12
|
+
<script type="text/javascript" src="../public/javascripts/Tweet.js"></script>
|
13
|
+
<script type="text/javascript" src="../public/javascripts/TwitSearch.js"></script>
|
14
|
+
<script type="text/javascript" src="../public/javascripts/TwitterApi.js"></script>
|
15
|
+
|
16
|
+
<!-- include spec files here... -->
|
17
|
+
<script type="text/javascript" src="../../../lib/mock-ajax.js"></script>
|
18
|
+
<script type="text/javascript" src="../../../lib/spec-helper.js"></script>
|
19
|
+
<script type="text/javascript" src="javascripts/helpers/test_responses/search.js"></script>
|
20
|
+
<script type="text/javascript" src="javascripts/helpers/tweets.js"></script>
|
21
|
+
<script type="text/javascript" src="javascripts/TweetSpec.js"></script>
|
22
|
+
<script type="text/javascript" src="javascripts/TwitterApiSpec.js"></script>
|
23
|
+
|
24
|
+
</head>
|
25
|
+
<body>
|
26
|
+
<script type="text/javascript">
|
27
|
+
jasmine.getEnv().addReporter(new jasmine.TrivialReporter());
|
28
|
+
jasmine.getEnv().execute();
|
29
|
+
</script>
|
30
|
+
|
31
|
+
</body>
|
32
|
+
</html>
|
@@ -0,0 +1,24 @@
|
|
1
|
+
describe("Tweet", function(){
|
2
|
+
var tweet;
|
3
|
+
|
4
|
+
beforeEach(function(){
|
5
|
+
tweet = new Tweet(eval('(' + Tweets.noAtReply + ')'));
|
6
|
+
});
|
7
|
+
|
8
|
+
it("should create a pretty date", function(){
|
9
|
+
expect(tweet.postedAt).toEqual("Thu, 29 Jul 2010 02:18:53 +0000");
|
10
|
+
});
|
11
|
+
|
12
|
+
it("should store the users messages", function(){
|
13
|
+
expect(tweet.text).toEqual("Pres Obama on stage with the Foo fighters, jonas brothers and a whole lot of ppl..nice..");
|
14
|
+
});
|
15
|
+
|
16
|
+
it("should store the username", function(){
|
17
|
+
expect(tweet.user).toEqual("_wbrodrigues");
|
18
|
+
});
|
19
|
+
|
20
|
+
it("stores the users messages", function(){
|
21
|
+
expect(tweet.imageUrl).toEqual("http://a2.twimg.com/profile_images/1014111170/06212010155_normal.jpg");
|
22
|
+
});
|
23
|
+
|
24
|
+
});
|
@@ -0,0 +1,89 @@
|
|
1
|
+
describe("TwitterApi#search", function(){
|
2
|
+
var twitter, request;
|
3
|
+
var onSuccess, onFailure, onComplete, onFailWhale;
|
4
|
+
|
5
|
+
beforeEach(function(){
|
6
|
+
jasmine.Ajax.useMock();
|
7
|
+
|
8
|
+
onSuccess = jasmine.createSpy('onSuccess');
|
9
|
+
onFailure = jasmine.createSpy('onFailure');
|
10
|
+
onComplete = jasmine.createSpy('onComplete');
|
11
|
+
onFailWhale = jasmine.createSpy('onFailWhale');
|
12
|
+
|
13
|
+
twitter = new TwitterApi();
|
14
|
+
|
15
|
+
twitter.search('basketball', {
|
16
|
+
onSuccess: onSuccess,
|
17
|
+
onFailure: onFailure,
|
18
|
+
onComplete: onComplete,
|
19
|
+
onFailWhale: onFailWhale
|
20
|
+
});
|
21
|
+
|
22
|
+
request = mostRecentAjaxRequest();
|
23
|
+
});
|
24
|
+
|
25
|
+
it("calls Twitter with the correct url", function(){
|
26
|
+
expect(request.url).toEqual("http://search.twitter.com/search.json?q=basketball")
|
27
|
+
});
|
28
|
+
|
29
|
+
describe("on success", function(){
|
30
|
+
beforeEach(function(){
|
31
|
+
request.response(TestResponses.search.success);
|
32
|
+
});
|
33
|
+
|
34
|
+
it("should call the provided success callback", function() {
|
35
|
+
expect(onSuccess).toHaveBeenCalled();
|
36
|
+
});
|
37
|
+
|
38
|
+
it("calls onComplete", function(){
|
39
|
+
expect(onComplete).toHaveBeenCalled();
|
40
|
+
});
|
41
|
+
|
42
|
+
it("does not call onFailure", function(){
|
43
|
+
expect(onFailure).not.toHaveBeenCalled();
|
44
|
+
});
|
45
|
+
|
46
|
+
it("call convert the server response to Tweet objects", function(){
|
47
|
+
var results = onSuccess.mostRecentCall.args[0];
|
48
|
+
|
49
|
+
expect(results.length).toEqual(15);
|
50
|
+
expect(results[0]).toEqual(jasmine.any(Tweet));
|
51
|
+
});
|
52
|
+
});
|
53
|
+
|
54
|
+
describe('on failure', function(){
|
55
|
+
beforeEach(function(){
|
56
|
+
request.response(TestResponses.search.failure);
|
57
|
+
});
|
58
|
+
|
59
|
+
it("calls onFailure", function() {
|
60
|
+
expect(onFailure).toHaveBeenCalled();
|
61
|
+
});
|
62
|
+
|
63
|
+
it("call onComplete", function(){
|
64
|
+
expect(onComplete).toHaveBeenCalled();
|
65
|
+
});
|
66
|
+
|
67
|
+
it("does not call onSuccess", function(){
|
68
|
+
expect(onSuccess).not.toHaveBeenCalled();
|
69
|
+
});
|
70
|
+
});
|
71
|
+
|
72
|
+
describe("on fail whale", function(){
|
73
|
+
beforeEach(function(){
|
74
|
+
request.response(TestResponses.search.failWhale);
|
75
|
+
});
|
76
|
+
|
77
|
+
it("calls onFailWhale", function(){
|
78
|
+
expect(onFailWhale).toHaveBeenCalled();
|
79
|
+
});
|
80
|
+
|
81
|
+
it("does not call onSuccess", function(){
|
82
|
+
expect(onSuccess).not.toHaveBeenCalled();
|
83
|
+
});
|
84
|
+
|
85
|
+
it("calls onComplete", function(){
|
86
|
+
expect(onComplete).toHaveBeenCalled();
|
87
|
+
});
|
88
|
+
});
|
89
|
+
});
|