honkster-screw-unit-server 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. data/CHANGES +48 -0
  2. data/README.markdown +359 -0
  3. data/Rakefile +43 -0
  4. data/VERSION.yml +5 -0
  5. data/bin/screw_unit +6 -0
  6. data/bin/screw_unit_server +14 -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 +95 -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 +166 -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.rb +21 -0
  34. data/spec/functional/functional_spec.rb +25 -0
  35. data/spec/functional/functional_spec_helper.rb +42 -0
  36. data/spec/functional/functional_spec_server_starter.rb +68 -0
  37. data/spec/functional_suite.rb +10 -0
  38. data/spec/spec_suite.rb +2 -0
  39. data/standalone.ru +3 -0
  40. data/vendor/js-test-core/CHANGES +31 -0
  41. data/vendor/js-test-core/README +6 -0
  42. data/vendor/js-test-core/Rakefile +73 -0
  43. data/vendor/js-test-core/bin/js-test-client +0 -0
  44. data/vendor/js-test-core/bin/js-test-server +6 -0
  45. data/vendor/js-test-core/lib/js_test_core.rb +38 -0
  46. data/vendor/js-test-core/lib/js_test_core/app.rb +11 -0
  47. data/vendor/js-test-core/lib/js_test_core/client.rb +139 -0
  48. data/vendor/js-test-core/lib/js_test_core/configuration.rb +65 -0
  49. data/vendor/js-test-core/lib/js_test_core/representations.rb +13 -0
  50. data/vendor/js-test-core/lib/js_test_core/representations/dir.html.rb +25 -0
  51. data/vendor/js-test-core/lib/js_test_core/representations/frameworks.rb +3 -0
  52. data/vendor/js-test-core/lib/js_test_core/representations/not_found.html.rb +16 -0
  53. data/vendor/js-test-core/lib/js_test_core/representations/page.html.rb +41 -0
  54. data/vendor/js-test-core/lib/js_test_core/representations/suite.html.rb +57 -0
  55. data/vendor/js-test-core/lib/js_test_core/representations/suites.rb +3 -0
  56. data/vendor/js-test-core/lib/js_test_core/representations/suites/screw_unit.html.rb +81 -0
  57. data/vendor/js-test-core/lib/js_test_core/resources.rb +15 -0
  58. data/vendor/js-test-core/lib/js_test_core/resources/core_file.rb +19 -0
  59. data/vendor/js-test-core/lib/js_test_core/resources/file.rb +62 -0
  60. data/vendor/js-test-core/lib/js_test_core/resources/implementations_deprecation.rb +12 -0
  61. data/vendor/js-test-core/lib/js_test_core/resources/not_found.rb +28 -0
  62. data/vendor/js-test-core/lib/js_test_core/resources/resource.rb +16 -0
  63. data/vendor/js-test-core/lib/js_test_core/resources/spec_file.rb +51 -0
  64. data/vendor/js-test-core/lib/js_test_core/resources/web_root.rb +15 -0
  65. data/vendor/js-test-core/lib/js_test_core/server.rb +84 -0
  66. data/vendor/js-test-core/public/js_test_server.js +541 -0
  67. data/vendor/js-test-core/spec/example_framework/JsTestCore.css +0 -0
  68. data/vendor/js-test-core/spec/example_framework/JsTestCore.js +0 -0
  69. data/vendor/js-test-core/spec/example_framework/subdir/SubDirFile.js +0 -0
  70. data/vendor/js-test-core/spec/example_root/favicon.ico +0 -0
  71. data/vendor/js-test-core/spec/example_root/javascripts/foo.js +3 -0
  72. data/vendor/js-test-core/spec/example_root/javascripts/large_file.js +59 -0
  73. data/vendor/js-test-core/spec/example_root/javascripts/subdir/bar.js +1 -0
  74. data/vendor/js-test-core/spec/example_root/robots.txt +0 -0
  75. data/vendor/js-test-core/spec/example_root/stylesheets/example.css +3 -0
  76. data/vendor/js-test-core/spec/example_spec/custom_dir_and_suite/passing_spec.js +8 -0
  77. data/vendor/js-test-core/spec/example_spec/custom_suite.html +8 -0
  78. data/vendor/js-test-core/spec/example_spec/failing_spec.js +7 -0
  79. data/vendor/js-test-core/spec/example_spec/foo/failing_spec.js +8 -0
  80. data/vendor/js-test-core/spec/example_spec/foo/passing_spec.js +8 -0
  81. data/vendor/js-test-core/spec/example_spec/passing_spec.js +8 -0
  82. data/vendor/js-test-core/spec/functional/functional_spec.rb +25 -0
  83. data/vendor/js-test-core/spec/functional/functional_spec_helper.rb +42 -0
  84. data/vendor/js-test-core/spec/functional/functional_spec_server_starter.rb +77 -0
  85. data/vendor/js-test-core/spec/functional_suite.rb +10 -0
  86. data/vendor/js-test-core/spec/spec_helpers/be_http.rb +32 -0
  87. data/vendor/js-test-core/spec/spec_helpers/example_group.rb +36 -0
  88. data/vendor/js-test-core/spec/spec_helpers/fake_selenium_driver.rb +16 -0
  89. data/vendor/js-test-core/spec/spec_helpers/show_test_exceptions.rb +22 -0
  90. data/vendor/js-test-core/spec/spec_suite.rb +3 -0
  91. data/vendor/js-test-core/spec/specs/failing_spec.js +0 -0
  92. data/vendor/js-test-core/spec/unit/js_test_core/client_spec.rb +196 -0
  93. data/vendor/js-test-core/spec/unit/js_test_core/configuration_spec.rb +50 -0
  94. data/vendor/js-test-core/spec/unit/js_test_core/resources/core_file_spec.rb +60 -0
  95. data/vendor/js-test-core/spec/unit/js_test_core/resources/file_spec.rb +81 -0
  96. data/vendor/js-test-core/spec/unit/js_test_core/resources/implementations_deprecation_spec.rb +18 -0
  97. data/vendor/js-test-core/spec/unit/js_test_core/resources/not_found_spec.rb +51 -0
  98. data/vendor/js-test-core/spec/unit/js_test_core/resources/spec_file_spec.rb +149 -0
  99. data/vendor/js-test-core/spec/unit/js_test_core/resources/web_root_spec.rb +28 -0
  100. data/vendor/js-test-core/spec/unit/js_test_core/server_spec.rb +66 -0
  101. data/vendor/js-test-core/spec/unit/unit_spec_helper.rb +30 -0
  102. data/vendor/js-test-core/spec/unit_suite.rb +10 -0
  103. data/vendor/js-test-core/standalone.ru +1 -0
  104. data/vendor/js-test-core/vendor/lucky-luciano/README.markdown +77 -0
  105. data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano.rb +5 -0
  106. data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/resource.rb +142 -0
  107. data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/resource/path.rb +24 -0
  108. data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/rspec.rb +4 -0
  109. data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/rspec/be_http.rb +32 -0
  110. data/vendor/js-test-core/vendor/lucky-luciano/spec/lucky_luciano/resource_spec.rb +276 -0
  111. data/vendor/js-test-core/vendor/lucky-luciano/spec/spec_helper.rb +48 -0
  112. data/vendor/js-test-core/vendor/lucky-luciano/spec/spec_suite.rb +4 -0
  113. data/vendor/js-test-core/vendor/lucky-luciano/syntax_ideas.txt +34 -0
  114. metadata +201 -0
@@ -0,0 +1,3 @@
1
+ var Foo = {
2
+ value: true
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
+ //////////////////////////////////////////////
@@ -0,0 +1,3 @@
1
+ h1 {
2
+ text-align: center;
3
+ }
@@ -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
@@ -0,0 +1,3 @@
1
+ dir = File.dirname(__FILE__)
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|)
@@ -0,0 +1,196 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../unit_spec_helper")
2
+
3
+ module JsTestCore
4
+ describe Client do
5
+ describe '.run' do
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
12
+
13
+ after do
14
+ Client.__send__(:remove_const, :STDOUT)
15
+ end
16
+
17
+ describe "#start" do
18
+ attr_reader :driver, :browser_host, :spec_url, :selenium_browser_start_command, :selenium_host, :selenium_port
19
+
20
+ context "with default runner parameters" do
21
+ before do
22
+ @driver = FakeSeleniumDriver.new
23
+
24
+ expected_selenium_client_params = {
25
+ :host => "0.0.0.0", :port => 4444, :browser => "*firefox", :url => "http://localhost:8080"
26
+ }
27
+
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
49
+
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
56
+ end
57
+
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
81
+ end
82
+ end
83
+
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
120
+ end
121
+ end
122
+ end
123
+ end
124
+
125
+ describe ".run_argv" do
126
+ attr_reader :request, :response
127
+ before do
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])
139
+ end
140
+ end
141
+
142
+ context "when passed-in Hash contains :spec_url" do
143
+ it "passes the spec_url as a post parameter" do
144
+ spec_url = 'http://foobar.com/foo'
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])
150
+ end
151
+ end
152
+
153
+ context "when passed-in Hash contains :selenium_host" do
154
+ it "passes the selenium_host as a post parameter" do
155
+ selenium_host = 'test-runner'
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])
161
+ end
162
+ end
163
+
164
+ context "when passed-in Hash contains :selenium_port" do
165
+ it "passes the selenium_port as a post parameter" do
166
+ selenium_port = 5000
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])
172
+ end
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
194
+ end
195
+ end
196
+ end