btakita-screw-unit-server 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. data/CHANGES +5 -0
  2. data/README.markdown +347 -0
  3. data/Rakefile +70 -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/TODO +2 -0
  10. data/core/example/models/cat.js +5 -0
  11. data/core/example/models/man.js +17 -0
  12. data/core/example/spec/matchers/have.js +8 -0
  13. data/core/example/spec/models/cat_spec.js +31 -0
  14. data/core/example/spec/models/man_spec.js +34 -0
  15. data/core/example/spec/spec_helper.js +5 -0
  16. data/core/example/spec/suite.html +25 -0
  17. data/core/lib/jquery-1.2.3.js +3408 -0
  18. data/core/lib/jquery.fn.js +29 -0
  19. data/core/lib/jquery.print.js +108 -0
  20. data/core/lib/screw.assets.js +36 -0
  21. data/core/lib/screw.behaviors.js +91 -0
  22. data/core/lib/screw.builder.js +80 -0
  23. data/core/lib/screw.css +90 -0
  24. data/core/lib/screw.events.js +38 -0
  25. data/core/lib/screw.matchers.js +65 -0
  26. data/core/lib/screw.server.js +21 -0
  27. data/core/spec/behaviors_spec.js +178 -0
  28. data/core/spec/matchers_spec.js +93 -0
  29. data/core/spec/print_spec.js +119 -0
  30. data/core/spec/spec_helper.js +0 -0
  31. data/core/spec/suite.html +18 -0
  32. data/init.rb +0 -0
  33. data/lib/screw_unit.rb +26 -0
  34. data/lib/screw_unit/resources.rb +2 -0
  35. data/lib/screw_unit/resources/spec.rb +37 -0
  36. data/spec/functional/functional_spec.rb +14 -0
  37. data/spec/functional/functional_spec_helper.rb +55 -0
  38. data/spec/functional_suite.rb +10 -0
  39. data/spec/spec_suite.rb +3 -0
  40. data/spec/unit/js_test_core/specs/spec_dir_spec.rb +43 -0
  41. data/spec/unit/js_test_core/specs/spec_file_spec.rb +43 -0
  42. data/spec/unit/unit_spec_helper.rb +120 -0
  43. data/spec/unit_suite.rb +10 -0
  44. data/vendor/js-test-core/CHANGES +9 -0
  45. data/vendor/js-test-core/README +12 -0
  46. data/vendor/js-test-core/Rakefile +72 -0
  47. data/vendor/js-test-core/lib/js_test_core.rb +30 -0
  48. data/vendor/js-test-core/lib/js_test_core/client.rb +50 -0
  49. data/vendor/js-test-core/lib/js_test_core/rack.rb +2 -0
  50. data/vendor/js-test-core/lib/js_test_core/rack/commonlogger.rb +5 -0
  51. data/vendor/js-test-core/lib/js_test_core/rails_server.rb +22 -0
  52. data/vendor/js-test-core/lib/js_test_core/resources.rb +11 -0
  53. data/vendor/js-test-core/lib/js_test_core/resources/dir.rb +52 -0
  54. data/vendor/js-test-core/lib/js_test_core/resources/file.rb +32 -0
  55. data/vendor/js-test-core/lib/js_test_core/resources/file_not_found.rb +15 -0
  56. data/vendor/js-test-core/lib/js_test_core/resources/runners.rb +15 -0
  57. data/vendor/js-test-core/lib/js_test_core/resources/runners/firefox_runner.rb +75 -0
  58. data/vendor/js-test-core/lib/js_test_core/resources/specs/spec_dir.rb +50 -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 +24 -0
  61. data/vendor/js-test-core/lib/js_test_core/resources/suite_finish.rb +19 -0
  62. data/vendor/js-test-core/lib/js_test_core/resources/web_root.rb +62 -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/server.rb +111 -0
  66. data/vendor/js-test-core/lib/js_test_core/thin.rb +3 -0
  67. data/vendor/js-test-core/lib/js_test_core/thin/backends/js_test_core_server.rb +9 -0
  68. data/vendor/js-test-core/lib/js_test_core/thin/js_test_core_connection.rb +42 -0
  69. data/vendor/js-test-core/spec/example_core/JsTestCore.css +0 -0
  70. data/vendor/js-test-core/spec/example_core/JsTestCore.js +0 -0
  71. data/vendor/js-test-core/spec/example_public/favicon.ico +0 -0
  72. data/vendor/js-test-core/spec/example_public/javascripts/foo.js +3 -0
  73. data/vendor/js-test-core/spec/example_public/robots.txt +0 -0
  74. data/vendor/js-test-core/spec/example_public/stylesheets/example.css +3 -0
  75. data/vendor/js-test-core/spec/example_specs/failing_spec.js +5 -0
  76. data/vendor/js-test-core/spec/example_specs/foo/failing_spec.js +6 -0
  77. data/vendor/js-test-core/spec/example_specs/foo/passing_spec.js +6 -0
  78. data/vendor/js-test-core/spec/spec_suite.rb +2 -0
  79. data/vendor/js-test-core/spec/specs/failing_spec.js +0 -0
  80. data/vendor/js-test-core/spec/unit/js_test_core/client_spec.rb +137 -0
  81. data/vendor/js-test-core/spec/unit/js_test_core/rails_server_spec.rb +45 -0
  82. data/vendor/js-test-core/spec/unit/js_test_core/resources/dir_spec.rb +42 -0
  83. data/vendor/js-test-core/spec/unit/js_test_core/resources/file_not_found_spec.rb +26 -0
  84. data/vendor/js-test-core/spec/unit/js_test_core/resources/file_spec.rb +88 -0
  85. data/vendor/js-test-core/spec/unit/js_test_core/resources/runner_spec.rb +24 -0
  86. data/vendor/js-test-core/spec/unit/js_test_core/resources/runners/firefox_runner_spec.rb +197 -0
  87. data/vendor/js-test-core/spec/unit/js_test_core/resources/specs/spec_dir_spec.rb +79 -0
  88. data/vendor/js-test-core/spec/unit/js_test_core/resources/specs/spec_file_spec.rb +42 -0
  89. data/vendor/js-test-core/spec/unit/js_test_core/resources/suite_finish_spec.rb +94 -0
  90. data/vendor/js-test-core/spec/unit/js_test_core/resources/suite_spec.rb +44 -0
  91. data/vendor/js-test-core/spec/unit/js_test_core/resources/web_root_spec.rb +103 -0
  92. data/vendor/js-test-core/spec/unit/js_test_core/server_spec.rb +131 -0
  93. data/vendor/js-test-core/spec/unit/thin/js_test_core_connection_spec.rb +92 -0
  94. data/vendor/js-test-core/spec/unit/unit_spec_helper.rb +125 -0
  95. data/vendor/js-test-core/spec/unit_suite.rb +10 -0
  96. metadata +186 -0
@@ -0,0 +1,42 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../unit_spec_helper")
2
+
3
+ module JsTestCore
4
+ module Resources
5
+ describe Dir do
6
+ attr_reader :dir, :absolute_path, :relative_path
7
+
8
+ describe "#locate" do
9
+ before do
10
+ @absolute_path = core_path
11
+ @relative_path = "/core"
12
+ @dir = Resources::Dir.new(absolute_path, relative_path)
13
+ end
14
+
15
+ describe "when passed a name of a real file" do
16
+ it "returns a Resources::File representing it" do
17
+ file = dir.locate("JsTestCore.css")
18
+ file.relative_path.should == "/core/JsTestCore.css"
19
+ file.absolute_path.should == "#{core_path}/JsTestCore.css"
20
+ end
21
+ end
22
+ end
23
+
24
+ describe "#glob" do
25
+ before do
26
+ @absolute_path = spec_root_path
27
+ @relative_path = "/specs"
28
+ @dir = Resources::Dir.new(absolute_path, relative_path)
29
+ end
30
+
31
+ it "returns an array of matching Files under this directory with the correct relative paths" do
32
+ globbed_files = dir.glob("/**/*_spec.js")
33
+
34
+ globbed_files.size.should == 3
35
+ globbed_files.should contain_spec_file_with_correct_paths("/failing_spec.js")
36
+ globbed_files.should contain_spec_file_with_correct_paths("/foo/failing_spec.js")
37
+ globbed_files.should contain_spec_file_with_correct_paths("/foo/passing_spec.js")
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,26 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../unit_spec_helper")
2
+
3
+ module JsTestCore
4
+ module Resources
5
+ describe FileNotFound do
6
+ attr_reader :request, :response, :file_not_found
7
+
8
+ before do
9
+ WebRoot.dispatch_specs
10
+ stub(EventMachine).send_data
11
+ stub(EventMachine).close_connection
12
+ @request = create_request('get', '/invalid')
13
+ @response = Rack::Response.new
14
+ @file_not_found = FileNotFound.new('invalid')
15
+ end
16
+
17
+ describe "#get" do
18
+ it "returns a 404 response code with an error message" do
19
+ file_not_found.get(request, response)
20
+ response.status.should == 404
21
+ response.body.should include("Path invalid not found. You may want to try the /specs directory.")
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,88 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../unit_spec_helper")
2
+
3
+ module JsTestCore
4
+ module Resources
5
+ describe File do
6
+ attr_reader :request, :file
7
+
8
+ before do
9
+ WebRoot.dispatch_specs
10
+ stub(EventMachine).send_data
11
+ stub(EventMachine).close_connection
12
+ @file = Resources::File.new(absolute_path, relative_path)
13
+ @request = create_request('get', relative_path)
14
+ end
15
+
16
+ def absolute_path
17
+ "#{spec_root_path}/failing_spec.js"
18
+ end
19
+
20
+ def relative_path
21
+ "/specs/failing_spec.js"
22
+ end
23
+
24
+ describe "#absolute_path" do
25
+ it "returns the absolute path passed into the initializer" do
26
+ file.absolute_path.should == absolute_path
27
+ end
28
+ end
29
+
30
+ describe "#relative_path" do
31
+ it "returns the relative path passed into the initializer" do
32
+ file.relative_path.should == relative_path
33
+ end
34
+ end
35
+
36
+ describe "#get" do
37
+ attr_reader :response
38
+ before do
39
+ @response = Rack::Response.new
40
+ end
41
+
42
+ it "returns the contents of the file" do
43
+ file.get(request, response)
44
+ response.body.should == ::File.read(absolute_path)
45
+ end
46
+
47
+ describe "when File has an extension" do
48
+ describe '.js' do
49
+ it "sets Content-Type to text/javascript" do
50
+ file.get(request,response)
51
+ response.content_type.should == "text/javascript"
52
+ end
53
+ end
54
+
55
+ describe '.css' do
56
+ it "sets Content-Type to text/css" do
57
+ file.get(request, response)
58
+ response.content_type.should == "text/css"
59
+ end
60
+
61
+ def absolute_path
62
+ "#{core_path}/JsTestCore.css"
63
+ end
64
+
65
+ def relative_path
66
+ "/core/JsTestCore.css"
67
+ end
68
+ end
69
+ end
70
+ end
71
+
72
+ describe "==" do
73
+ it "returns true when passed a file with the same absolute and relative paths" do
74
+ file.should == Resources::File.new(absolute_path, relative_path)
75
+ end
76
+
77
+ it "returns false when passed a file with a different absolute or relative path" do
78
+ file.should_not == Resources::File.new(absolute_path, "bogus")
79
+ file.should_not == Resources::File.new("bogus", relative_path)
80
+ end
81
+
82
+ it "when passed a Dir, returns false because File is not a Dir" do
83
+ file.should_not == Resources::Dir.new(absolute_path, relative_path)
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,24 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../unit_spec_helper")
2
+
3
+ module JsTestCore
4
+ module Resources
5
+ describe Runners do
6
+ attr_reader :runner
7
+ before do
8
+ @runner = Runners.new
9
+ end
10
+
11
+ describe "#locate" do
12
+ it "when passed 'firefox', returns a Firefox1Runner" do
13
+ runner.locate('firefox').is_a?(Runners::FirefoxRunner).should be_true
14
+ end
15
+
16
+ it "when not passed 'firefox', raises an error" do
17
+ lambda do
18
+ runner.locate('invalid')
19
+ end.should raise_error
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,197 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../../unit_spec_helper")
2
+
3
+ module JsTestCore
4
+ module Resources
5
+ describe Runners::FirefoxRunner do
6
+ attr_reader :runner, :request, :response, :driver, :suite_id
7
+
8
+ before do
9
+ Thread.current[:connection] = connection
10
+ @driver = "Selenium Driver"
11
+ @suite_id = 12345
12
+ stub(Selenium::SeleniumDriver).new('localhost', 4444, '*firefox', 'http://0.0.0.0:8080') do
13
+ driver
14
+ end
15
+ end
16
+
17
+ describe ".resume" do
18
+ describe "when there is a runner for the passed in suite_id" do
19
+ before do
20
+ @request = Rack::Request.new( Rack::MockRequest.env_for('/runners/firefox') )
21
+ @response = Rack::Response.new
22
+ @runner = Runners::FirefoxRunner.new
23
+ stub(Thread).start.yields
24
+
25
+ stub(driver).start
26
+ stub(driver).open
27
+ stub(driver).session_id {suite_id}
28
+ stub(driver).stop
29
+ stub(EventMachine).send_data
30
+ stub(EventMachine).close_connection
31
+
32
+ runner.post(request, response)
33
+ runner.suite_id.should == suite_id
34
+ end
35
+
36
+ it "removes and finalizes the instance that has the suite_id" do
37
+ mock.proxy(runner).finalize("Browser output")
38
+ Runners::FirefoxRunner.send(:instances)[suite_id].should == runner
39
+ Runners::FirefoxRunner.resume(suite_id, "Browser output")
40
+ Runners::FirefoxRunner.send(:instances)[suite_id].should be_nil
41
+ end
42
+ end
43
+
44
+ describe "when there is not a runner for the passed in suite_id" do
45
+ it "does nothing" do
46
+ lambda do
47
+ Runners::FirefoxRunner.resume("invalid", "nothing happens")
48
+ end.should_not raise_error
49
+ end
50
+ end
51
+ end
52
+
53
+ describe "#post" do
54
+ attr_reader :firefox_profile_path
55
+ before do
56
+ @request = Rack::Request.new( Rack::MockRequest.env_for('/runners/firefox') )
57
+ @response = Rack::Response.new
58
+ @runner = Runners::FirefoxRunner.new
59
+ stub(Thread).start.yields
60
+ end
61
+
62
+ it "keeps the connection open" do
63
+ stub(driver).start
64
+ stub(driver).open
65
+ stub(driver).session_id {suite_id}
66
+ dont_allow(EventMachine).send_data
67
+ dont_allow(EventMachine).close_connection
68
+ runner.post(request, response)
69
+
70
+ response.body.should be_empty
71
+ end
72
+
73
+ describe "when a selenium_host parameter is passed into the request" do
74
+ before do
75
+ request['selenium_host'] = "another-machine"
76
+ stub(driver).start
77
+ stub(driver).open
78
+ stub(driver).session_id {suite_id}
79
+ end
80
+
81
+ it "starts the Selenium Driver with the passed in selenium_host" do
82
+ mock(Selenium::SeleniumDriver).new('another-machine', 4444, '*firefox', 'http://0.0.0.0:8080') do
83
+ driver
84
+ end
85
+ runner.post(request, response)
86
+ end
87
+ end
88
+
89
+ describe "when a selenium_host parameter is not passed into the request" do
90
+ before do
91
+ request['selenium_host'].should be_nil
92
+ stub(driver).start
93
+ stub(driver).open
94
+ stub(driver).session_id {suite_id}
95
+ end
96
+
97
+ it "starts the Selenium Driver from localhost" do
98
+ mock(Selenium::SeleniumDriver).new('localhost', 4444, '*firefox', 'http://0.0.0.0:8080') do
99
+ driver
100
+ end
101
+ runner.post(request, response)
102
+ end
103
+ end
104
+
105
+ describe "when a selenium_port parameter is passed into the request" do
106
+ before do
107
+ request['selenium_port'] = "4000"
108
+ stub(driver).start
109
+ stub(driver).open
110
+ stub(driver).session_id {suite_id}
111
+ end
112
+
113
+ it "starts the Selenium Driver with the passed in selenium_port" do
114
+ mock(Selenium::SeleniumDriver).new('localhost', 4000, '*firefox', 'http://0.0.0.0:8080') do
115
+ driver
116
+ end
117
+ runner.post(request, response)
118
+ end
119
+ end
120
+
121
+ describe "when a selenium_port parameter is not passed into the request" do
122
+ before do
123
+ request['selenium_port'].should be_nil
124
+ stub(driver).start
125
+ stub(driver).open
126
+ stub(driver).session_id {suite_id}
127
+ end
128
+
129
+ it "starts the Selenium Driver from localhost" do
130
+ mock(Selenium::SeleniumDriver).new('localhost', 4444, '*firefox', 'http://0.0.0.0:8080') do
131
+ driver
132
+ end
133
+ runner.post(request, response)
134
+ end
135
+ end
136
+
137
+ describe "when a spec_url is passed into the request" do
138
+ before do
139
+ request['spec_url'] = "http://another-host:8080/specs/subdir"
140
+ end
141
+
142
+ it "runs Selenium with the passed in host and part to run the specified spec suite in Firefox" do
143
+ mock(Selenium::SeleniumDriver).new('localhost', 4444, '*firefox', 'http://another-host:8080') do
144
+ driver
145
+ end
146
+ mock(driver).start
147
+ mock(driver).open("http://another-host:8080/specs/subdir")
148
+ mock(driver).session_id {suite_id}
149
+
150
+ runner.post(request, response)
151
+ end
152
+ end
153
+
154
+ describe "when a spec_url is not passed into the request" do
155
+ before do
156
+ request['spec_url'].should be_nil
157
+ mock(Selenium::SeleniumDriver).new('localhost', 4444, '*firefox', 'http://0.0.0.0:8080') do
158
+ driver
159
+ end
160
+ end
161
+
162
+ it "uses Selenium to run the entire spec suite in Firefox" do
163
+ mock(driver).start
164
+ mock(driver).open("http://0.0.0.0:8080/specs")
165
+ mock(driver).session_id {suite_id}
166
+
167
+ runner.post(request, response)
168
+ end
169
+ end
170
+ end
171
+
172
+ describe "#finalize" do
173
+ before do
174
+ @request = Rack::Request.new( Rack::MockRequest.env_for('/runners/firefox') )
175
+ @response = Rack::Response.new
176
+ @runner = Runners::FirefoxRunner.new
177
+ stub(driver).start
178
+ stub(driver).open
179
+ stub(driver).session_id {suite_id}
180
+ runner.post(request, response)
181
+ end
182
+
183
+ it "kills the browser, sends the response body, and close the connection" do
184
+ mock(driver).stop
185
+ data = ""
186
+ stub(EventMachine).send_data do |signature, data, data_length|
187
+ data << data
188
+ end
189
+ mock(connection).close_connection_after_writing
190
+
191
+ runner.finalize("The text")
192
+ data.should include("The text")
193
+ end
194
+ end
195
+ end
196
+ end
197
+ end
@@ -0,0 +1,79 @@
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
+ attr_reader :dir, :absolute_path, :relative_path
8
+ before do
9
+ @absolute_path = spec_root_path
10
+ @relative_path = "/specs"
11
+ @dir = Resources::Specs::SpecDir.new(absolute_path, relative_path)
12
+ end
13
+
14
+ it "has an absolute path" do
15
+ dir.absolute_path.should == absolute_path
16
+ end
17
+
18
+ it "has a relative path" do
19
+ dir.relative_path.should == relative_path
20
+ end
21
+
22
+ describe "#locate when passed the name with an extension" do
23
+ it "when file exists, returns a Resources::File representing it" do
24
+ file = dir.locate("failing_spec.js")
25
+ file.relative_path.should == "/specs/failing_spec.js"
26
+ file.absolute_path.should == "#{spec_root_path}/failing_spec.js"
27
+ end
28
+
29
+ it "when file does not exist, raises error" do
30
+ lambda { dir.locate("nonexistent.js") }.should raise_error
31
+ end
32
+ end
33
+
34
+ describe "#locate when passed a name without an extension" do
35
+ it "when name corresponds to a subdirectory, returns a DirectoryRunner for the directory" do
36
+ subdir = dir.locate("foo")
37
+ subdir.should == spec_dir("/foo")
38
+ end
39
+
40
+ it "when name does not correspond to a .js file or directory, raises an error" do
41
+ lambda do
42
+ dir.locate("nonexistent")
43
+ end.should raise_error
44
+ end
45
+ end
46
+
47
+ describe "#get" do
48
+ attr_reader :request, :response
49
+ before do
50
+ @request = Rack::Request.new( Rack::MockRequest.env_for('/core') )
51
+ @response = Rack::Response.new
52
+ end
53
+
54
+ it "raises NotImplementedError" do
55
+ lambda do
56
+ dir.get(request, response)
57
+ end.should raise_error(NotImplementedError)
58
+ end
59
+
60
+ it "can be overridden from a Module without needing to redefine the #get method" do
61
+ spec_dir_class = Resources::Specs::SpecDir.clone
62
+ mod = Module.new do
63
+ def get(request, response)
64
+ end
65
+ end
66
+ spec_dir_class.class_eval do
67
+ include mod
68
+ end
69
+ @dir = spec_dir_class.new(absolute_path, relative_path)
70
+
71
+ lambda do
72
+ dir.get(request, response)
73
+ end.should_not raise_error
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end