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.
- data/CHANGES +44 -1
- data/README.markdown +17 -5
- data/Rakefile +28 -55
- data/VERSION.yml +5 -0
- data/bin/screw_unit_server +8 -4
- data/core/CHANGES +10 -0
- data/core/EXAMPLE.html +4 -4
- data/core/README.markdown +7 -7
- data/core/example/models/man.js +2 -2
- data/core/example/spec/suite.html +1 -1
- data/core/lib/jquery-1.3.2.js +4376 -0
- data/core/lib/jquery.fn.js +2 -1
- data/core/lib/jquery.print.js +13 -12
- data/core/lib/screw.behaviors.js +11 -9
- data/core/lib/screw.builder.js +26 -11
- data/core/lib/screw.css +2 -2
- data/core/lib/screw.events.js +11 -4
- data/core/lib/screw.matchers.js +192 -13
- data/core/spec/behaviors_spec.js +11 -1
- data/core/spec/matchers_spec.js +288 -9
- data/core/spec/print_spec.js +47 -8
- data/core/spec/suite.html +2 -1
- data/core/spec/with_screw_context_spec.js +9 -0
- data/lib/screw_unit.rb +12 -17
- data/spec/functional/functional_spec.rb +15 -4
- data/spec/functional/functional_spec_helper.rb +22 -35
- data/spec/functional/functional_spec_server_starter.rb +68 -0
- data/spec/spec_suite.rb +0 -1
- data/standalone.ru +3 -0
- data/vendor/js-test-core/CHANGES +22 -0
- data/vendor/js-test-core/README +4 -10
- data/vendor/js-test-core/Rakefile +2 -1
- data/vendor/js-test-core/{spec/example_core/JsTestCore.css → bin/js-test-client} +0 -0
- data/vendor/js-test-core/bin/js-test-server +6 -0
- data/vendor/js-test-core/lib/js_test_core.rb +27 -19
- data/vendor/js-test-core/lib/js_test_core/app.rb +11 -0
- data/vendor/js-test-core/lib/js_test_core/client.rb +125 -36
- data/vendor/js-test-core/lib/js_test_core/configuration.rb +65 -0
- data/vendor/js-test-core/lib/js_test_core/representations.rb +13 -0
- data/vendor/js-test-core/lib/js_test_core/representations/dir.html.rb +25 -0
- data/vendor/js-test-core/lib/js_test_core/representations/frameworks.rb +3 -0
- data/vendor/js-test-core/lib/js_test_core/representations/not_found.html.rb +16 -0
- data/vendor/js-test-core/lib/js_test_core/representations/page.html.rb +41 -0
- data/vendor/js-test-core/lib/js_test_core/representations/suite.html.rb +57 -0
- data/vendor/js-test-core/lib/js_test_core/representations/suites.rb +3 -0
- data/vendor/js-test-core/lib/js_test_core/representations/suites/screw_unit.html.rb +81 -0
- data/vendor/js-test-core/lib/js_test_core/resources.rb +12 -8
- data/vendor/js-test-core/lib/js_test_core/resources/core_file.rb +19 -0
- data/vendor/js-test-core/lib/js_test_core/resources/file.rb +43 -13
- data/vendor/js-test-core/lib/js_test_core/resources/implementations_deprecation.rb +12 -0
- data/vendor/js-test-core/lib/js_test_core/resources/not_found.rb +28 -0
- data/vendor/js-test-core/lib/js_test_core/resources/resource.rb +16 -0
- data/vendor/js-test-core/lib/js_test_core/resources/spec_file.rb +51 -0
- data/vendor/js-test-core/lib/js_test_core/resources/web_root.rb +7 -54
- data/vendor/js-test-core/lib/js_test_core/server.rb +65 -92
- data/vendor/js-test-core/public/js_test_server.js +541 -0
- data/vendor/js-test-core/spec/{example_core/JsTestCore.js → example_framework/JsTestCore.css} +0 -0
- data/vendor/js-test-core/spec/{example_public/favicon.ico → example_framework/JsTestCore.js} +0 -0
- data/vendor/js-test-core/spec/{example_public/robots.txt → example_framework/subdir/SubDirFile.js} +0 -0
- data/vendor/js-test-core/spec/example_root/favicon.ico +0 -0
- data/vendor/js-test-core/spec/{example_public → example_root}/javascripts/foo.js +1 -1
- data/vendor/js-test-core/spec/example_root/javascripts/large_file.js +59 -0
- data/vendor/js-test-core/spec/example_root/javascripts/subdir/bar.js +1 -0
- data/vendor/js-test-core/spec/example_root/robots.txt +0 -0
- data/vendor/js-test-core/spec/{example_public → example_root}/stylesheets/example.css +0 -0
- data/vendor/js-test-core/spec/example_spec/custom_dir_and_suite/passing_spec.js +8 -0
- data/vendor/js-test-core/spec/example_spec/custom_suite.html +8 -0
- data/vendor/js-test-core/spec/example_spec/failing_spec.js +7 -0
- data/vendor/js-test-core/spec/example_spec/foo/failing_spec.js +8 -0
- data/vendor/js-test-core/spec/example_spec/foo/passing_spec.js +8 -0
- data/vendor/js-test-core/spec/example_spec/passing_spec.js +8 -0
- data/vendor/js-test-core/spec/functional/functional_spec.rb +25 -0
- data/vendor/js-test-core/spec/functional/functional_spec_helper.rb +42 -0
- data/vendor/js-test-core/spec/functional/functional_spec_server_starter.rb +77 -0
- data/vendor/js-test-core/spec/functional_suite.rb +10 -0
- data/vendor/js-test-core/spec/spec_helpers/be_http.rb +32 -0
- data/vendor/js-test-core/spec/spec_helpers/example_group.rb +36 -0
- data/vendor/js-test-core/spec/spec_helpers/fake_selenium_driver.rb +16 -0
- data/vendor/js-test-core/spec/spec_helpers/show_test_exceptions.rb +22 -0
- data/vendor/js-test-core/spec/spec_suite.rb +2 -1
- data/vendor/js-test-core/spec/unit/js_test_core/client_spec.rb +153 -94
- data/vendor/js-test-core/spec/unit/js_test_core/configuration_spec.rb +50 -0
- data/vendor/js-test-core/spec/unit/js_test_core/resources/core_file_spec.rb +60 -0
- data/vendor/js-test-core/spec/unit/js_test_core/resources/file_spec.rb +61 -68
- data/vendor/js-test-core/spec/unit/js_test_core/resources/implementations_deprecation_spec.rb +18 -0
- data/vendor/js-test-core/spec/unit/js_test_core/resources/not_found_spec.rb +51 -0
- data/vendor/js-test-core/spec/unit/js_test_core/resources/spec_file_spec.rb +149 -0
- data/vendor/js-test-core/spec/unit/js_test_core/resources/web_root_spec.rb +14 -89
- data/vendor/js-test-core/spec/unit/js_test_core/server_spec.rb +41 -106
- data/vendor/js-test-core/spec/unit/unit_spec_helper.rb +19 -114
- data/vendor/js-test-core/standalone.ru +1 -0
- data/vendor/js-test-core/vendor/lucky-luciano/README.markdown +77 -0
- data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano.rb +5 -0
- data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/resource.rb +142 -0
- data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/resource/path.rb +24 -0
- data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/rspec.rb +4 -0
- data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/rspec/be_http.rb +32 -0
- data/vendor/js-test-core/vendor/lucky-luciano/spec/lucky_luciano/resource_spec.rb +276 -0
- data/vendor/js-test-core/vendor/lucky-luciano/spec/spec_helper.rb +48 -0
- data/vendor/js-test-core/vendor/lucky-luciano/spec/spec_suite.rb +4 -0
- data/vendor/js-test-core/vendor/lucky-luciano/syntax_ideas.txt +34 -0
- metadata +145 -130
- data/core/TODO +0 -2
- data/core/lib/jquery-1.2.3.js +0 -3408
- data/core/lib/screw.assets.js +0 -36
- data/core/lib/screw.server.js +0 -21
- data/lib/screw_unit/resources.rb +0 -2
- data/lib/screw_unit/resources/spec.rb +0 -37
- data/spec/unit/js_test_core/specs/spec_dir_spec.rb +0 -43
- data/spec/unit/js_test_core/specs/spec_file_spec.rb +0 -43
- data/spec/unit/unit_spec_helper.rb +0 -120
- data/spec/unit_suite.rb +0 -10
- data/vendor/js-test-core/lib/js_test_core/rack.rb +0 -2
- data/vendor/js-test-core/lib/js_test_core/rack/commonlogger.rb +0 -5
- data/vendor/js-test-core/lib/js_test_core/rails_server.rb +0 -22
- data/vendor/js-test-core/lib/js_test_core/resources/dir.rb +0 -52
- data/vendor/js-test-core/lib/js_test_core/resources/file_not_found.rb +0 -15
- data/vendor/js-test-core/lib/js_test_core/resources/runners.rb +0 -15
- data/vendor/js-test-core/lib/js_test_core/resources/runners/firefox_runner.rb +0 -75
- data/vendor/js-test-core/lib/js_test_core/resources/specs/spec_dir.rb +0 -50
- data/vendor/js-test-core/lib/js_test_core/resources/specs/spec_file.rb +0 -17
- data/vendor/js-test-core/lib/js_test_core/resources/suite.rb +0 -24
- data/vendor/js-test-core/lib/js_test_core/resources/suite_finish.rb +0 -19
- data/vendor/js-test-core/lib/js_test_core/selenium.rb +0 -2
- data/vendor/js-test-core/lib/js_test_core/selenium/selenium_driver.rb +0 -5
- data/vendor/js-test-core/lib/js_test_core/thin.rb +0 -3
- data/vendor/js-test-core/lib/js_test_core/thin/backends/js_test_core_server.rb +0 -9
- data/vendor/js-test-core/lib/js_test_core/thin/js_test_core_connection.rb +0 -42
- data/vendor/js-test-core/spec/example_specs/failing_spec.js +0 -5
- data/vendor/js-test-core/spec/example_specs/foo/failing_spec.js +0 -6
- data/vendor/js-test-core/spec/example_specs/foo/passing_spec.js +0 -6
- data/vendor/js-test-core/spec/unit/js_test_core/rails_server_spec.rb +0 -45
- data/vendor/js-test-core/spec/unit/js_test_core/resources/dir_spec.rb +0 -42
- data/vendor/js-test-core/spec/unit/js_test_core/resources/file_not_found_spec.rb +0 -26
- data/vendor/js-test-core/spec/unit/js_test_core/resources/runner_spec.rb +0 -24
- data/vendor/js-test-core/spec/unit/js_test_core/resources/runners/firefox_runner_spec.rb +0 -197
- data/vendor/js-test-core/spec/unit/js_test_core/resources/specs/spec_dir_spec.rb +0 -79
- data/vendor/js-test-core/spec/unit/js_test_core/resources/specs/spec_file_spec.rb +0 -42
- data/vendor/js-test-core/spec/unit/js_test_core/resources/suite_finish_spec.rb +0 -94
- data/vendor/js-test-core/spec/unit/js_test_core/resources/suite_spec.rb +0 -44
- data/vendor/js-test-core/spec/unit/thin/js_test_core_connection_spec.rb +0 -92
data/vendor/js-test-core/spec/{example_core/JsTestCore.js → example_framework/JsTestCore.css}
RENAMED
File without changes
|
data/vendor/js-test-core/spec/{example_public/favicon.ico → example_framework/JsTestCore.js}
RENAMED
File without changes
|
data/vendor/js-test-core/spec/{example_public/robots.txt → example_framework/subdir/SubDirFile.js}
RENAMED
File without changes
|
File without changes
|
@@ -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 @@
|
|
1
|
+
var bar = true;
|
File without changes
|
File without changes
|
@@ -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,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,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
|
@@ -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
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
-
|
21
|
-
|
22
|
-
Client.run
|
23
|
-
end
|
13
|
+
after do
|
14
|
+
Client.__send__(:remove_const, :STDOUT)
|
24
15
|
end
|
25
16
|
|
26
|
-
describe
|
27
|
-
|
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
|
-
|
37
|
-
|
38
|
-
|
20
|
+
context "with default runner parameters" do
|
21
|
+
before do
|
22
|
+
@driver = FakeSeleniumDriver.new
|
39
23
|
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
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
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
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
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
"
|
74
|
-
|
75
|
-
|
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 "
|
80
|
-
it "
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
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
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
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
|
-
|
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(
|
107
|
-
|
108
|
-
|
109
|
-
)
|
110
|
-
Client.run_argv(['--
|
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
|
-
|
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(
|
118
|
-
|
119
|
-
|
120
|
-
)
|
121
|
-
Client.run_argv(['--
|
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
|
-
|
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(
|
129
|
-
|
130
|
-
|
131
|
-
)
|
132
|
-
Client.run_argv(['--
|
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
|