btakita-screw-unit-server 0.3.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. data/CHANGES +44 -1
  2. data/README.markdown +17 -5
  3. data/Rakefile +28 -55
  4. data/VERSION.yml +5 -0
  5. data/bin/screw_unit_server +8 -4
  6. data/core/CHANGES +10 -0
  7. data/core/EXAMPLE.html +4 -4
  8. data/core/README.markdown +7 -7
  9. data/core/example/models/man.js +2 -2
  10. data/core/example/spec/suite.html +1 -1
  11. data/core/lib/jquery-1.3.2.js +4376 -0
  12. data/core/lib/jquery.fn.js +2 -1
  13. data/core/lib/jquery.print.js +13 -12
  14. data/core/lib/screw.behaviors.js +11 -9
  15. data/core/lib/screw.builder.js +26 -11
  16. data/core/lib/screw.css +2 -2
  17. data/core/lib/screw.events.js +11 -4
  18. data/core/lib/screw.matchers.js +192 -13
  19. data/core/spec/behaviors_spec.js +11 -1
  20. data/core/spec/matchers_spec.js +288 -9
  21. data/core/spec/print_spec.js +47 -8
  22. data/core/spec/suite.html +2 -1
  23. data/core/spec/with_screw_context_spec.js +9 -0
  24. data/lib/screw_unit.rb +12 -17
  25. data/spec/functional/functional_spec.rb +15 -4
  26. data/spec/functional/functional_spec_helper.rb +22 -35
  27. data/spec/functional/functional_spec_server_starter.rb +68 -0
  28. data/spec/spec_suite.rb +0 -1
  29. data/standalone.ru +3 -0
  30. data/vendor/js-test-core/CHANGES +22 -0
  31. data/vendor/js-test-core/README +4 -10
  32. data/vendor/js-test-core/Rakefile +2 -1
  33. data/vendor/js-test-core/{spec/example_core/JsTestCore.css → bin/js-test-client} +0 -0
  34. data/vendor/js-test-core/bin/js-test-server +6 -0
  35. data/vendor/js-test-core/lib/js_test_core.rb +27 -19
  36. data/vendor/js-test-core/lib/js_test_core/app.rb +11 -0
  37. data/vendor/js-test-core/lib/js_test_core/client.rb +125 -36
  38. data/vendor/js-test-core/lib/js_test_core/configuration.rb +65 -0
  39. data/vendor/js-test-core/lib/js_test_core/representations.rb +13 -0
  40. data/vendor/js-test-core/lib/js_test_core/representations/dir.html.rb +25 -0
  41. data/vendor/js-test-core/lib/js_test_core/representations/frameworks.rb +3 -0
  42. data/vendor/js-test-core/lib/js_test_core/representations/not_found.html.rb +16 -0
  43. data/vendor/js-test-core/lib/js_test_core/representations/page.html.rb +41 -0
  44. data/vendor/js-test-core/lib/js_test_core/representations/suite.html.rb +57 -0
  45. data/vendor/js-test-core/lib/js_test_core/representations/suites.rb +3 -0
  46. data/vendor/js-test-core/lib/js_test_core/representations/suites/screw_unit.html.rb +81 -0
  47. data/vendor/js-test-core/lib/js_test_core/resources.rb +12 -8
  48. data/vendor/js-test-core/lib/js_test_core/resources/core_file.rb +19 -0
  49. data/vendor/js-test-core/lib/js_test_core/resources/file.rb +43 -13
  50. data/vendor/js-test-core/lib/js_test_core/resources/implementations_deprecation.rb +12 -0
  51. data/vendor/js-test-core/lib/js_test_core/resources/not_found.rb +28 -0
  52. data/vendor/js-test-core/lib/js_test_core/resources/resource.rb +16 -0
  53. data/vendor/js-test-core/lib/js_test_core/resources/spec_file.rb +51 -0
  54. data/vendor/js-test-core/lib/js_test_core/resources/web_root.rb +7 -54
  55. data/vendor/js-test-core/lib/js_test_core/server.rb +65 -92
  56. data/vendor/js-test-core/public/js_test_server.js +541 -0
  57. data/vendor/js-test-core/spec/{example_core/JsTestCore.js → example_framework/JsTestCore.css} +0 -0
  58. data/vendor/js-test-core/spec/{example_public/favicon.ico → example_framework/JsTestCore.js} +0 -0
  59. data/vendor/js-test-core/spec/{example_public/robots.txt → example_framework/subdir/SubDirFile.js} +0 -0
  60. data/vendor/js-test-core/spec/example_root/favicon.ico +0 -0
  61. data/vendor/js-test-core/spec/{example_public → example_root}/javascripts/foo.js +1 -1
  62. data/vendor/js-test-core/spec/example_root/javascripts/large_file.js +59 -0
  63. data/vendor/js-test-core/spec/example_root/javascripts/subdir/bar.js +1 -0
  64. data/vendor/js-test-core/spec/example_root/robots.txt +0 -0
  65. data/vendor/js-test-core/spec/{example_public → example_root}/stylesheets/example.css +0 -0
  66. data/vendor/js-test-core/spec/example_spec/custom_dir_and_suite/passing_spec.js +8 -0
  67. data/vendor/js-test-core/spec/example_spec/custom_suite.html +8 -0
  68. data/vendor/js-test-core/spec/example_spec/failing_spec.js +7 -0
  69. data/vendor/js-test-core/spec/example_spec/foo/failing_spec.js +8 -0
  70. data/vendor/js-test-core/spec/example_spec/foo/passing_spec.js +8 -0
  71. data/vendor/js-test-core/spec/example_spec/passing_spec.js +8 -0
  72. data/vendor/js-test-core/spec/functional/functional_spec.rb +25 -0
  73. data/vendor/js-test-core/spec/functional/functional_spec_helper.rb +42 -0
  74. data/vendor/js-test-core/spec/functional/functional_spec_server_starter.rb +77 -0
  75. data/vendor/js-test-core/spec/functional_suite.rb +10 -0
  76. data/vendor/js-test-core/spec/spec_helpers/be_http.rb +32 -0
  77. data/vendor/js-test-core/spec/spec_helpers/example_group.rb +36 -0
  78. data/vendor/js-test-core/spec/spec_helpers/fake_selenium_driver.rb +16 -0
  79. data/vendor/js-test-core/spec/spec_helpers/show_test_exceptions.rb +22 -0
  80. data/vendor/js-test-core/spec/spec_suite.rb +2 -1
  81. data/vendor/js-test-core/spec/unit/js_test_core/client_spec.rb +153 -94
  82. data/vendor/js-test-core/spec/unit/js_test_core/configuration_spec.rb +50 -0
  83. data/vendor/js-test-core/spec/unit/js_test_core/resources/core_file_spec.rb +60 -0
  84. data/vendor/js-test-core/spec/unit/js_test_core/resources/file_spec.rb +61 -68
  85. data/vendor/js-test-core/spec/unit/js_test_core/resources/implementations_deprecation_spec.rb +18 -0
  86. data/vendor/js-test-core/spec/unit/js_test_core/resources/not_found_spec.rb +51 -0
  87. data/vendor/js-test-core/spec/unit/js_test_core/resources/spec_file_spec.rb +149 -0
  88. data/vendor/js-test-core/spec/unit/js_test_core/resources/web_root_spec.rb +14 -89
  89. data/vendor/js-test-core/spec/unit/js_test_core/server_spec.rb +41 -106
  90. data/vendor/js-test-core/spec/unit/unit_spec_helper.rb +19 -114
  91. data/vendor/js-test-core/standalone.ru +1 -0
  92. data/vendor/js-test-core/vendor/lucky-luciano/README.markdown +77 -0
  93. data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano.rb +5 -0
  94. data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/resource.rb +142 -0
  95. data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/resource/path.rb +24 -0
  96. data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/rspec.rb +4 -0
  97. data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/rspec/be_http.rb +32 -0
  98. data/vendor/js-test-core/vendor/lucky-luciano/spec/lucky_luciano/resource_spec.rb +276 -0
  99. data/vendor/js-test-core/vendor/lucky-luciano/spec/spec_helper.rb +48 -0
  100. data/vendor/js-test-core/vendor/lucky-luciano/spec/spec_suite.rb +4 -0
  101. data/vendor/js-test-core/vendor/lucky-luciano/syntax_ideas.txt +34 -0
  102. metadata +145 -130
  103. data/core/TODO +0 -2
  104. data/core/lib/jquery-1.2.3.js +0 -3408
  105. data/core/lib/screw.assets.js +0 -36
  106. data/core/lib/screw.server.js +0 -21
  107. data/lib/screw_unit/resources.rb +0 -2
  108. data/lib/screw_unit/resources/spec.rb +0 -37
  109. data/spec/unit/js_test_core/specs/spec_dir_spec.rb +0 -43
  110. data/spec/unit/js_test_core/specs/spec_file_spec.rb +0 -43
  111. data/spec/unit/unit_spec_helper.rb +0 -120
  112. data/spec/unit_suite.rb +0 -10
  113. data/vendor/js-test-core/lib/js_test_core/rack.rb +0 -2
  114. data/vendor/js-test-core/lib/js_test_core/rack/commonlogger.rb +0 -5
  115. data/vendor/js-test-core/lib/js_test_core/rails_server.rb +0 -22
  116. data/vendor/js-test-core/lib/js_test_core/resources/dir.rb +0 -52
  117. data/vendor/js-test-core/lib/js_test_core/resources/file_not_found.rb +0 -15
  118. data/vendor/js-test-core/lib/js_test_core/resources/runners.rb +0 -15
  119. data/vendor/js-test-core/lib/js_test_core/resources/runners/firefox_runner.rb +0 -75
  120. data/vendor/js-test-core/lib/js_test_core/resources/specs/spec_dir.rb +0 -50
  121. data/vendor/js-test-core/lib/js_test_core/resources/specs/spec_file.rb +0 -17
  122. data/vendor/js-test-core/lib/js_test_core/resources/suite.rb +0 -24
  123. data/vendor/js-test-core/lib/js_test_core/resources/suite_finish.rb +0 -19
  124. data/vendor/js-test-core/lib/js_test_core/selenium.rb +0 -2
  125. data/vendor/js-test-core/lib/js_test_core/selenium/selenium_driver.rb +0 -5
  126. data/vendor/js-test-core/lib/js_test_core/thin.rb +0 -3
  127. data/vendor/js-test-core/lib/js_test_core/thin/backends/js_test_core_server.rb +0 -9
  128. data/vendor/js-test-core/lib/js_test_core/thin/js_test_core_connection.rb +0 -42
  129. data/vendor/js-test-core/spec/example_specs/failing_spec.js +0 -5
  130. data/vendor/js-test-core/spec/example_specs/foo/failing_spec.js +0 -6
  131. data/vendor/js-test-core/spec/example_specs/foo/passing_spec.js +0 -6
  132. data/vendor/js-test-core/spec/unit/js_test_core/rails_server_spec.rb +0 -45
  133. data/vendor/js-test-core/spec/unit/js_test_core/resources/dir_spec.rb +0 -42
  134. data/vendor/js-test-core/spec/unit/js_test_core/resources/file_not_found_spec.rb +0 -26
  135. data/vendor/js-test-core/spec/unit/js_test_core/resources/runner_spec.rb +0 -24
  136. data/vendor/js-test-core/spec/unit/js_test_core/resources/runners/firefox_runner_spec.rb +0 -197
  137. data/vendor/js-test-core/spec/unit/js_test_core/resources/specs/spec_dir_spec.rb +0 -79
  138. data/vendor/js-test-core/spec/unit/js_test_core/resources/specs/spec_file_spec.rb +0 -42
  139. data/vendor/js-test-core/spec/unit/js_test_core/resources/suite_finish_spec.rb +0 -94
  140. data/vendor/js-test-core/spec/unit/js_test_core/resources/suite_spec.rb +0 -44
  141. data/vendor/js-test-core/spec/unit/thin/js_test_core_connection_spec.rb +0 -92
File without changes
@@ -1,3 +1,3 @@
1
1
  var Foo = {
2
2
  value: true
3
- }
3
+ };
@@ -0,0 +1,59 @@
1
+ //////////////////////////////////////////////
2
+ //////////////////////////////////////////////
3
+ //////////////////////////////////////////////
4
+ //////////////////////////////////////////////
5
+ //////////////////////////////////////////////
6
+ //////////////////////////////////////////////
7
+ //////////////////////////////////////////////
8
+ //////////////////////////////////////////////
9
+ //////////////////////////////////////////////
10
+ //////////////////////////////////////////////
11
+ //////////////////////////////////////////////
12
+ //////////////////////////////////////////////
13
+ //////////////////////////////////////////////
14
+ //////////////////////////////////////////////
15
+ //////////////////////////////////////////////
16
+ //////////////////////////////////////////////
17
+ //////////////////////////////////////////////
18
+ //////////////////////////////////////////////
19
+ //////////////////////////////////////////////
20
+ //////////////////////////////////////////////
21
+ //////////////////////////////////////////////
22
+ //////////////////////////////////////////////
23
+ //////////////////////////////////////////////
24
+ //////////////////////////////////////////////
25
+ //////////////////////////////////////////////
26
+ //////////////////////////////////////////////
27
+ //////////////////////////////////////////////
28
+ //////////////////////////////////////////////
29
+ //////////////////////////////////////////////
30
+ //////////////////////////////////////////////
31
+ //////////////////////////////////////////////
32
+ //////////////////////////////////////////////
33
+ //////////////////////////////////////////////
34
+ //////////////////////////////////////////////
35
+ //////////////////////////////////////////////
36
+ //////////////////////////////////////////////
37
+ //////////////////////////////////////////////
38
+ //////////////////////////////////////////////
39
+ //////////////////////////////////////////////
40
+ //////////////////////////////////////////////
41
+ //////////////////////////////////////////////
42
+ //////////////////////////////////////////////
43
+ //////////////////////////////////////////////
44
+ //////////////////////////////////////////////
45
+ //////////////////////////////////////////////
46
+ //////////////////////////////////////////////
47
+ //////////////////////////////////////////////
48
+ //////////////////////////////////////////////
49
+ //////////////////////////////////////////////
50
+ //////////////////////////////////////////////
51
+ //////////////////////////////////////////////
52
+ //////////////////////////////////////////////
53
+ //////////////////////////////////////////////
54
+ //////////////////////////////////////////////
55
+ //////////////////////////////////////////////
56
+ //////////////////////////////////////////////
57
+ //////////////////////////////////////////////
58
+ //////////////////////////////////////////////
59
+ //////////////////////////////////////////////
File without changes
@@ -0,0 +1,8 @@
1
+ require("/javascripts/foo");
2
+ Screw.Unit(function() {
3
+ describe("A passing spec", function() {
4
+ it("passes", function() {
5
+ expect(Foo.value).to(equal, true);
6
+ });
7
+ });
8
+ });
@@ -0,0 +1,8 @@
1
+ <html>
2
+ <head>
3
+ <title>Custom Suite</title>
4
+ </head>
5
+ <body>
6
+
7
+ </body>
8
+ </html>
@@ -0,0 +1,7 @@
1
+ Screw.Unit(function() {
2
+ describe("A failing spec", function() {
3
+ it("fails", function() {
4
+ expect(true).to(equal, false);
5
+ });
6
+ });
7
+ });
@@ -0,0 +1,8 @@
1
+ require("/javascripts/foo");
2
+ Screw.Unit(function() {
3
+ describe("A failing spec in foo", function() {
4
+ it("fails", function() {
5
+ expect(Foo.value).to(equal, false);
6
+ });
7
+ });
8
+ });
@@ -0,0 +1,8 @@
1
+ require("/javascripts/foo");
2
+ Screw.Unit(function() {
3
+ describe("A passing spec in foo", function() {
4
+ it("passes", function() {
5
+ expect(Foo.value).to(equal, true);
6
+ });
7
+ });
8
+ });
@@ -0,0 +1,8 @@
1
+ require("/javascripts/foo");
2
+ Screw.Unit(function() {
3
+ describe("A passing spec", function() {
4
+ it("passes", function() {
5
+ expect(Foo.value).to(equal, true);
6
+ });
7
+ });
8
+ });
@@ -0,0 +1,25 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/functional_spec_helper")
2
+
3
+ describe JsTestCore do
4
+ attr_reader :stdout, :request
5
+ before do
6
+ @stdout = StringIO.new
7
+ JsTestCore::Client.const_set(:STDOUT, stdout)
8
+ @request = "http request"
9
+ end
10
+
11
+ after do
12
+ JsTestCore::Client.__send__(:remove_const, :STDOUT)
13
+ end
14
+
15
+ it "runs a full passing Suite" do
16
+ JsTestCore::Client.run(:spec_url => "#{root_url}/specs/foo/passing_spec")
17
+ stdout.string.strip.should == JsTestCore::Client::PASSED_RUNNER_STATE.capitalize
18
+ end
19
+
20
+ it "runs a full failing Suite" do
21
+ JsTestCore::Client.run(:spec_url => "#{root_url}/specs/foo/failing_spec")
22
+ stdout.string.strip.should include(JsTestCore::Client::FAILED_RUNNER_STATE.capitalize)
23
+ stdout.string.strip.should include("A failing spec in foo fails: expected true to equal false")
24
+ end
25
+ end
@@ -0,0 +1,42 @@
1
+ require "rubygems"
2
+ require "spec"
3
+ require "spec/autorun"
4
+ require "selenium_rc"
5
+ require "thin"
6
+ dir = File.dirname(__FILE__)
7
+ LIBRARY_ROOT_DIR = File.expand_path("#{dir}/../..")
8
+ require File.expand_path("#{dir}/../spec_helpers/be_http")
9
+ require File.expand_path("#{dir}/../spec_helpers/show_test_exceptions")
10
+ require "#{dir}/functional_spec_server_starter"
11
+ ARGV.push("-b")
12
+
13
+ Spec::Runner.configure do |config|
14
+ config.mock_with :rr
15
+ end
16
+
17
+ Sinatra::Application.use ShowTestExceptions
18
+ Sinatra::Application.set :raise_errors, true
19
+
20
+ Sinatra::Application.use(JsTestCore::App)
21
+
22
+
23
+ class Spec::ExampleGroup
24
+ include WaitFor
25
+ attr_reader :spec_path, :root_path
26
+
27
+ before(:all) do
28
+ @spec_path = FunctionalSpecServerStarter.spec_path
29
+ @root_path = FunctionalSpecServerStarter.root_path
30
+ unless SeleniumRC::Server.service_is_running?
31
+ Thread.start do
32
+ SeleniumRC::Server.boot
33
+ end
34
+ end
35
+ FunctionalSpecServerStarter.call
36
+ TCPSocket.wait_for_service :host => "0.0.0.0", :port => "4444"
37
+ end
38
+
39
+ def root_url
40
+ "http://#{JsTestCore::Server::DEFAULTS[:host]}:#{JsTestCore::Server::DEFAULTS[:port]}"
41
+ end
42
+ end
@@ -0,0 +1,77 @@
1
+ require "rubygems"
2
+ require "timeout"
3
+ require "lsof"
4
+ dir = File.dirname(__FILE__)
5
+ $LOAD_PATH.unshift "#{dir}/../../lib"
6
+ require "js_test_core"
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 $js_test_server_started
26
+
27
+ Lsof.kill(8080)
28
+ wait_for do
29
+ !Lsof.running?(8080)
30
+ end
31
+
32
+ dir = File.dirname(__FILE__)
33
+ Dir.chdir("#{dir}/../../") do
34
+ Thread.start do
35
+ start_thin_server
36
+ end
37
+ end
38
+
39
+ wait_for do
40
+ Lsof.running?(8080)
41
+ end
42
+ $js_test_server_started = true
43
+ end
44
+
45
+ def start_thin_server
46
+ system("bin/js-test-server --spec-path=#{spec_path} --root-path=#{root_path} --framework-name=#{framework_name} --framework-path=#{framework_path}")
47
+ at_exit do
48
+ puts "#{__FILE__}:#{__LINE__}"
49
+ Lsof.kill(8080)
50
+ end
51
+ end
52
+
53
+ def framework_name
54
+ "screw-unit"
55
+ end
56
+
57
+ def framework_path
58
+ File.expand_path("#{dir}/../../../screw-unit/lib")
59
+ end
60
+
61
+ def spec_path
62
+ File.expand_path("#{dir}/../example_spec")
63
+ end
64
+
65
+ def root_path
66
+ File.expand_path("#{dir}/../example_root")
67
+ end
68
+
69
+ def dir
70
+ dir = File.dirname(__FILE__)
71
+ end
72
+ end
73
+ end
74
+
75
+ if $0 == __FILE__
76
+ FunctionalSpecServerStarter.call(false)
77
+ 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,32 @@
1
+ module BeHttp
2
+ include Spec::Matchers
3
+ def be_http(status, headers, body)
4
+ SimpleMatcher.new(nil) do |given, matcher|
5
+ description = (<<-DESC).gsub(/^ +/, "")
6
+ be an http of
7
+ expected status: #{status.inspect}
8
+ actual status : #{given.status.inspect}
9
+
10
+ expected headers containing: #{headers.inspect}
11
+ actual headers : #{given.headers.inspect}
12
+
13
+ expected body containing: #{body.inspect}
14
+ actual body : #{given.body.inspect}
15
+ DESC
16
+ matcher.failure_message = description
17
+ matcher.negative_failure_message = "not #{description}"
18
+
19
+ passed = true
20
+ unless given.status == status
21
+ passed = false
22
+ end
23
+ unless headers.all?{|k, v| given.headers[k] == headers[k]}
24
+ passed = false
25
+ end
26
+ unless body.is_a?(Regexp) ? given.body =~ body : given.body.include?(body)
27
+ passed = false
28
+ end
29
+ passed
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,36 @@
1
+ class Spec::ExampleGroup
2
+ class << self
3
+ def macro(name, &block)
4
+ eigen do
5
+ define_method(name, &block)
6
+ end
7
+ end
8
+
9
+ def eigen(&block)
10
+ eigen_class = (class << self; self; end)
11
+ eigen_class.class_eval(&block)
12
+ eigen_class
13
+ end
14
+ end
15
+
16
+ include Rack::Test::Methods
17
+ include BeHttp
18
+ attr_reader :framework_path, :spec_path, :root_path, :server, :connection
19
+ before(:all) do
20
+ dir = File.dirname(__FILE__)
21
+ @framework_path = File.expand_path("#{LIBRARY_ROOT_DIR}/spec/example_framework")
22
+ @spec_path = File.expand_path("#{LIBRARY_ROOT_DIR}/spec/example_spec")
23
+ @root_path = File.expand_path("#{LIBRARY_ROOT_DIR}/spec/example_root")
24
+ stub(Thread).start.yields
25
+ end
26
+
27
+ before(:each) do
28
+ JsTestCore::Configuration.instance.spec_path = spec_path
29
+ JsTestCore::Configuration.instance.root_path = root_path
30
+ JsTestCore::Configuration.instance.framework_path = framework_path
31
+ end
32
+
33
+ def app
34
+ Sinatra::Application
35
+ end
36
+ end
@@ -0,0 +1,16 @@
1
+ class FakeSeleniumDriver
2
+ def initialize
3
+ end
4
+
5
+ def start
6
+ end
7
+
8
+ def get_eval(js)
9
+ end
10
+
11
+ def stop
12
+ end
13
+
14
+ def open(url)
15
+ end
16
+ end
@@ -0,0 +1,22 @@
1
+ class ShowTestExceptions
2
+ attr_reader :app
3
+
4
+ def initialize(app)
5
+ @app = app
6
+ end
7
+
8
+ def call(env)
9
+ app.call(env)
10
+ rescue StandardError, LoadError, SyntaxError => e
11
+ body = [
12
+ e.message,
13
+ e.backtrace.join("\n\t")
14
+ ].join("\n")
15
+ [
16
+ 500,
17
+ {"Content-Type" => "text",
18
+ "Content-Length" => body.size.to_s},
19
+ body
20
+ ]
21
+ end
22
+ end
@@ -1,2 +1,3 @@
1
1
  dir = File.dirname(__FILE__)
2
- raise "Failure" unless system(%Q|ruby #{dir}/unit_suite.rb|)
2
+ raise "Unit Suite Failure" unless system(%Q|ruby #{dir}/unit_suite.rb|)
3
+ raise "Functional Suite Failure" unless system(%Q|ruby #{dir}/functional_suite.rb|)
@@ -3,135 +3,194 @@ require File.expand_path("#{File.dirname(__FILE__)}/../unit_spec_helper")
3
3
  module JsTestCore
4
4
  describe Client do
5
5
  describe '.run' do
6
- describe 'when successful' do
7
- before do
8
- request = Object.new
9
- mock(request).post("/runners/firefox", "selenium_host=localhost&selenium_port=4444")
10
- response = Object.new
11
- mock(response).body {""}
12
- mock(Net::HTTP).start(DEFAULT_HOST, DEFAULT_PORT).yields(request) {response}
13
- stub(Client).puts
14
- end
15
-
16
- it "returns true" do
17
- Client.run.should be_true
18
- end
6
+ attr_reader :stdout, :request
7
+ before do
8
+ @stdout = StringIO.new
9
+ Client.const_set(:STDOUT, stdout)
10
+ stub.instance_of(Client).sleep
11
+ end
19
12
 
20
- it "prints 'SUCCESS'" do
21
- mock(Client).puts("SUCCESS")
22
- Client.run
23
- end
13
+ after do
14
+ Client.__send__(:remove_const, :STDOUT)
24
15
  end
25
16
 
26
- describe 'when unsuccessful' do
27
- before do
28
- request = Object.new
29
- mock(request).post("/runners/firefox", "selenium_host=localhost&selenium_port=4444")
30
- response = Object.new
31
- mock(response).body {"the failure message"}
32
- mock(Net::HTTP).start(DEFAULT_HOST, DEFAULT_PORT).yields(request) {response}
33
- stub(Client).puts
34
- end
17
+ describe "#start" do
18
+ attr_reader :driver, :browser_host, :spec_url, :selenium_browser_start_command, :selenium_host, :selenium_port
35
19
 
36
- it "returns false" do
37
- Client.run.should be_false
38
- end
20
+ context "with default runner parameters" do
21
+ before do
22
+ @driver = FakeSeleniumDriver.new
39
23
 
40
- it "prints 'FAILURE' and the error message(s)" do
41
- mock(Client).puts("FAILURE")
42
- mock(Client).puts("the failure message")
43
- Client.run
44
- end
45
- end
24
+ expected_selenium_client_params = {
25
+ :host => "0.0.0.0", :port => 4444, :browser => "*firefox", :url => "http://localhost:8080"
26
+ }
46
27
 
47
- describe "arguments" do
48
- attr_reader :request, :response
49
- before do
50
- @request = Object.new
51
- @response = Object.new
52
- mock(response).body {""}
53
- mock(Net::HTTP).start(DEFAULT_HOST, DEFAULT_PORT).yields(request) {response}
54
- stub(Client).puts
55
- end
28
+ mock.proxy(Selenium::Client::Driver).new(expected_selenium_client_params) do
29
+ driver
30
+ end
31
+ end
32
+
33
+ context "when the suite fails" do
34
+ it "returns false" do
35
+ mock.proxy(driver).start.ordered
36
+ mock.proxy(driver).open("/specs").ordered
37
+
38
+ mock.strong(driver).get_eval("window.JsTestServer.status()") do
39
+ {"runner_state" => Client::RUNNING_RUNNER_STATE, "console" => ""}.to_json
40
+ end
41
+
42
+ mock.strong(driver).get_eval("window.JsTestServer.status()") do
43
+ {"runner_state" => Client::RUNNING_RUNNER_STATE, "console" => ".."}.to_json
44
+ end
45
+
46
+ mock.strong(driver).get_eval("window.JsTestServer.status()") do
47
+ {"runner_state" => Client::RUNNING_RUNNER_STATE, "console" => "...F."}.to_json
48
+ end
56
49
 
57
- describe "when passed a custom spec_url" do
58
- it "passes the spec_url as a post parameter" do
59
- spec_url = 'http://foobar.com/foo'
60
- mock(request).post(
61
- "/runners/firefox",
62
- "selenium_host=localhost&selenium_port=4444&spec_url=#{CGI.escape(spec_url)}"
63
- )
64
- Client.run(:spec_url => spec_url)
50
+ mock.strong(driver).get_eval("window.JsTestServer.status()") do
51
+ {"runner_state" => Client::FAILED_RUNNER_STATE, "console" => "...F..\n\nFailure\n/specs/foo_spec.js"}.to_json
52
+ end
53
+
54
+ Client.run.should be_false
55
+ end
65
56
  end
66
- end
67
57
 
68
- describe "when passed a custom selenium host" do
69
- it "passes the selenium_host as a post parameter" do
70
- selenium_host = 'test-runner'
71
- mock(request).post(
72
- "/runners/firefox",
73
- "selenium_host=test-runner&selenium_port=4444"
74
- )
75
- Client.run(:selenium_host => selenium_host)
58
+ context "when the suite passes" do
59
+ it "returns true" do
60
+ mock.proxy(driver).start.ordered
61
+ mock.proxy(driver).open("/specs").ordered
62
+
63
+ mock.strong(driver).get_eval("window.JsTestServer.status()") do
64
+ {"runner_state" => Client::RUNNING_RUNNER_STATE, "console" => ""}.to_json
65
+ end
66
+
67
+ mock.strong(driver).get_eval("window.JsTestServer.status()") do
68
+ {"runner_state" => Client::RUNNING_RUNNER_STATE, "console" => ".."}.to_json
69
+ end
70
+
71
+ mock.strong(driver).get_eval("window.JsTestServer.status()") do
72
+ {"runner_state" => Client::RUNNING_RUNNER_STATE, "console" => "....."}.to_json
73
+ end
74
+
75
+ mock.strong(driver).get_eval("window.JsTestServer.status()") do
76
+ {"runner_state" => Client::PASSED_RUNNER_STATE, "console" => "......\n\nPassed"}.to_json
77
+ end
78
+
79
+ Client.run.should be_true
80
+ end
76
81
  end
77
82
  end
78
83
 
79
- describe "when passed a custom selenium port" do
80
- it "passes the selenium_port as a post parameter" do
81
- selenium_port = 5000
82
- mock(request).post(
83
- "/runners/firefox",
84
- "selenium_host=localhost&selenium_port=5000"
85
- )
86
- Client.run(:selenium_port => selenium_port)
84
+ describe "with overridden runner parameters" do
85
+ it "allows overrides for :host, :port, :browser, and :url" do
86
+ driver = FakeSeleniumDriver.new
87
+
88
+ host = "myhost"
89
+ port = 9999
90
+ browser = "*iexplore"
91
+ spec_url = "http://myspechost:7777/specs/path"
92
+ expected_selenium_client_params = {
93
+ :host => host, :port => port, :browser => browser, :url => "http://myspechost:7777"
94
+ }
95
+ mock.proxy(Selenium::Client::Driver).new(expected_selenium_client_params) do
96
+ driver
97
+ end
98
+
99
+ mock.proxy(driver).start.ordered
100
+ mock.proxy(driver).open("/specs/path").ordered
101
+
102
+ mock.strong(driver).get_eval("window.JsTestServer.status()") do
103
+ {"runner_state" => Client::RUNNING_RUNNER_STATE, "console" => ""}.to_json
104
+ end
105
+
106
+ mock.strong(driver).get_eval("window.JsTestServer.status()") do
107
+ {"runner_state" => Client::RUNNING_RUNNER_STATE, "console" => ".."}.to_json
108
+ end
109
+
110
+ mock.strong(driver).get_eval("window.JsTestServer.status()") do
111
+ {"runner_state" => Client::RUNNING_RUNNER_STATE, "console" => "....."}.to_json
112
+ end
113
+
114
+ mock.strong(driver).get_eval("window.JsTestServer.status()") do
115
+ {"runner_state" => Client::PASSED_RUNNER_STATE, "console" => "......\n\nPassed"}.to_json
116
+ end
117
+
118
+ Client.run(:selenium_host => host, :selenium_port => port, :selenium_browser => browser, :spec_url => spec_url).
119
+ should be_true
87
120
  end
88
121
  end
89
122
  end
90
-
91
123
  end
92
-
124
+
93
125
  describe ".run_argv" do
94
126
  attr_reader :request, :response
95
127
  before do
96
- @request = Object.new
97
- @response = Object.new
98
- mock(response).body {""}
99
- mock(Net::HTTP).start(DEFAULT_HOST, DEFAULT_PORT).yields(request) {response}
100
- stub(Client).puts
128
+ stub(Client).puts
129
+ end
130
+
131
+ context "when passed-in Hash contains :selenium_browser" do
132
+ it "passes the spec_url as a post parameter" do
133
+ selenium_browser = '*iexplore'
134
+ mock(Client).run(satisfy do |params|
135
+ default_params.merge(:selenium_browser => selenium_browser).
136
+ to_set.subset?(params.to_set)
137
+ end)
138
+ client = Client.run_argv(['--selenium-browser', selenium_browser])
101
139
  end
140
+ end
102
141
 
103
- describe "when passed a custom spec_url" do
142
+ context "when passed-in Hash contains :spec_url" do
104
143
  it "passes the spec_url as a post parameter" do
105
144
  spec_url = 'http://foobar.com/foo'
106
- mock(request).post(
107
- "/runners/firefox",
108
- "selenium_host=localhost&selenium_port=4444&spec_url=#{CGI.escape(spec_url)}"
109
- )
110
- Client.run_argv(['--spec_url', spec_url])
145
+ mock(Client).run(satisfy do |params|
146
+ default_params.merge(:spec_url => spec_url).
147
+ to_set.subset?(params.to_set)
148
+ end)
149
+ client = Client.run_argv(['--spec-url', spec_url])
111
150
  end
112
151
  end
113
152
 
114
- describe "when passed a custom selenium host" do
153
+ context "when passed-in Hash contains :selenium_host" do
115
154
  it "passes the selenium_host as a post parameter" do
116
155
  selenium_host = 'test-runner'
117
- mock(request).post(
118
- "/runners/firefox",
119
- "selenium_host=test-runner&selenium_port=4444"
120
- )
121
- Client.run_argv(['--selenium_host', selenium_host])
156
+ mock(Client).run(satisfy do |params|
157
+ default_params.merge(:selenium_host => selenium_host).
158
+ to_set.subset?(params.to_set)
159
+ end)
160
+ client = Client.run_argv(['--selenium-host', selenium_host])
122
161
  end
123
162
  end
124
163
 
125
- describe "when passed a custom selenium port" do
164
+ context "when passed-in Hash contains :selenium_port" do
126
165
  it "passes the selenium_port as a post parameter" do
127
166
  selenium_port = 5000
128
- mock(request).post(
129
- "/runners/firefox",
130
- "selenium_host=localhost&selenium_port=5000"
131
- )
132
- Client.run_argv(['--selenium_port', selenium_port.to_s])
167
+ mock(Client).run(satisfy do |params|
168
+ default_params.merge(:selenium_port => selenium_port).
169
+ to_set.subset?(params.to_set)
170
+ end)
171
+ client = Client.run_argv(['--selenium-port', selenium_port.to_s])
133
172
  end
134
173
  end
174
+
175
+ context "when passed-in Hash contains :timeout" do
176
+ it "passes the timeout as a post parameter" do
177
+ mock(Client).run(satisfy do |params|
178
+ default_params.merge(:timeout => 5).
179
+ to_set.subset?(params.to_set)
180
+ end)
181
+ client = Client.run_argv(['--timeout', "5"])
182
+ end
183
+ end
184
+
185
+ def default_params
186
+ {
187
+ :selenium_browser => "*firefox",
188
+ :selenium_host => "0.0.0.0",
189
+ :selenium_port => 4444,
190
+ :spec_url => "http://localhost:8080/specs",
191
+ :timeout => 60
192
+ }
193
+ end
135
194
  end
136
195
  end
137
196
  end