screw-unit 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. data/CHANGES +11 -0
  2. data/README.markdown +354 -0
  3. data/Rakefile +40 -0
  4. data/bin/screw_unit +6 -0
  5. data/bin/screw_unit_server +10 -0
  6. data/core/EXAMPLE.html +68 -0
  7. data/core/LICENSE +22 -0
  8. data/core/README.markdown +307 -0
  9. data/core/example/models/cat.js +5 -0
  10. data/core/example/models/man.js +17 -0
  11. data/core/example/spec/matchers/have.js +8 -0
  12. data/core/example/spec/models/cat_spec.js +31 -0
  13. data/core/example/spec/models/man_spec.js +34 -0
  14. data/core/example/spec/spec_helper.js +5 -0
  15. data/core/example/spec/suite.html +25 -0
  16. data/core/lib/jquery-1.2.6.js +3549 -0
  17. data/core/lib/jquery.fn.js +29 -0
  18. data/core/lib/jquery.print.js +109 -0
  19. data/core/lib/screw.assets.js +36 -0
  20. data/core/lib/screw.behaviors.js +91 -0
  21. data/core/lib/screw.builder.js +80 -0
  22. data/core/lib/screw.css +90 -0
  23. data/core/lib/screw.events.js +44 -0
  24. data/core/lib/screw.matchers.js +145 -0
  25. data/core/lib/screw.server.js +21 -0
  26. data/core/spec/behaviors_spec.js +178 -0
  27. data/core/spec/matchers_spec.js +237 -0
  28. data/core/spec/print_spec.js +152 -0
  29. data/core/spec/spec_helper.js +0 -0
  30. data/core/spec/suite.html +18 -0
  31. data/init.rb +0 -0
  32. data/lib/screw_unit.rb +26 -0
  33. data/lib/screw_unit/resources.rb +2 -0
  34. data/lib/screw_unit/resources/spec.rb +38 -0
  35. data/spec/functional/functional_spec.rb +25 -0
  36. data/spec/functional/functional_spec_helper.rb +55 -0
  37. data/spec/functional_suite.rb +10 -0
  38. data/spec/spec_suite.rb +3 -0
  39. data/spec/unit/js_test_core/specs/spec_dir_spec.rb +39 -0
  40. data/spec/unit/js_test_core/specs/spec_file_spec.rb +35 -0
  41. data/spec/unit/unit_spec_helper.rb +120 -0
  42. data/spec/unit_suite.rb +10 -0
  43. data/vendor/js-test-core/CHANGES +15 -0
  44. data/vendor/js-test-core/README +12 -0
  45. data/vendor/js-test-core/Rakefile +72 -0
  46. data/vendor/js-test-core/lib/js_test_core.rb +38 -0
  47. data/vendor/js-test-core/lib/js_test_core/client.rb +114 -0
  48. data/vendor/js-test-core/lib/js_test_core/extensions.rb +3 -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/rack.rb +2 -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/rails_server.rb +22 -0
  53. data/vendor/js-test-core/lib/js_test_core/resources.rb +10 -0
  54. data/vendor/js-test-core/lib/js_test_core/resources/dir.rb +67 -0
  55. data/vendor/js-test-core/lib/js_test_core/resources/file.rb +49 -0
  56. data/vendor/js-test-core/lib/js_test_core/resources/file_not_found.rb +11 -0
  57. data/vendor/js-test-core/lib/js_test_core/resources/runner.rb +105 -0
  58. data/vendor/js-test-core/lib/js_test_core/resources/specs/spec_dir.rb +46 -0
  59. data/vendor/js-test-core/lib/js_test_core/resources/specs/spec_file.rb +17 -0
  60. data/vendor/js-test-core/lib/js_test_core/resources/suite.rb +40 -0
  61. data/vendor/js-test-core/lib/js_test_core/resources/suite_finish.rb +17 -0
  62. data/vendor/js-test-core/lib/js_test_core/resources/web_root.rb +63 -0
  63. data/vendor/js-test-core/lib/js_test_core/selenium.rb +2 -0
  64. data/vendor/js-test-core/lib/js_test_core/selenium/selenium_driver.rb +5 -0
  65. data/vendor/js-test-core/lib/js_test_core/selenium_server_configuration.rb +48 -0
  66. data/vendor/js-test-core/lib/js_test_core/server.rb +50 -0
  67. data/vendor/js-test-core/lib/js_test_core/thin.rb +3 -0
  68. data/vendor/js-test-core/lib/js_test_core/thin/backends/js_test_core_server.rb +9 -0
  69. data/vendor/js-test-core/lib/js_test_core/thin/js_test_core_connection.rb +8 -0
  70. data/vendor/js-test-core/spec/example_core/JsTestCore.css +0 -0
  71. data/vendor/js-test-core/spec/example_core/JsTestCore.js +0 -0
  72. data/vendor/js-test-core/spec/example_public/favicon.ico +0 -0
  73. data/vendor/js-test-core/spec/example_public/javascripts/foo.js +3 -0
  74. data/vendor/js-test-core/spec/example_public/javascripts/large_file.js +59 -0
  75. data/vendor/js-test-core/spec/example_public/javascripts/subdir/bar.js +1 -0
  76. data/vendor/js-test-core/spec/example_public/robots.txt +0 -0
  77. data/vendor/js-test-core/spec/example_public/stylesheets/example.css +3 -0
  78. data/vendor/js-test-core/spec/example_specs/failing_spec.js +5 -0
  79. data/vendor/js-test-core/spec/example_specs/foo/failing_spec.js +6 -0
  80. data/vendor/js-test-core/spec/example_specs/foo/passing_spec.js +6 -0
  81. data/vendor/js-test-core/spec/spec_suite.rb +2 -0
  82. data/vendor/js-test-core/spec/specs/failing_spec.js +0 -0
  83. data/vendor/js-test-core/spec/unit/js_test_core/client_spec.rb +166 -0
  84. data/vendor/js-test-core/spec/unit/js_test_core/rails_server_spec.rb +45 -0
  85. data/vendor/js-test-core/spec/unit/js_test_core/resources/dir_spec.rb +52 -0
  86. data/vendor/js-test-core/spec/unit/js_test_core/resources/file_not_found_spec.rb +16 -0
  87. data/vendor/js-test-core/spec/unit/js_test_core/resources/file_spec.rb +128 -0
  88. data/vendor/js-test-core/spec/unit/js_test_core/resources/runners/runner_spec.rb +283 -0
  89. data/vendor/js-test-core/spec/unit/js_test_core/resources/specs/spec_dir_spec.rb +105 -0
  90. data/vendor/js-test-core/spec/unit/js_test_core/resources/specs/spec_file_spec.rb +42 -0
  91. data/vendor/js-test-core/spec/unit/js_test_core/resources/suite_finish_spec.rb +82 -0
  92. data/vendor/js-test-core/spec/unit/js_test_core/resources/suite_spec.rb +86 -0
  93. data/vendor/js-test-core/spec/unit/js_test_core/resources/web_root_spec.rb +32 -0
  94. data/vendor/js-test-core/spec/unit/js_test_core/selenium_server_configuration_spec.rb +49 -0
  95. data/vendor/js-test-core/spec/unit/js_test_core/server_spec.rb +117 -0
  96. data/vendor/js-test-core/spec/unit/thin/js_test_core_connection_spec.rb +6 -0
  97. data/vendor/js-test-core/spec/unit/unit_spec_helper.rb +134 -0
  98. data/vendor/js-test-core/spec/unit_suite.rb +10 -0
  99. data/vendor/js-test-core/vendor/thin-rest/CHANGES +2 -0
  100. data/vendor/js-test-core/vendor/thin-rest/README +0 -0
  101. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest.rb +9 -0
  102. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/connection.rb +116 -0
  103. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/extensions.rb +3 -0
  104. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/extensions/object.rb +21 -0
  105. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/resource.rb +104 -0
  106. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/resource_invalid.rb +4 -0
  107. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/routing_error.rb +5 -0
  108. data/vendor/js-test-core/vendor/thin-rest/spec/spec_suite.rb +5 -0
  109. data/vendor/js-test-core/vendor/thin-rest/spec/thin_rest/connection_spec.rb +207 -0
  110. data/vendor/js-test-core/vendor/thin-rest/spec/thin_rest/resource_spec.rb +127 -0
  111. data/vendor/js-test-core/vendor/thin-rest/spec/thin_rest_spec_helper.rb +124 -0
  112. metadata +210 -0
@@ -0,0 +1,152 @@
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(equal, 'function ()');
52
+ expect($.print(function foo() {})).to(equal, 'function foo()');
53
+ expect($.print(function foo(bar) {})).to(equal, 'function 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 an element', function() {
70
+ it("returns the string representation of the element", function() {
71
+ expect($.print($('<div>').get(0))).to(equal, '<div>');
72
+ expect($.print($('<div foo="bar">').get(0))).to(equal, '<div>');
73
+ expect($.print($('<div class="foo" id="bar">').get(0))).to(equal, '<div class="foo" id="bar">');
74
+ });
75
+
76
+ describe('when the element is an img', function() {
77
+ it('prints out the img src attribute', function() {
78
+ expect($.print($('<img src="test.png">'))).to(match, /<img src=".+?test.png">/);
79
+ })
80
+ });
81
+ });
82
+
83
+ describe('when given an array', function() {
84
+ it("returns the printed elements, comma separated, encircled by square brackets", function() {
85
+ expect($.print([])).to(equal, '[]');
86
+ expect($.print([1])).to(equal, '[ 1 ]');
87
+ expect($.print([1, 2, 3])).to(equal, '[ 1, 2, 3 ]');
88
+ });
89
+
90
+ describe('when the array is longer than the [max_array] option', function() {
91
+ it("returns the printed array, truncated", function() {
92
+ expect($.print([1, 2, 3, 4], { max_array: 2 })).to(equal, '[ 1, 2, 2 more... ]');
93
+ });
94
+ });
95
+
96
+ describe('when the array has arrays as its elements', function() {
97
+ it("returns the recursively printed array", function() {
98
+ expect($.print([[]])).to(equal, '[ [] ]');
99
+ expect($.print([ [1, 2, 3], 4 ])).to(equal, '[ [ 1, 2, 3 ], 4 ]');
100
+ });
101
+ });
102
+
103
+ describe('when the array has objects as its elements', function() {
104
+ it("returns recursively printed array", function() {
105
+ expect($.print([{}])).to(equal, '[ {} ]');
106
+ expect($.print([ { foo: 'bar' }, 'baz' ])).to(equal, '[ { foo: "bar" }, "baz" ]');
107
+ });
108
+ });
109
+ });
110
+
111
+ describe('when given arguments', function() {
112
+ it("returns the printed array of elements ", function() {
113
+ var args = null;
114
+ (function(){ args = arguments })(1,2,3);
115
+ expect($.print(args)).to(equal, '[ 1, 2, 3 ]');
116
+ });
117
+ });
118
+
119
+ describe('when given a jQuery', function() {
120
+ it("returns the printed array of elements engirthed in '$()'", function() {
121
+ expect($.print($('<div>'))).to(equal, '$([ <div> ])');
122
+ });
123
+ });
124
+
125
+ describe('when given a NodeList', function() {
126
+ it("returns the printed array of elements in the list", function() {
127
+ expect($.print(document.getElementsByTagName('body'))).to(equal, '[ <body> ]');
128
+ });
129
+ });
130
+
131
+ describe('when given an object', function() {
132
+ it("returns the keys and values of the object, enraptured with curly braces", function() {
133
+ expect($.print({})).to(equal, '{}');
134
+ expect($.print({ foo: 1, bar: 2 })).to(equal, '{ foo: 1, bar: 2 }');
135
+ });
136
+
137
+ describe('when the values of the object are non-primitive', function() {
138
+ it("recursively prints the keys and values", function() {
139
+ expect($.print({ foo: [1, 2] })).to(equal, '{ foo: [ 1, 2 ] }');
140
+ });
141
+
142
+ describe('when the object has circular references', function() {
143
+ it("returns elipses for circularities", function() {
144
+ var circular = {};
145
+ circular[0] = circular;
146
+ expect($.print(circular)).to(equal, '{ 0: ... }');
147
+ });
148
+ });
149
+ });
150
+ });
151
+ });
152
+ });
File without changes
@@ -0,0 +1,18 @@
1
+ <html>
2
+ <head>
3
+ <script src="../lib/jquery-1.2.6.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
+
15
+ <link rel="stylesheet" href="../lib/screw.css">
16
+ </head>
17
+ <body></body>
18
+ </html>
data/init.rb ADDED
File without changes
@@ -0,0 +1,26 @@
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/resources"
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
+
20
+ class JsTestCore::Resources::Specs::SpecFile
21
+ include ScrewUnit::Resources::Spec
22
+ end
23
+
24
+ class JsTestCore::Resources::Specs::SpecDir
25
+ include ScrewUnit::Resources::Spec
26
+ end
@@ -0,0 +1,2 @@
1
+ dir = File.dirname(__FILE__)
2
+ require "#{dir}/resources/spec"
@@ -0,0 +1,38 @@
1
+ module ScrewUnit
2
+ module Resources
3
+ module Spec
4
+ def get
5
+ html = <<-HTML
6
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
7
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
8
+ <head>
9
+ <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
10
+ <title>ScrewUnit results</title>
11
+ <script src="/core/jquery-1.2.6.js"></script>
12
+ <script src="/core/jquery.fn.js"></script>
13
+ <script src="/core/jquery.print.js"></script>
14
+ <script src="/core/screw.builder.js"></script>
15
+ <script src="/core/screw.matchers.js"></script>
16
+ <script src="/core/screw.events.js"></script>
17
+ <script src="/core/screw.behaviors.js"></script>
18
+ <script src="/core/screw.assets.js"></script>
19
+ <script src="/core/screw.server.js"></script>
20
+ <link rel="stylesheet" href="/core/screw.css">
21
+ HTML
22
+ spec_files.each do |file|
23
+ html << %{<script type="text/javascript" src="#{file.relative_path}"></script>\n}
24
+ end
25
+
26
+ html << <<-HTML
27
+ </head>
28
+ <body>
29
+ <div id="screw_unit_content"></div>
30
+ </body>
31
+ </html>
32
+ HTML
33
+ connection.send_head
34
+ connection.send_body(html.gsub(/^ /, ""))
35
+ end
36
+ end
37
+ end
38
+ end
@@ -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("expected true to equal false")
24
+ end
25
+ end
@@ -0,0 +1,55 @@
1
+ require "rubygems"
2
+ require "spec"
3
+
4
+ dir = File.dirname(__FILE__)
5
+ $LOAD_PATH.unshift "#{dir}/../../lib"
6
+ require "screw_unit"
7
+ require "hpricot"
8
+ require "lsof"
9
+
10
+ Spec::Runner.configure do |config|
11
+ config.mock_with :rr
12
+ end
13
+
14
+ Thin::Logging.silent = false
15
+ Thin::Logging.debug = true
16
+
17
+ module WaitFor
18
+ extend self
19
+ def wait_for(time=5)
20
+ Timeout.timeout(time) do
21
+ loop do
22
+ value = yield
23
+ return value if value
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ module Spec::Example::ExampleMethods
30
+ include WaitFor
31
+ attr_reader :spec_root_path, :implementation_root_path, :public_path
32
+ before(:all) do
33
+ Lsof.kill(8080)
34
+ wait_for do
35
+ !Lsof.running?(8080)
36
+ end
37
+ dir = File.dirname(__FILE__)
38
+ @spec_root_path = "#{dir}/../example_specs"
39
+ @public_path = "#{dir}/../example_public"
40
+ @implementation_root_path = "#{public_path}/javascripts"
41
+ unless $screw_unit_server_started
42
+ Thread.start do
43
+ ScrewUnit::Server.run(spec_root_path, implementation_root_path, public_path)
44
+ end
45
+ $screw_unit_server_started = true
46
+ end
47
+ wait_for do
48
+ Lsof.running?(8080)
49
+ end
50
+ end
51
+
52
+ def root_url
53
+ "http://#{ScrewUnit::DEFAULT_HOST}:#{ScrewUnit::DEFAULT_PORT}"
54
+ end
55
+ 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
13
+ mock(connection).send_body(anything) do |@html|
14
+ # do nothing
15
+ end
16
+
17
+ connection.receive_data("GET /specs HTTP/1.1\r\nHost: _\r\n\r\n")
18
+ @doc = Hpricot(html)
19
+ end
20
+
21
+ it "returns script tags for each test javascript file" do
22
+ doc.at("script[@src='/specs/failing_spec.js']").should exist
23
+ doc.at("script[@src='/specs/foo/failing_spec.js']").should exist
24
+ doc.at("script[@src='/specs/foo/passing_spec.js']").should exist
25
+ end
26
+
27
+ it "returns the screw unit template" do
28
+ doc.at("link[@href='/core/screw.css']").should exist
29
+ doc.at("script[@src='/core/screw.builder.js']").should exist
30
+ doc.at("script[@src='/core/screw.events.js']").should exist
31
+ doc.at("script[@src='/core/screw.behaviors.js']").should exist
32
+ doc.at("script[@src='/core/screw.assets.js']").should exist
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
11
+ mock(connection).send_body(anything) do |@html|
12
+ # do nothing
13
+ end
14
+
15
+ connection.receive_data("GET /specs/failing_spec HTTP/1.1\r\nHost: _\r\n\r\n")
16
+ @doc = Hpricot(html)
17
+ end
18
+
19
+ it "returns script tags for the test javascript file" do
20
+ doc.at("script[@src='/specs/failing_spec.js']").should exist
21
+ end
22
+
23
+ it "returns the screw unit template" do
24
+ doc.at("link[@href='/core/screw.css']").should exist
25
+ doc.at("script[@src='/core/screw.builder.js']").should exist
26
+ doc.at("script[@src='/core/screw.events.js']").should exist
27
+ doc.at("script[@src='/core/screw.behaviors.js']").should exist
28
+ doc.at("script[@src='/core/screw.assets.js']").should exist
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,120 @@
1
+ require "rubygems"
2
+ require "spec"
3
+ dir = File.dirname(__FILE__)
4
+
5
+ $LOAD_PATH.unshift "#{dir}/../../lib"
6
+ require "screw_unit"
7
+ require "hpricot"
8
+ require "guid"
9
+
10
+ Spec::Runner.configure do |config|
11
+ config.mock_with :rr
12
+ end
13
+
14
+ module Spec
15
+ module Matchers
16
+ class Exist
17
+ def matches?(actual)
18
+ @actual = actual
19
+ !@actual.nil?
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ class Spec::Example::ExampleGroup
26
+ class << self
27
+ def thin_logging
28
+ @thin_logging = true if @thin_logging.nil?
29
+ @thin_logging
30
+ end
31
+
32
+ attr_writer :thin_logging
33
+ end
34
+ end
35
+
36
+ module Spec::Example::ExampleMethods
37
+ attr_reader :spec_root_path, :implementation_root_path, :public_path, :server, :connection
38
+ before(:all) do
39
+ dir = File.dirname(__FILE__)
40
+ @spec_root_path = File.expand_path("#{dir}/../example_specs")
41
+ @implementation_root_path = File.expand_path("#{dir}/../example_public/javascripts")
42
+ @public_path = File.expand_path("#{dir}/../example_public")
43
+ end
44
+
45
+ before(:each) do
46
+ JsTestCore::Server.instance = JsTestCore::Server.new(spec_root_path, implementation_root_path, public_path)
47
+ stub(EventMachine).run do
48
+ raise "You need to mock calls to EventMachine.run or the process will hang"
49
+ end
50
+ stub(EventMachine).start_server do
51
+ raise "You need to mock calls to EventMachine.start_server or the process will hang"
52
+ end
53
+ stub(EventMachine).send_data do
54
+ raise "Calls to EventMachine.send_data must be mocked or stubbed"
55
+ end
56
+ @connection = Thin::JsTestCoreConnection.new(Guid.new)
57
+ stub(EventMachine).send_data {raise "EventMachine.send_data must be handled"}
58
+ stub(EventMachine).close_connection {raise "EventMachine.close_connection must be handled"}
59
+ @server = JsTestCore::Server.instance
60
+ Thin::Logging.silent = !self.class.thin_logging
61
+ Thin::Logging.debug = self.class.thin_logging
62
+ end
63
+
64
+ after(:each) do
65
+ Thin::Logging.silent = true
66
+ Thin::Logging.debug = false
67
+ end
68
+
69
+ def get(url, params={})
70
+ request(:get, url, params)
71
+ end
72
+
73
+ def post(url, params={})
74
+ request(:post, url, params)
75
+ end
76
+
77
+ def put(url, params={})
78
+ request(:put, url, params)
79
+ end
80
+
81
+ def delete(url, params={})
82
+ request(:delete, url, params)
83
+ end
84
+
85
+ def env_for(method, url, params)
86
+ Rack::MockRequest.env_for(url, params.merge({:method => method.to_s.upcase, 'js_test_core.connection' => connection}))
87
+ end
88
+
89
+ def create_request(method, url, params={})
90
+ env = env_for(method, url, params)
91
+ server.call(env)[2]
92
+ end
93
+ alias_method :request, :create_request
94
+
95
+ def core_path
96
+ JsTestCore::Server.core_path
97
+ end
98
+
99
+ def spec_file(relative_path)
100
+ absolute_path = spec_root_path + relative_path
101
+ JsTestCore::Resources::File.new(absolute_path, "/specs#{relative_path}")
102
+ end
103
+
104
+ def spec_dir(relative_path="")
105
+ absolute_path = spec_root_path + relative_path
106
+ JsTestCore::Resources::SpecDir.new(absolute_path, "/specs#{relative_path}")
107
+ end
108
+
109
+ def contain_spec_file_with_correct_paths(path_relative_to_spec_root)
110
+ expected_absolute_path = spec_root_path + path_relative_to_spec_root
111
+ expected_relative_path = "/specs" + path_relative_to_spec_root
112
+
113
+ ::Spec::Matchers::SimpleMatcher.new(expected_relative_path) do |globbed_files|
114
+ file = globbed_files.find do |file|
115
+ file.absolute_path == expected_absolute_path
116
+ end
117
+ file && file.relative_path == expected_relative_path
118
+ end
119
+ end
120
+ end