drogus-blue-ridge 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. data/LICENSE +20 -0
  2. data/LICENSE-Screw.Unit +22 -0
  3. data/LICENSE-Smoke +22 -0
  4. data/README.markdown +256 -0
  5. data/Rakefile +65 -0
  6. data/VERSION +1 -0
  7. data/blue_ridge_generators/blue_ridge/USAGE +5 -0
  8. data/blue_ridge_generators/blue_ridge/blue_ridge_generator.rb +19 -0
  9. data/blue_ridge_generators/blue_ridge/templates/application.html +16 -0
  10. data/blue_ridge_generators/blue_ridge/templates/application_spec.js +15 -0
  11. data/blue_ridge_generators/blue_ridge/templates/javascript_spec_helper.rb +44 -0
  12. data/blue_ridge_generators/blue_ridge/templates/screw.css +90 -0
  13. data/blue_ridge_generators/blue_ridge/templates/spec_helper.js +1 -0
  14. data/blue_ridge_generators/javascript_spec/USAGE +5 -0
  15. data/blue_ridge_generators/javascript_spec/javascript_spec_generator.rb +52 -0
  16. data/blue_ridge_generators/javascript_spec/templates/fixture.html.erb +13 -0
  17. data/blue_ridge_generators/javascript_spec/templates/fixture_render_spec.rb.erb +10 -0
  18. data/blue_ridge_generators/javascript_spec/templates/javascript_spec.js.erb +10 -0
  19. data/lib/blue-ridge.js +73 -0
  20. data/lib/consoleReportForRake.js +32 -0
  21. data/lib/env.rhino.js +8841 -0
  22. data/lib/jquery-1.2.6.js +3549 -0
  23. data/lib/jquery-1.3.2.js +4376 -0
  24. data/lib/jquery.fn.js +29 -0
  25. data/lib/jquery.print.js +109 -0
  26. data/lib/js.jar +0 -0
  27. data/lib/screw.behaviors.js +92 -0
  28. data/lib/screw.builder.js +82 -0
  29. data/lib/screw.events.js +45 -0
  30. data/lib/screw.matchers.js +187 -0
  31. data/lib/screw.mocking.js +26 -0
  32. data/lib/shell.js +27 -0
  33. data/lib/smoke.core.js +49 -0
  34. data/lib/smoke.mock.js +171 -0
  35. data/lib/smoke.stub.js +29 -0
  36. data/lib/test_runner.js +58 -0
  37. data/spec/fixtures/rails_project/app/controllers/accounts_controller.rb +85 -0
  38. data/spec/fixtures/rails_project/app/controllers/application_controller.rb +10 -0
  39. data/spec/fixtures/rails_project/app/controllers/home_controller.rb +5 -0
  40. data/spec/fixtures/rails_project/app/helpers/accounts_helper.rb +2 -0
  41. data/spec/fixtures/rails_project/app/helpers/application_helper.rb +13 -0
  42. data/spec/fixtures/rails_project/app/helpers/home_helper.rb +2 -0
  43. data/spec/fixtures/rails_project/app/models/account.rb +3 -0
  44. data/spec/fixtures/rails_project/config/boot.rb +110 -0
  45. data/spec/fixtures/rails_project/config/environment.rb +41 -0
  46. data/spec/fixtures/rails_project/config/environments/cucumber.rb +25 -0
  47. data/spec/fixtures/rails_project/config/environments/development.rb +17 -0
  48. data/spec/fixtures/rails_project/config/environments/production.rb +28 -0
  49. data/spec/fixtures/rails_project/config/environments/test.rb +35 -0
  50. data/spec/fixtures/rails_project/config/initializers/backtrace_silencers.rb +7 -0
  51. data/spec/fixtures/rails_project/config/initializers/inflections.rb +10 -0
  52. data/spec/fixtures/rails_project/config/initializers/mime_types.rb +5 -0
  53. data/spec/fixtures/rails_project/config/initializers/new_rails_defaults.rb +19 -0
  54. data/spec/fixtures/rails_project/config/initializers/session_store.rb +2 -0
  55. data/spec/fixtures/rails_project/config/routes.rb +47 -0
  56. data/spec/fixtures/rails_project/db/migrate/20090719005327_create_sessions.rb +16 -0
  57. data/spec/fixtures/rails_project/db/migrate/20090719031606_create_accounts.rb +13 -0
  58. data/spec/fixtures/rails_project/db/schema.rb +30 -0
  59. data/spec/fixtures/rails_project/spec/spec_helper.rb +52 -0
  60. data/tasks/javascript_testing_tasks.rake +84 -0
  61. data/test/test_blue_ridge_generator.rb +48 -0
  62. data/test/test_generator_helper.rb +29 -0
  63. data/test/test_javascript_spec_generator.rb +57 -0
  64. metadata +148 -0
@@ -0,0 +1,29 @@
1
+ (function($) {
2
+ $.fn.fn = function() {
3
+ var self = this;
4
+ var extension = arguments[0], name = arguments[0];
5
+ if (typeof name == "string") {
6
+ return apply(self, name, $.makeArray(arguments).slice(1, arguments.length));
7
+ } else {
8
+ $.each(extension, function(key, value) {
9
+ define(self, key, value);
10
+ });
11
+ return self;
12
+ }
13
+ }
14
+ function define(self, name, fn) {
15
+ self.data(namespacedName(name), fn);
16
+ };
17
+ function apply(self, name, args) {
18
+ var result;
19
+ self.each(function(i, item) {
20
+ var fn = $(item).data(namespacedName(name));
21
+ if (fn) result = fn.apply(item, args)
22
+ else throw(name + " is not defined");
23
+ });
24
+ return result;
25
+ };
26
+ function namespacedName(name) {
27
+ return 'fn.' + name;
28
+ }
29
+ })(jQuery);
@@ -0,0 +1,109 @@
1
+ (function($) {
2
+
3
+ function print_array(obj, opts) {
4
+ var result = [];
5
+ for (var i = 0; i < Math.min(opts.max_array, obj.length); i++)
6
+ result.push($.print(obj[i], $.extend({}, opts, { max_array: 3, max_string: 40 })));
7
+
8
+ if (obj.length > opts.max_array)
9
+ result.push((obj.length - opts.max_array) + ' more...');
10
+ if (result.length == 0) return "[]"
11
+ return "[ " + result.join(", ") + " ]";
12
+ }
13
+
14
+ function print_element(obj) {
15
+ if (obj.nodeType == 1) {
16
+ var result = [];
17
+ var properties = [ 'className', 'id' ];
18
+ var extra = {
19
+ 'input': ['type', 'name', 'value'],
20
+ 'a': ['href', 'target'],
21
+ 'form': ['method', 'action'],
22
+ 'script': ['src'],
23
+ 'link': ['href'],
24
+ 'img': ['src']
25
+ };
26
+
27
+ $.each(properties.concat(extra[obj.tagName.toLowerCase()] || []), function(){
28
+ if (obj[this])
29
+ result.push(' ' + this.replace('className', 'class') + "=" + $.print(obj[this]))
30
+ });
31
+ return "<" + obj.tagName.toLowerCase()
32
+ + result.join('') + ">";
33
+ }
34
+ }
35
+
36
+ function print_object(obj, opts) {
37
+ var seen = opts.seen || [ obj ];
38
+
39
+ var result = [], key, value;
40
+ for (var k in obj) {
41
+ if (obj.hasOwnProperty(k) && $.inArray(obj[k], seen) < 0) {
42
+ seen.push(obj[k]);
43
+ value = $.print(obj[k], $.extend({}, opts, { max_array: 6, max_string: 40, seen: seen }));
44
+ } else
45
+ value = "...";
46
+ result.push(k + ": " + value);
47
+ }
48
+ if (result.length == 0) return "{}";
49
+ return "{ " + result.join(", ") + " }";
50
+ }
51
+
52
+ function print_string(value, opts) {
53
+ var character_substitutions = {
54
+ '\b': '\\b',
55
+ '\t': '\\t',
56
+ '\n': '\\n',
57
+ '\f': '\\f',
58
+ '\r': '\\r',
59
+ '"' : '\\"',
60
+ '\\': '\\\\'
61
+ };
62
+ var r = /["\\\x00-\x1f\x7f-\x9f]/g;
63
+
64
+ var str = r.test(value)
65
+ ? '"' + value.replace(r, function (a) {
66
+ var c = character_substitutions[a];
67
+ if (c) return c;
68
+ c = a.charCodeAt();
69
+ return '\\u00' + Math.floor(c / 16).toString(16) + (c % 16).toString(16);
70
+ }) + '"'
71
+ : '"' + value + '"';
72
+ if (str.length > opts.max_string)
73
+ return str.slice(0, opts.max_string + 1) + '..."';
74
+ else
75
+ return str;
76
+ }
77
+
78
+ $.print = function(obj, options) {
79
+ var opts = $.extend({}, { max_array: 10, max_string: 100 }, options);
80
+
81
+ if (typeof obj == 'undefined')
82
+ return "undefined";
83
+ else if (typeof obj == 'boolean')
84
+ return obj.toString();
85
+ else if (typeof obj == 'number')
86
+ return obj.toString();
87
+ else if (!obj)
88
+ return "null";
89
+ else if (typeof obj == 'string')
90
+ return print_string(obj, opts);
91
+ else if (obj instanceof RegExp)
92
+ return obj.toString();
93
+ else if (obj instanceof Array || obj.callee || obj.item)
94
+ return print_array(obj, opts);
95
+ else if (typeof obj == 'function' || obj instanceof Function)
96
+ return obj.toString().match(/^([^)]*\))/)[1];
97
+ else if (obj.nodeType)
98
+ return print_element(obj);
99
+ else if (obj instanceof jQuery)
100
+ return "$(" + $.print(obj.get()) + ")";
101
+ else if (obj instanceof Error)
102
+ return print_object(obj, $.extend({}, options, { max_string: 200 }));
103
+ else if (obj instanceof Object)
104
+ return print_object(obj, opts);
105
+ else
106
+ return obj.toString().replace(/\n\s*/g, '');
107
+ }
108
+
109
+ })(jQuery);
Binary file
@@ -0,0 +1,92 @@
1
+ (function($) {
2
+ $(Screw).bind('loaded', function() {
3
+ $('.status').fn({
4
+ display: function() {
5
+ $(this).html(
6
+ $('.passed').length + $('.failed').length + ' test(s), ' + $('.failed').length + ' failure(s)<br />' +
7
+ ((new Date() - Screw.suite_start_time)/1000.0).toString() + " seconds elapsed"
8
+ );
9
+ }
10
+ });
11
+
12
+ $('.describe').fn({
13
+ parent: function() {
14
+ return $(this).parent('.describes').parent('.describe');
15
+ },
16
+
17
+ run_befores: function() {
18
+ $(this).fn('parent').fn('run_befores');
19
+ $(this).children('.befores').children('.before').fn('run');
20
+ },
21
+
22
+ run_afters: function() {
23
+ $(this).fn('parent').fn('run_afters');
24
+ $(this).children('.afters').children('.after').fn('run');
25
+ },
26
+
27
+ enqueue: function() {
28
+ $(this).children('.its').children('.it').fn('enqueue');
29
+ $(this).children('.describes').children('.describe').fn('enqueue');
30
+ },
31
+
32
+ selector: function() {
33
+ return $(this).fn('parent').fn('selector')
34
+ + ' > .describes > .describe:eq(' + $(this).parent('.describes').children('.describe').index(this) + ')';
35
+ }
36
+ });
37
+
38
+ $('body > .describe').fn({
39
+ selector: function() { return 'body > .describe' }
40
+ });
41
+
42
+ $('.it').fn({
43
+ parent: function() {
44
+ return $(this).parent('.its').parent('.describe');
45
+ },
46
+
47
+ run: function() {
48
+ try {
49
+ try {
50
+ $(this).fn('parent').fn('run_befores');
51
+ $(this).data('screwunit.run')();
52
+ } finally {
53
+ $(this).fn('parent').fn('run_afters');
54
+ }
55
+ $(this).trigger('passed');
56
+ } catch(e) {
57
+ $(this).trigger('failed', [e]);
58
+ }
59
+ },
60
+
61
+ enqueue: function() {
62
+ var self = $(this).trigger('enqueued');
63
+ $(Screw)
64
+ .queue(function() {
65
+ self.fn('run');
66
+ setTimeout(function() { $(Screw).dequeue() }, 0);
67
+ });
68
+ },
69
+
70
+ selector: function() {
71
+ return $(this).fn('parent').fn('selector')
72
+ + ' > .its > .it:eq(' + $(this).parent('.its').children('.it').index(this) + ')';
73
+ }
74
+ });
75
+
76
+ $('.before').fn({
77
+ run: function() { $(this).data('screwunit.run')() }
78
+ });
79
+
80
+ $('.after').fn({
81
+ run: function() { $(this).data('screwunit.run')() }
82
+ });
83
+
84
+ $(Screw).trigger('before');
85
+ var to_run = unescape(location.search.slice(1)) || 'body > .describe > .describes > .describe';
86
+ $(to_run)
87
+ .focus()
88
+ .eq(0).trigger('scroll').end()
89
+ .fn('enqueue');
90
+ $(Screw).queue(function() { $(Screw).trigger('after') });
91
+ })
92
+ })(jQuery);
@@ -0,0 +1,82 @@
1
+ var Screw = (function($) {
2
+ var screw = {
3
+ Unit: function(fn) {
4
+ var contents = fn.toString().match(/^[^\{]*{((.*\n*)*)}/m)[1];
5
+ var fn = new Function("matchers", "specifications",
6
+ "with (specifications) { with (matchers) { " + contents + " } }"
7
+ );
8
+
9
+ $(Screw).queue(function() {
10
+ Screw.Specifications.context.push($('body > .describe'));
11
+ fn.call(this, Screw.Matchers, Screw.Specifications);
12
+ Screw.Specifications.context.pop();
13
+ $(this).dequeue();
14
+ });
15
+ },
16
+
17
+ Specifications: {
18
+ context: [],
19
+
20
+ describe: function(name, fn) {
21
+ var describe = $('<li class="describe"></li>')
22
+ .append($('<h1></h1>').text(name))
23
+ .append('<ol class="befores"></ol>')
24
+ .append('<ul class="its"></ul>')
25
+ .append('<ul class="describes"></ul>')
26
+ .append('<ol class="afters"></ol>');
27
+
28
+ this.context.push(describe);
29
+ fn.call();
30
+ this.context.pop();
31
+
32
+ this.context[this.context.length-1]
33
+ .children('.describes')
34
+ .append(describe);
35
+ },
36
+
37
+ it: function(name, fn) {
38
+ var it = $('<li class="it"></li>')
39
+ .append($('<h2></h2>').text(name))
40
+ .data('screwunit.run', fn);
41
+
42
+ this.context[this.context.length-1]
43
+ .children('.its')
44
+ .append(it);
45
+ },
46
+
47
+ before: function(fn) {
48
+ var before = $('<li class="before"></li>')
49
+ .data('screwunit.run', fn);
50
+
51
+ this.context[this.context.length-1]
52
+ .children('.befores')
53
+ .append(before);
54
+ },
55
+
56
+ after: function(fn) {
57
+ var after = $('<li class="after"></li>')
58
+ .data('screwunit.run', fn);
59
+
60
+ this.context[this.context.length-1]
61
+ .children('.afters')
62
+ .append(after);
63
+ }
64
+ }
65
+ };
66
+
67
+ $(screw).queue(function() { $(screw).trigger('loading') });
68
+
69
+ $(window).load(function(){
70
+ $('<div class="describe"></div>')
71
+ .append('<h3 class="status"></h3>')
72
+ .append('<ol class="befores"></ol>')
73
+ .append('<ul class="describes"></ul>')
74
+ .append('<ol class="afters"></ol>')
75
+ .appendTo('body');
76
+
77
+ $(screw).dequeue();
78
+ $(screw).trigger('loaded');
79
+ });
80
+
81
+ return screw;
82
+ })(jQuery);
@@ -0,0 +1,45 @@
1
+ (function($) {
2
+ $(Screw)
3
+ .bind('loaded', function() {
4
+ $('.describe, .it')
5
+ .click(function() {
6
+ document.location = location.href.split('?')[0] + '?' + $(this).fn('selector');
7
+ return false;
8
+ })
9
+ .focus(function() {
10
+ return $(this).addClass('focused');
11
+ })
12
+ .bind('scroll', function() {
13
+ document.body.scrollTop = $(this).offset().top;
14
+ });
15
+
16
+ $('.it')
17
+ .bind('enqueued', function() {
18
+ $(this).addClass('enqueued');
19
+ })
20
+ .bind('running', function() {
21
+ $(this).addClass('running');
22
+ })
23
+ .bind('passed', function() {
24
+ $(this).addClass('passed');
25
+ })
26
+ .bind('failed', function(e, reason) {
27
+ $(this)
28
+ .addClass('failed')
29
+ .append($('<p class="error"></p>').text(reason.toString()));
30
+
31
+ var file = reason.fileName || reason.sourceURL;
32
+ var line = reason.lineNumber || reason.line;
33
+ if (file || line) {
34
+ $(this).append($('<p class="error"></p>').text('line ' + line + ', ' + file));
35
+ }
36
+ })
37
+ })
38
+ .bind('before', function() {
39
+ Screw.suite_start_time = new Date();
40
+ $('.status').text('Running...');
41
+ })
42
+ .bind('after', function() {
43
+ $('.status').fn('display')
44
+ })
45
+ })(jQuery);
@@ -0,0 +1,187 @@
1
+ Screw.Matchers = (function($) {
2
+ return matchers = {
3
+ expect: function(actual) {
4
+ return {
5
+ to: function(matcher, expected, not) {
6
+ var matched = matcher.match(expected, actual);
7
+ if (not ? matched : !matched) {
8
+ throw(matcher.failure_message(expected, actual, not));
9
+ }
10
+ },
11
+
12
+ to_not: function(matcher, expected) {
13
+ this.to(matcher, expected, true);
14
+ }
15
+ }
16
+ },
17
+
18
+ equal: {
19
+ match: function(expected, actual) {
20
+ if(expected == actual) return true;
21
+ if(actual == undefined) return false;
22
+
23
+ if (expected instanceof Array) {
24
+ for (var i = 0; i < actual.length; i++)
25
+ if (!Screw.Matchers.equal.match(expected[i], actual[i])) return false;
26
+ return actual.length == expected.length;
27
+ } else if (expected instanceof Object) {
28
+ for (var key in expected)
29
+ if (!this.match(expected[key], actual[key])) return false;
30
+ for (var key in actual)
31
+ if (!this.match(actual[key], expected[key])) return false;
32
+ return true;
33
+ }
34
+ return false;
35
+ },
36
+
37
+ failure_message: function(expected, actual, not) {
38
+ return 'expected ' + $.print(actual) + (not ? ' to not equal ' : ' to equal ') + $.print(expected);
39
+ }
40
+ },
41
+
42
+ be_gt: {
43
+ match: function(expected, actual) {
44
+ return actual > expected;
45
+ },
46
+
47
+ failure_message: function(expected, actual, not) {
48
+ return 'expected ' + $.print(actual) + (not ? ' to not ' : ' to ') + 'be greater than ' + $.print(expected);
49
+ }
50
+ },
51
+
52
+ be_gte: {
53
+ match: function(expected, actual) {
54
+ return actual >= expected;
55
+ },
56
+
57
+ failure_message: function(expected, actual, not) {
58
+ return 'expected ' + $.print(actual) + (not ? ' to not ' : ' to ') + 'be greater than or equal to ' + $.print(expected);
59
+ }
60
+ },
61
+
62
+ be_lt: {
63
+ match: function(expected, actual) {
64
+ return actual < expected;
65
+ },
66
+
67
+ failure_message: function(expected, actual, not) {
68
+ return 'expected ' + $.print(actual) + (not ? ' to not ' : ' to ') + 'be less than ' + $.print(expected);
69
+ }
70
+ },
71
+
72
+ be_lte: {
73
+ match: function(expected, actual) {
74
+ return actual <= expected;
75
+ },
76
+
77
+ failure_message: function(expected, actual, not) {
78
+ return 'expected ' + $.print(actual) + (not ? ' to not ' : ' to ') + 'be less than or equal to ' + $.print(expected);
79
+ }
80
+ },
81
+
82
+ match: {
83
+ match: function(expected, actual) {
84
+ if (expected.constructor == RegExp)
85
+ return expected.exec(actual.toString());
86
+ else
87
+ return actual.indexOf(expected) > -1;
88
+ },
89
+
90
+ failure_message: function(expected, actual, not) {
91
+ return 'expected ' + $.print(actual) + (not ? ' to not match ' : ' to match ') + $.print(expected);
92
+ }
93
+ },
94
+
95
+ be_empty: {
96
+ match: function(expected, actual) {
97
+ if (actual.length == undefined) throw(actual.toString() + " does not respond to length");
98
+
99
+ return actual.length == 0;
100
+ },
101
+
102
+ failure_message: function(expected, actual, not) {
103
+ return 'expected ' + $.print(actual) + (not ? ' to not be empty' : ' to be empty');
104
+ }
105
+ },
106
+
107
+ have_length: {
108
+ match: function(expected, actual) {
109
+ if (actual.length == undefined) throw(actual.toString() + " does not respond to length");
110
+
111
+ return actual.length == expected;
112
+ },
113
+
114
+ failure_message: function(expected, actual, not) {
115
+ return 'expected ' + $.print(actual) + (not ? ' to not' : ' to') + ' have length ' + expected;
116
+ }
117
+ },
118
+
119
+ be_null: {
120
+ match: function(expected, actual) {
121
+ return actual == null;
122
+ },
123
+
124
+ failure_message: function(expected, actual, not) {
125
+ return 'expected ' + $.print(actual) + (not ? ' to not be null' : ' to be null');
126
+ }
127
+ },
128
+
129
+ be_undefined: {
130
+ match: function(expected, actual) {
131
+ return actual == undefined;
132
+ },
133
+
134
+ failure_message: function(expected, actual, not) {
135
+ return 'expected ' + $.print(actual) + (not ? ' to not be undefined' : ' to be undefined');
136
+ }
137
+ },
138
+
139
+ be_true: {
140
+ match: function(expected, actual) {
141
+ return actual;
142
+ },
143
+
144
+ failure_message: function(expected, actual, not) {
145
+ return 'expected ' + $.print(actual) + (not ? ' to not be true' : ' to be true');
146
+ }
147
+ },
148
+
149
+ be_false: {
150
+ match: function(expected, actual) {
151
+ return !actual;
152
+ },
153
+
154
+ failure_message: function(expected, actual, not) {
155
+ return 'expected ' + $.print(actual) + (not ? ' to not be false' : ' to be false');
156
+ }
157
+ },
158
+
159
+ match_selector: {
160
+ match: function(expected, actual) {
161
+ if (!(actual instanceof jQuery)) {
162
+ throw expected.toString() + " must be an instance of jQuery to match against a selector"
163
+ }
164
+
165
+ return actual.is(expected);
166
+ },
167
+
168
+ failure_message: function(expected, actual, not) {
169
+ return 'expected ' + $.print(actual) + (not ? ' to not match selector ' : ' to match selector ') + expected;
170
+ }
171
+ },
172
+
173
+ contain_selector: {
174
+ match: function(expected, actual) {
175
+ if (!(actual instanceof jQuery)) {
176
+ throw expected.toString() + " must be an instance of jQuery to match against a selector"
177
+ }
178
+
179
+ return actual.find(expected).length > 0;
180
+ },
181
+
182
+ failure_message: function(expected, actual, not) {
183
+ return 'expected ' + $.print(actual) + (not ? ' to not contain selector ' : ' to contain selector ') + expected;
184
+ }
185
+ }
186
+ }
187
+ })(jQuery);