pivotal-screw-unit 0.4.0

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.
Files changed (127) hide show
  1. data/CHANGES +21 -0
  2. data/README.markdown +354 -0
  3. data/Rakefile +39 -0
  4. data/VERSION.yml +4 -0
  5. data/bin/screw_unit +6 -0
  6. data/bin/screw_unit_server +10 -0
  7. data/core/CHANGES +10 -0
  8. data/core/EXAMPLE.html +68 -0
  9. data/core/LICENSE +22 -0
  10. data/core/README.markdown +307 -0
  11. data/core/example/models/cat.js +5 -0
  12. data/core/example/models/man.js +17 -0
  13. data/core/example/spec/matchers/have.js +8 -0
  14. data/core/example/spec/models/cat_spec.js +31 -0
  15. data/core/example/spec/models/man_spec.js +34 -0
  16. data/core/example/spec/spec_helper.js +5 -0
  17. data/core/example/spec/suite.html +25 -0
  18. data/core/lib/jquery-1.3.2.js +4376 -0
  19. data/core/lib/jquery.fn.js +30 -0
  20. data/core/lib/jquery.print.js +109 -0
  21. data/core/lib/screw.behaviors.js +93 -0
  22. data/core/lib/screw.builder.js +94 -0
  23. data/core/lib/screw.css +90 -0
  24. data/core/lib/screw.events.js +45 -0
  25. data/core/lib/screw.matchers.js +244 -0
  26. data/core/spec/behaviors_spec.js +188 -0
  27. data/core/spec/matchers_spec.js +372 -0
  28. data/core/spec/print_spec.js +158 -0
  29. data/core/spec/spec_helper.js +0 -0
  30. data/core/spec/suite.html +19 -0
  31. data/core/spec/with_screw_context_spec.js +9 -0
  32. data/init.rb +0 -0
  33. data/lib/screw_unit/representations/spec.html.rb +117 -0
  34. data/lib/screw_unit/representations.rb +2 -0
  35. data/lib/screw_unit.rb +19 -0
  36. data/spec/functional/functional_spec.rb +25 -0
  37. data/spec/functional/functional_spec_helper.rb +34 -0
  38. data/spec/functional/functional_spec_server_starter.rb +63 -0
  39. data/spec/functional_suite.rb +10 -0
  40. data/spec/spec_suite.rb +3 -0
  41. data/spec/unit/js_test_core/specs/spec_dir_spec.rb +39 -0
  42. data/spec/unit/js_test_core/specs/spec_file_spec.rb +35 -0
  43. data/spec/unit/unit_spec_helper.rb +119 -0
  44. data/spec/unit_suite.rb +10 -0
  45. data/vendor/js-test-core/CHANGES +25 -0
  46. data/vendor/js-test-core/README +12 -0
  47. data/vendor/js-test-core/Rakefile +73 -0
  48. data/vendor/js-test-core/lib/js_test_core/client.rb +129 -0
  49. data/vendor/js-test-core/lib/js_test_core/extensions/time.rb +6 -0
  50. data/vendor/js-test-core/lib/js_test_core/extensions.rb +3 -0
  51. data/vendor/js-test-core/lib/js_test_core/rack/commonlogger.rb +5 -0
  52. data/vendor/js-test-core/lib/js_test_core/rack.rb +2 -0
  53. data/vendor/js-test-core/lib/js_test_core/rails_server.rb +22 -0
  54. data/vendor/js-test-core/lib/js_test_core/representations/spec.html.rb +23 -0
  55. data/vendor/js-test-core/lib/js_test_core/representations.rb +9 -0
  56. data/vendor/js-test-core/lib/js_test_core/resources/dir.rb +67 -0
  57. data/vendor/js-test-core/lib/js_test_core/resources/file.rb +42 -0
  58. data/vendor/js-test-core/lib/js_test_core/resources/runner.rb +107 -0
  59. data/vendor/js-test-core/lib/js_test_core/resources/session.rb +44 -0
  60. data/vendor/js-test-core/lib/js_test_core/resources/session_finish.rb +17 -0
  61. data/vendor/js-test-core/lib/js_test_core/resources/specs/spec.rb +32 -0
  62. data/vendor/js-test-core/lib/js_test_core/resources/specs/spec_dir.rb +50 -0
  63. data/vendor/js-test-core/lib/js_test_core/resources/specs/spec_file.rb +21 -0
  64. data/vendor/js-test-core/lib/js_test_core/resources/web_root.rb +66 -0
  65. data/vendor/js-test-core/lib/js_test_core/resources.rb +17 -0
  66. data/vendor/js-test-core/lib/js_test_core/selenium/client/driver.rb +7 -0
  67. data/vendor/js-test-core/lib/js_test_core/selenium.rb +2 -0
  68. data/vendor/js-test-core/lib/js_test_core/selenium_server_configuration.rb +48 -0
  69. data/vendor/js-test-core/lib/js_test_core/server.rb +50 -0
  70. data/vendor/js-test-core/lib/js_test_core/thin/backends/js_test_core_server.rb +9 -0
  71. data/vendor/js-test-core/lib/js_test_core/thin/js_test_core_connection.rb +8 -0
  72. data/vendor/js-test-core/lib/js_test_core/thin.rb +3 -0
  73. data/vendor/js-test-core/lib/js_test_core.rb +41 -0
  74. data/vendor/js-test-core/spec/example_core/JsTestCore.css +0 -0
  75. data/vendor/js-test-core/spec/example_core/JsTestCore.js +0 -0
  76. data/vendor/js-test-core/spec/example_public/favicon.ico +0 -0
  77. data/vendor/js-test-core/spec/example_public/javascripts/foo.js +3 -0
  78. data/vendor/js-test-core/spec/example_public/javascripts/large_file.js +59 -0
  79. data/vendor/js-test-core/spec/example_public/javascripts/subdir/bar.js +1 -0
  80. data/vendor/js-test-core/spec/example_public/robots.txt +0 -0
  81. data/vendor/js-test-core/spec/example_public/stylesheets/example.css +3 -0
  82. data/vendor/js-test-core/spec/example_specs/custom_dir_and_suite/passing_spec.js +6 -0
  83. data/vendor/js-test-core/spec/example_specs/custom_dir_and_suite.html +9 -0
  84. data/vendor/js-test-core/spec/example_specs/custom_suite.html +8 -0
  85. data/vendor/js-test-core/spec/example_specs/failing_spec.js +5 -0
  86. data/vendor/js-test-core/spec/example_specs/foo/failing_spec.js +6 -0
  87. data/vendor/js-test-core/spec/example_specs/foo/passing_spec.js +6 -0
  88. data/vendor/js-test-core/spec/spec_suite.rb +2 -0
  89. data/vendor/js-test-core/spec/specs/failing_spec.js +0 -0
  90. data/vendor/js-test-core/spec/unit/js_test_core/client_spec.rb +192 -0
  91. data/vendor/js-test-core/spec/unit/js_test_core/rails_server_spec.rb +45 -0
  92. data/vendor/js-test-core/spec/unit/js_test_core/resources/dir_spec.rb +53 -0
  93. data/vendor/js-test-core/spec/unit/js_test_core/resources/file_not_found_spec.rb +16 -0
  94. data/vendor/js-test-core/spec/unit/js_test_core/resources/file_spec.rb +90 -0
  95. data/vendor/js-test-core/spec/unit/js_test_core/resources/runners/runner_spec.rb +303 -0
  96. data/vendor/js-test-core/spec/unit/js_test_core/resources/session_finish_spec.rb +79 -0
  97. data/vendor/js-test-core/spec/unit/js_test_core/resources/session_spec.rb +82 -0
  98. data/vendor/js-test-core/spec/unit/js_test_core/resources/specs/spec_dir_spec.rb +104 -0
  99. data/vendor/js-test-core/spec/unit/js_test_core/resources/specs/spec_file_spec.rb +41 -0
  100. data/vendor/js-test-core/spec/unit/js_test_core/resources/web_root_spec.rb +32 -0
  101. data/vendor/js-test-core/spec/unit/js_test_core/selenium_server_configuration_spec.rb +49 -0
  102. data/vendor/js-test-core/spec/unit/js_test_core/server_spec.rb +117 -0
  103. data/vendor/js-test-core/spec/unit/thin/js_test_core_connection_spec.rb +6 -0
  104. data/vendor/js-test-core/spec/unit/unit_spec_helper.rb +161 -0
  105. data/vendor/js-test-core/spec/unit_suite.rb +10 -0
  106. data/vendor/js-test-core/vendor/thin-rest/CHANGES +2 -0
  107. data/vendor/js-test-core/vendor/thin-rest/README +0 -0
  108. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/connection.rb +117 -0
  109. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/extensions/object.rb +21 -0
  110. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/extensions.rb +3 -0
  111. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/representations/internal_error.html.rb +19 -0
  112. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/representations/page.html.rb +41 -0
  113. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/representations/resource_not_found.html.rb +18 -0
  114. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/representations.rb +4 -0
  115. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/resources/internal_error.rb +11 -0
  116. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/resources/resource.rb +105 -0
  117. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/resources/resource_not_found.rb +19 -0
  118. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/resources.rb +4 -0
  119. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/routing_error.rb +5 -0
  120. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest.rb +10 -0
  121. data/vendor/js-test-core/vendor/thin-rest/spec/spec_suite.rb +5 -0
  122. data/vendor/js-test-core/vendor/thin-rest/spec/thin_rest/connection_spec.rb +205 -0
  123. data/vendor/js-test-core/vendor/thin-rest/spec/thin_rest/resources/resource_not_found_spec.rb +16 -0
  124. data/vendor/js-test-core/vendor/thin-rest/spec/thin_rest/resources/resource_spec.rb +135 -0
  125. data/vendor/js-test-core/vendor/thin-rest/spec/thin_rest/resources/root_spec.rb +16 -0
  126. data/vendor/js-test-core/vendor/thin-rest/spec/thin_rest_spec_helper.rb +133 -0
  127. metadata +184 -0
@@ -0,0 +1,158 @@
1
+ Screw.Unit(function() {
2
+ describe("Print", function() {
3
+ describe('when given undefined', function() {
4
+ it("returns 'undefined'", function() {
5
+ expect($.print(undefined)).to(equal, 'undefined');
6
+ });
7
+ });
8
+
9
+ describe('when given null', function() {
10
+ it("returns 'null'", function() {
11
+ expect($.print(null)).to(equal, 'null');
12
+ });
13
+ });
14
+
15
+ describe('when given a number', function() {
16
+ it("returns the string representation of the number", function() {
17
+ expect($.print(1)).to(equal, '1');
18
+ expect($.print(1.01)).to(equal, '1.01');
19
+ expect($.print(-1)).to(equal, '-1');
20
+ });
21
+ });
22
+
23
+ describe('when given a boolean', function() {
24
+ it("returns the string representation of the boolean", function() {
25
+ expect($.print(true)).to(equal, 'true');
26
+ expect($.print(false)).to(equal, 'false');
27
+ });
28
+ });
29
+
30
+ describe('when given a string', function() {
31
+ it("returns the string, quoted", function() {
32
+ expect($.print('asdf')).to(equal, '"asdf"');
33
+ });
34
+
35
+ describe('when the string is longer than the [max_string] option', function() {
36
+ it("returns the string, truncated", function() {
37
+ expect($.print('asdf', { max_string: 3 })).to(equal, '"asd..."');
38
+ });
39
+ });
40
+
41
+ describe('when the strings has quotes or escaped characters', function() {
42
+ it("returns the string, with quotes and escaped characters escaped", function() {
43
+ expect($.print('as"df')).to(equal, '"as\\"df"');
44
+ expect($.print('as\tdf')).to(equal, '"as\\tdf"');
45
+ });
46
+ });
47
+ });
48
+
49
+ describe('when given a function', function() {
50
+ it("returns the function's signature", function() {
51
+ expect($.print(function() {})).to(match, /function\s*\(\)/);
52
+ expect($.print(function foo() {})).to(match, /function\s*foo\(\)/);
53
+ expect($.print(function foo(bar) {})).to(match, /function\s*foo\(bar\)/);
54
+ });
55
+ });
56
+
57
+ describe('when given a RegExp', function() {
58
+ it('should print the regexp', function() {
59
+ expect($.print(/abc/i)).to(equal, '/abc/i');
60
+ });
61
+ });
62
+
63
+ describe('when given NaN', function() {
64
+ it('should print the string "NaN"', function() {
65
+ expect($.print(NaN)).to(equal, 'NaN');
66
+ });
67
+ });
68
+
69
+ describe('when given 0', function() {
70
+ it('should print the string "0"', function() {
71
+ expect($.print(0)).to(equal, '0');
72
+ });
73
+ });
74
+
75
+ describe('when given an element', function() {
76
+ it("returns the string representation of the element", function() {
77
+ expect($.print($('<div></div>').get(0))).to(equal, '<div>');
78
+ expect($.print($('<div foo="bar"></div>').get(0))).to(equal, '<div>');
79
+ expect($.print($('<div class="foo" id="bar"></div>').get(0))).to(equal, '<div class="foo" id="bar">');
80
+ });
81
+
82
+ describe('when the element is an img', function() {
83
+ it('prints out the img src attribute', function() {
84
+ expect($.print($('<img src="test.png"/>'))).to(match, /<img src=".+?test.png">/);
85
+ })
86
+ });
87
+ });
88
+
89
+ describe('when given an array', function() {
90
+ it("returns the printed elements, comma separated, encircled by square brackets", function() {
91
+ expect($.print([])).to(equal, '[]');
92
+ expect($.print([1])).to(equal, '[ 1 ]');
93
+ expect($.print([1, 2, 3])).to(equal, '[ 1, 2, 3 ]');
94
+ });
95
+
96
+ describe('when the array is longer than the [max_array] option', function() {
97
+ it("returns the printed array, truncated", function() {
98
+ expect($.print([1, 2, 3, 4], { max_array: 2 })).to(equal, '[ 1, 2, 2 more... ]');
99
+ });
100
+ });
101
+
102
+ describe('when the array has arrays as its elements', function() {
103
+ it("returns the recursively printed array", function() {
104
+ expect($.print([[]])).to(equal, '[ [] ]');
105
+ expect($.print([ [1, 2, 3], 4 ])).to(equal, '[ [ 1, 2, 3 ], 4 ]');
106
+ });
107
+ });
108
+
109
+ describe('when the array has objects as its elements', function() {
110
+ it("returns recursively printed array", function() {
111
+ expect($.print([{}])).to(equal, '[ {} ]');
112
+ expect($.print([ { foo: 'bar' }, 'baz' ])).to(equal, '[ { foo: "bar" }, "baz" ]');
113
+ });
114
+ });
115
+ });
116
+
117
+ describe('when given arguments', function() {
118
+ it("returns the printed array of elements ", function() {
119
+ var args = null;
120
+ (function(){ args = arguments })(1,2,3);
121
+ expect($.print(args)).to(equal, '[ 1, 2, 3 ]');
122
+ });
123
+ });
124
+
125
+ describe('when given a jQuery', function() {
126
+ it("returns the printed array of elements engirthed in '$()'", function() {
127
+ expect($.print($('<div></div>'))).to(equal, '$([ <div> ])');
128
+ });
129
+ });
130
+
131
+ describe('when given a NodeList', function() {
132
+ it("returns the printed array of elements in the list", function() {
133
+ expect($.print(document.getElementsByTagName('body'))).to(equal, '[ <body> ]');
134
+ });
135
+ });
136
+
137
+ describe('when given an object', function() {
138
+ it("returns the keys and values of the object, enraptured with curly braces", function() {
139
+ expect($.print({})).to(equal, '{}');
140
+ expect($.print({ foo: 1, bar: 2 })).to(equal, '{ foo: 1, bar: 2 }');
141
+ });
142
+
143
+ describe('when the values of the object are non-primitive', function() {
144
+ it("recursively prints the keys and values", function() {
145
+ expect($.print({ foo: [1, 2] })).to(equal, '{ foo: [ 1, 2 ] }');
146
+ });
147
+
148
+ describe('when the object has circular references', function() {
149
+ it("returns elipses for circularities", function() {
150
+ var circular = {};
151
+ circular[0] = circular;
152
+ expect($.print(circular)).to(equal, '{ 0: ... }');
153
+ });
154
+ });
155
+ });
156
+ });
157
+ });
158
+ });
File without changes
@@ -0,0 +1,19 @@
1
+ <html>
2
+ <head>
3
+ <script src="../lib/jquery-1.3.2.js"></script>
4
+ <script src="../lib/jquery.fn.js"></script>
5
+ <script src="../lib/jquery.print.js"></script>
6
+ <script src="../lib/screw.builder.js"></script>
7
+ <script src="../lib/screw.matchers.js"></script>
8
+ <script src="../lib/screw.events.js"></script>
9
+ <script src="../lib/screw.behaviors.js"></script>
10
+ <script src="spec_helper.js"></script>
11
+ <script src="behaviors_spec.js"></script>
12
+ <script src="matchers_spec.js"></script>
13
+ <script src="print_spec.js"></script>
14
+ <script src="with_screw_context_spec.js"></script>
15
+
16
+ <link rel="stylesheet" href="../lib/screw.css">
17
+ </head>
18
+ <body></body>
19
+ </html>
@@ -0,0 +1,9 @@
1
+ Screw.Unit(function(screw) { with(screw) {
2
+ describe("Screw.Unit", function() {
3
+ describe("when the passed-in function has an arity of 1", function() {
4
+ it("passes the Screw.Unit context into the function", function() {
5
+ expect(true).to(equal, true);
6
+ });
7
+ });
8
+ });
9
+ }});
data/init.rb ADDED
File without changes
@@ -0,0 +1,117 @@
1
+ module ScrewUnit
2
+ module Representations
3
+ class Spec < JsTestCore::Representations::Spec
4
+ def title_text
5
+ "Screw Unit suite"
6
+ end
7
+
8
+ def head_content
9
+ core_js_files
10
+ script(raw(<<-JS), :type => "text/javascript")
11
+ (function($) {
12
+ Screw.Assets = {};
13
+ Screw.Assets.use_cache_buster = false; // TODO: NS/CTI - make this configurable from the UI.
14
+ var required_paths = [];
15
+ var included_stylesheets = {};
16
+ var cache_buster = parseInt(new Date().getTime()/(1*1000));
17
+
18
+ function tag(name, attributes) {
19
+ var html = "<" + name;
20
+ for(var attribute in attributes) {
21
+ html += (" " + attribute + "='" + attributes[attribute]) + "'";
22
+ };
23
+ html += "></";
24
+ html += name;
25
+ html += ">";
26
+ return html;
27
+ }
28
+
29
+ Screw.Assets.require = function(javascript_path, onload) {
30
+ if(!required_paths[javascript_path]) {
31
+ var full_path = javascript_path + ".js";
32
+ if (Screw.Assets.use_cache_buster) {
33
+ full_path += '?' + cache_buster;
34
+ }
35
+ document.write(tag("script", {src: full_path, type: 'text/javascript'}));
36
+ if(onload) {
37
+ var scripts = document.getElementsByTagName('script');
38
+ scripts[scripts.length-1].onload = onload;
39
+ }
40
+ required_paths[javascript_path] = true;
41
+ }
42
+ };
43
+
44
+ Screw.Assets.stylesheet = function(stylesheet_path) {
45
+ if(!included_stylesheets[stylesheet_path]) {
46
+ var full_path = stylesheet_path + ".css";
47
+ if(Screw.Assets.use_cache_buster) {
48
+ full_path += '?' + cache_buster;
49
+ }
50
+ document.write(tag("link", {rel: 'stylesheet', type: 'text/css', href: full_path}));
51
+ included_stylesheets[stylesheet_path] = true;
52
+ }
53
+ };
54
+
55
+ window.require = Screw.Assets.require;
56
+ window.stylesheet = Screw.Assets.stylesheet;
57
+ })(jQuery);
58
+
59
+ (function($) {
60
+ var ajax = $.ajax;
61
+ $(Screw).bind('after', function() {
62
+ var error_text = $(".error").map(function(i, error_element) {
63
+ var element = $(error_element);
64
+
65
+ var parent_descriptions = element.parents("li.describe");
66
+ var parent_description_text = [];
67
+
68
+ for(var i=parent_descriptions.length-1; i >= 0; i--) {
69
+ parent_description_text.push($(parent_descriptions[i]).find("h1").text());
70
+ }
71
+
72
+ var it_text = element.parents("li.it").find("h2").text();
73
+
74
+ return parent_description_text.join(" ") + " " + it_text + ": " + element.text();
75
+ }).get().join("\\n");
76
+
77
+ ajax({
78
+ type: "POST",
79
+ url: '/session/finish',
80
+ data: {"text": error_text}
81
+ });
82
+ });
83
+ })(jQuery);
84
+ JS
85
+ project_js_files
86
+ link :rel => "stylesheet", :href => "/core/screw.css"
87
+ project_css_files
88
+
89
+ spec_script_elements
90
+ end
91
+
92
+ def core_js_files
93
+ script :src => jquery_js_file
94
+ script :src => "/core/jquery.fn.js"
95
+ script :src => "/core/jquery.print.js"
96
+ script :src => "/core/screw.builder.js"
97
+ script :src => "/core/screw.matchers.js"
98
+ script :src => "/core/screw.events.js"
99
+ script :src => "/core/screw.behaviors.js"
100
+ end
101
+
102
+ def project_js_files
103
+ end
104
+
105
+ def project_css_files
106
+ end
107
+
108
+ def jquery_js_file
109
+ "/core/jquery-1.3.2.js"
110
+ end
111
+
112
+ def body_content
113
+ div :id => "screw_unit_content"
114
+ end
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,2 @@
1
+ dir = File.dirname(__FILE__)
2
+ require "#{dir}/representations/spec.html"
data/lib/screw_unit.rb ADDED
@@ -0,0 +1,19 @@
1
+ require "rubygems"
2
+
3
+ dir = File.dirname(__FILE__)
4
+ $:.unshift(File.expand_path("#{dir}/../vendor/js-test-core/lib"))
5
+ require "js_test_core"
6
+ JsTestCore::Resources::WebRoot.dispatch_specs
7
+
8
+ require "#{dir}/screw_unit/representations"
9
+
10
+ module ScrewUnit
11
+ DEFAULT_HOST = JsTestCore::DEFAULT_HOST
12
+ DEFAULT_PORT = JsTestCore::DEFAULT_PORT
13
+
14
+ Server = JsTestCore::Server
15
+ RailsServer = JsTestCore::RailsServer
16
+ Client = JsTestCore::Client
17
+ end
18
+ JsTestCore.core_path = File.expand_path("#{dir}/../core/lib")
19
+ JsTestCore::Resources::Specs::Spec.spec_representation_class = ScrewUnit::Representations::Spec
@@ -0,0 +1,25 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/functional_spec_helper")
2
+
3
+ describe "ScrewUnit" do
4
+ attr_reader :stdout, :request
5
+ before do
6
+ @stdout = StringIO.new
7
+ ScrewUnit::Client.const_set(:STDOUT, stdout)
8
+ @request = "http request"
9
+ end
10
+
11
+ after do
12
+ ScrewUnit::Client.__send__(:remove_const, :STDOUT)
13
+ end
14
+
15
+ it "runs a full passing Suite" do
16
+ ScrewUnit::Client.run(:spec_url => "#{root_url}/specs/foo/passing_spec")
17
+ stdout.string.strip.should == "SUCCESS"
18
+ end
19
+
20
+ it "runs a full failing Suite" do
21
+ ScrewUnit::Client.run(:spec_url => "#{root_url}/specs/foo/failing_spec")
22
+ stdout.string.strip.should include("FAILURE")
23
+ stdout.string.strip.should include("A failing spec in foo fails: expected true to equal false")
24
+ end
25
+ end
@@ -0,0 +1,34 @@
1
+ require "rubygems"
2
+ require "spec"
3
+ require "spec/autorun"
4
+ require "selenium_rc"
5
+ dir = File.dirname(__FILE__)
6
+ require "#{dir}/functional_spec_server_starter"
7
+
8
+ Spec::Runner.configure do |config|
9
+ config.mock_with :rr
10
+ end
11
+
12
+ Thin::Logging.silent = false
13
+ Thin::Logging.debug = true
14
+
15
+ class Spec::ExampleGroup
16
+ include WaitFor
17
+ attr_reader :spec_root_path, :implementation_root_path, :public_path
18
+
19
+ before(:all) do
20
+ @spec_root_path = FunctionalSpecServerStarter.spec_root_path
21
+ @public_path = FunctionalSpecServerStarter.public_path
22
+ @implementation_root_path = FunctionalSpecServerStarter.implementation_root_path
23
+ # Thread.start do
24
+ # SeleniumRC::Server.boot
25
+ # end
26
+ FunctionalSpecServerStarter.call
27
+ TCPSocket.wait_for_service :host => "0.0.0.0", :port => "4444"
28
+ end
29
+
30
+ def root_url
31
+ "http://#{ScrewUnit::DEFAULT_HOST}:#{ScrewUnit::DEFAULT_PORT}"
32
+ end
33
+ end
34
+
@@ -0,0 +1,63 @@
1
+ require "rubygems"
2
+ require "timeout"
3
+ require "lsof"
4
+ dir = File.dirname(__FILE__)
5
+ $LOAD_PATH.unshift "#{dir}/../../lib"
6
+ require "screw_unit"
7
+ require "nokogiri"
8
+
9
+ module WaitFor
10
+ extend self
11
+ def wait_for(time=5)
12
+ Timeout.timeout(time) do
13
+ loop do
14
+ value = yield
15
+ return value if value
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+ class FunctionalSpecServerStarter
22
+ class << self
23
+ include WaitFor
24
+ def call(threaded=true)
25
+ return if $screw_unit_server_started
26
+ Lsof.kill(8080)
27
+ wait_for do
28
+ !Lsof.running?(8080)
29
+ end
30
+ if threaded
31
+ Thread.start do
32
+ ScrewUnit::Server.run(spec_root_path, implementation_root_path, public_path)
33
+ end
34
+ else
35
+ ScrewUnit::Server.run(spec_root_path, implementation_root_path, public_path)
36
+ end
37
+ wait_for do
38
+ Lsof.running?(8080)
39
+ end
40
+ $screw_unit_server_started = true
41
+ end
42
+
43
+ def spec_root_path
44
+ File.expand_path("#{dir}/../example_specs")
45
+ end
46
+
47
+ def public_path
48
+ File.expand_path("#{dir}/../example_public")
49
+ end
50
+
51
+ def implementation_root_path
52
+ File.expand_path("#{public_path}/javascripts")
53
+ end
54
+
55
+ def dir
56
+ dir = File.dirname(__FILE__)
57
+ end
58
+ end
59
+ end
60
+
61
+ if $0 == __FILE__
62
+ FunctionalSpecServerStarter.call(false)
63
+ end
@@ -0,0 +1,10 @@
1
+ class FunctionalSuite
2
+ def run
3
+ dir = File.dirname(__FILE__)
4
+ Dir["#{dir}/functional/**/*_spec.rb"].each do |file|
5
+ require file
6
+ end
7
+ end
8
+ end
9
+
10
+ FunctionalSuite.new.run
@@ -0,0 +1,3 @@
1
+ dir = File.dirname(__FILE__)
2
+ raise "Failure" unless system(%Q|ruby #{dir}/unit_suite.rb|)
3
+ raise "Failure" unless system(%Q|ruby #{dir}/functional_suite.rb|)
@@ -0,0 +1,39 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../unit_spec_helper")
2
+
3
+ module JsTestCore
4
+ module Resources
5
+ module Specs
6
+ describe SpecDir do
7
+
8
+ describe "GET /specs" do
9
+ attr_reader :dir, :html, :doc
10
+
11
+ before do
12
+ mock(connection).send_head(200, is_a(Hash))
13
+ mock(connection).send_data(/Content-Length:/)
14
+ mock(connection).send_data(anything) do |@html|
15
+ # do nothing
16
+ end
17
+
18
+ connection.receive_data("GET /specs HTTP/1.1\r\nHost: _\r\n\r\n")
19
+ @doc = Nokogiri::HTML(html)
20
+ end
21
+
22
+ it "returns script tags for each test javascript file" do
23
+ doc.at("script[@src='/specs/failing_spec.js']").should_not be_nil
24
+ doc.at("script[@src='/specs/foo/failing_spec.js']").should_not be_nil
25
+ doc.at("script[@src='/specs/foo/passing_spec.js']").should_not be_nil
26
+ end
27
+
28
+ it "returns the screw unit template" do
29
+ doc.at("link[@href='/core/screw.css']").should_not be_nil
30
+ doc.at("script[@src='/core/screw.builder.js']").should_not be_nil
31
+ doc.at("script[@src='/core/screw.events.js']").should_not be_nil
32
+ doc.at("script[@src='/core/screw.behaviors.js']").should_not be_nil
33
+ doc.at("body/#screw_unit_content").should_not be_nil
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,35 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../unit_spec_helper")
2
+
3
+ module JsTestCore
4
+ module Resources
5
+ module Specs
6
+ describe SpecFile do
7
+ describe "GET /specs/failing_spec" do
8
+ attr_reader :html, :doc
9
+ before do
10
+ mock(connection).send_head(200, is_a(Hash))
11
+ mock(connection).send_data(/Content-Length:/)
12
+ mock(connection).send_data(anything) do |@html|
13
+ # do nothing
14
+ end
15
+
16
+ connection.receive_data("GET /specs/failing_spec HTTP/1.1\r\nHost: _\r\n\r\n")
17
+ @doc = Nokogiri::HTML(html)
18
+ end
19
+
20
+ it "returns script tags for the test javascript file" do
21
+ doc.at("script[@src='/specs/failing_spec.js']").should_not be_nil
22
+ end
23
+
24
+ it "returns the screw unit template" do
25
+ doc.at("link[@href='/core/screw.css']").should_not be_nil
26
+ doc.at("script[@src='/core/screw.builder.js']").should_not be_nil
27
+ doc.at("script[@src='/core/screw.events.js']").should_not be_nil
28
+ doc.at("script[@src='/core/screw.behaviors.js']").should_not be_nil
29
+ doc.at("body/#screw_unit_content").should_not be_nil
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,119 @@
1
+ require "rubygems"
2
+ require "spec"
3
+ require "spec/autorun"
4
+ dir = File.dirname(__FILE__)
5
+
6
+ $LOAD_PATH.unshift "#{dir}/../../lib"
7
+ require "screw_unit"
8
+ require "nokogiri"
9
+ require "guid"
10
+
11
+ Spec::Runner.configure do |config|
12
+ config.mock_with :rr
13
+ end
14
+
15
+ module Spec
16
+ module Matchers
17
+ class Exist
18
+ def matches?(actual)
19
+ @actual = actual
20
+ !@actual.nil?
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ class Spec::ExampleGroup
27
+ class << self
28
+ def thin_logging
29
+ @thin_logging = true if @thin_logging.nil?
30
+ @thin_logging
31
+ end
32
+
33
+ attr_writer :thin_logging
34
+ end
35
+
36
+ attr_reader :spec_root_path, :implementation_root_path, :public_path, :server, :connection
37
+ before(:all) do
38
+ dir = File.dirname(__FILE__)
39
+ @spec_root_path = File.expand_path("#{dir}/../example_specs")
40
+ @implementation_root_path = File.expand_path("#{dir}/../example_public/javascripts")
41
+ @public_path = File.expand_path("#{dir}/../example_public")
42
+ end
43
+
44
+ before(:each) do
45
+ JsTestCore::Server.instance = JsTestCore::Server.new(spec_root_path, implementation_root_path, public_path)
46
+ stub(EventMachine).run do
47
+ raise "You need to mock calls to EventMachine.run or the process will hang"
48
+ end
49
+ stub(EventMachine).start_server do
50
+ raise "You need to mock calls to EventMachine.start_server or the process will hang"
51
+ end
52
+ stub(EventMachine).send_data do
53
+ raise "Calls to EventMachine.send_data must be mocked or stubbed"
54
+ end
55
+ @connection = Thin::JsTestCoreConnection.new(Guid.new)
56
+ stub(EventMachine).send_data {raise "EventMachine.send_data must be handled"}
57
+ stub(EventMachine).close_connection {raise "EventMachine.close_connection must be handled"}
58
+ @server = JsTestCore::Server.instance
59
+ Thin::Logging.silent = !self.class.thin_logging
60
+ Thin::Logging.debug = self.class.thin_logging
61
+ end
62
+
63
+ after(:each) do
64
+ Thin::Logging.silent = true
65
+ Thin::Logging.debug = false
66
+ end
67
+
68
+ def get(url, params={})
69
+ request(:get, url, params)
70
+ end
71
+
72
+ def post(url, params={})
73
+ request(:post, url, params)
74
+ end
75
+
76
+ def put(url, params={})
77
+ request(:put, url, params)
78
+ end
79
+
80
+ def delete(url, params={})
81
+ request(:delete, url, params)
82
+ end
83
+
84
+ def env_for(method, url, params)
85
+ Rack::MockRequest.env_for(url, params.merge({:method => method.to_s.upcase, 'js_test_core.connection' => connection}))
86
+ end
87
+
88
+ def create_request(method, url, params={})
89
+ env = env_for(method, url, params)
90
+ server.call(env)[2]
91
+ end
92
+ alias_method :request, :create_request
93
+
94
+ def core_path
95
+ JsTestCore::Server.core_path
96
+ end
97
+
98
+ def spec_file(relative_path)
99
+ absolute_path = spec_root_path + relative_path
100
+ JsTestCore::Resources::File.new(absolute_path, "/specs#{relative_path}")
101
+ end
102
+
103
+ def spec_dir(relative_path="")
104
+ absolute_path = spec_root_path + relative_path
105
+ JsTestCore::Resources::SpecDir.new(absolute_path, "/specs#{relative_path}")
106
+ end
107
+
108
+ def contain_spec_file_with_correct_paths(path_relative_to_spec_root)
109
+ expected_absolute_path = spec_root_path + path_relative_to_spec_root
110
+ expected_relative_path = "/specs" + path_relative_to_spec_root
111
+
112
+ ::Spec::Matchers::SimpleMatcher.new(expected_relative_path) do |globbed_files|
113
+ file = globbed_files.find do |file|
114
+ file.absolute_path == expected_absolute_path
115
+ end
116
+ file && file.relative_path == expected_relative_path
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,10 @@
1
+ class UnitSuite
2
+ def run
3
+ dir = File.dirname(__FILE__)
4
+ Dir["#{dir}/unit/**/*_spec.rb"].each do |file|
5
+ require file
6
+ end
7
+ end
8
+ end
9
+
10
+ UnitSuite.new.run