pivotal-screw-unit-server 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. data/CHANGES +27 -0
  2. data/README.markdown +354 -0
  3. data/Rakefile +42 -0
  4. data/VERSION.yml +4 -0
  5. data/bin/screw_unit +6 -0
  6. data/bin/screw_unit_server +20 -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 +188 -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 +23 -0
  34. data/lib/screw_unit/representations.rb +2 -0
  35. data/lib/screw_unit/representations/spec.html.rb +117 -0
  36. data/spec/functional/functional_spec.rb +25 -0
  37. data/spec/functional/functional_spec_helper.rb +43 -0
  38. data/spec/functional/functional_spec_server_starter.rb +68 -0
  39. data/spec/functional_suite.rb +10 -0
  40. data/spec/spec_suite.rb +3 -0
  41. data/spec/unit/js_test_core/specs/spec_file_spec.rb +68 -0
  42. data/spec/unit/unit_spec_helper.rb +51 -0
  43. data/spec/unit_suite.rb +10 -0
  44. data/vendor/js-test-core/CHANGES +28 -0
  45. data/vendor/js-test-core/README +12 -0
  46. data/vendor/js-test-core/Rakefile +73 -0
  47. data/vendor/js-test-core/lib/js_test_core.rb +46 -0
  48. data/vendor/js-test-core/lib/js_test_core/app.rb +12 -0
  49. data/vendor/js-test-core/lib/js_test_core/client.rb +129 -0
  50. data/vendor/js-test-core/lib/js_test_core/configuration.rb +35 -0
  51. data/vendor/js-test-core/lib/js_test_core/extensions.rb +3 -0
  52. data/vendor/js-test-core/lib/js_test_core/extensions/selenium/client/driver.rb +7 -0
  53. data/vendor/js-test-core/lib/js_test_core/extensions/time.rb +6 -0
  54. data/vendor/js-test-core/lib/js_test_core/models.rb +8 -0
  55. data/vendor/js-test-core/lib/js_test_core/models/selenium_session.rb +80 -0
  56. data/vendor/js-test-core/lib/js_test_core/representations.rb +11 -0
  57. data/vendor/js-test-core/lib/js_test_core/representations/dir.html.rb +24 -0
  58. data/vendor/js-test-core/lib/js_test_core/representations/not_found.html.rb +15 -0
  59. data/vendor/js-test-core/lib/js_test_core/representations/page.html.rb +41 -0
  60. data/vendor/js-test-core/lib/js_test_core/representations/spec.html.rb +24 -0
  61. data/vendor/js-test-core/lib/js_test_core/resources.rb +16 -0
  62. data/vendor/js-test-core/lib/js_test_core/resources/core_file.rb +19 -0
  63. data/vendor/js-test-core/lib/js_test_core/resources/file.rb +62 -0
  64. data/vendor/js-test-core/lib/js_test_core/resources/implementations_deprecation.rb +12 -0
  65. data/vendor/js-test-core/lib/js_test_core/resources/not_found.rb +35 -0
  66. data/vendor/js-test-core/lib/js_test_core/resources/resource.rb +16 -0
  67. data/vendor/js-test-core/lib/js_test_core/resources/selenium_session.rb +104 -0
  68. data/vendor/js-test-core/lib/js_test_core/resources/spec_file.rb +63 -0
  69. data/vendor/js-test-core/lib/js_test_core/resources/web_root.rb +11 -0
  70. data/vendor/js-test-core/lib/js_test_core/selenium_server_configuration.rb +48 -0
  71. data/vendor/js-test-core/spec/example_core/JsTestCore.css +0 -0
  72. data/vendor/js-test-core/spec/example_core/JsTestCore.js +0 -0
  73. data/vendor/js-test-core/spec/example_core/subdir/SubDirFile.js +0 -0
  74. data/vendor/js-test-core/spec/example_public/favicon.ico +0 -0
  75. data/vendor/js-test-core/spec/example_public/javascripts/foo.js +3 -0
  76. data/vendor/js-test-core/spec/example_public/javascripts/large_file.js +59 -0
  77. data/vendor/js-test-core/spec/example_public/javascripts/subdir/bar.js +1 -0
  78. data/vendor/js-test-core/spec/example_public/robots.txt +0 -0
  79. data/vendor/js-test-core/spec/example_public/stylesheets/example.css +3 -0
  80. data/vendor/js-test-core/spec/example_specs/custom_dir_and_suite/passing_spec.js +6 -0
  81. data/vendor/js-test-core/spec/example_specs/custom_suite.html +8 -0
  82. data/vendor/js-test-core/spec/example_specs/failing_spec.js +5 -0
  83. data/vendor/js-test-core/spec/example_specs/foo/failing_spec.js +6 -0
  84. data/vendor/js-test-core/spec/example_specs/foo/passing_spec.js +6 -0
  85. data/vendor/js-test-core/spec/spec_helpers/be_http.rb +32 -0
  86. data/vendor/js-test-core/spec/spec_helpers/example_group.rb +36 -0
  87. data/vendor/js-test-core/spec/spec_helpers/fake_selenium_driver.rb +27 -0
  88. data/vendor/js-test-core/spec/spec_helpers/show_test_exceptions.rb +22 -0
  89. data/vendor/js-test-core/spec/spec_suite.rb +2 -0
  90. data/vendor/js-test-core/spec/specs/failing_spec.js +0 -0
  91. data/vendor/js-test-core/spec/unit/js_test_core/client_spec.rb +192 -0
  92. data/vendor/js-test-core/spec/unit/js_test_core/configuration_spec.rb +44 -0
  93. data/vendor/js-test-core/spec/unit/js_test_core/models/selenium_session_spec.rb +85 -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/selenium_session_spec.rb +362 -0
  99. data/vendor/js-test-core/spec/unit/js_test_core/resources/spec_file_spec.rb +120 -0
  100. data/vendor/js-test-core/spec/unit/js_test_core/resources/web_root_spec.rb +28 -0
  101. data/vendor/js-test-core/spec/unit/js_test_core/selenium_server_configuration_spec.rb +49 -0
  102. data/vendor/js-test-core/spec/unit/unit_spec_helper.rb +28 -0
  103. data/vendor/js-test-core/spec/unit_suite.rb +10 -0
  104. data/vendor/js-test-core/vendor/lucky-luciano/README.markdown +7 -0
  105. data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano.rb +4 -0
  106. data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/resource.rb +135 -0
  107. data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/rspec.rb +4 -0
  108. data/vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/rspec/be_http.rb +32 -0
  109. data/vendor/js-test-core/vendor/lucky-luciano/spec/lucky_luciano/resource_spec.rb +231 -0
  110. data/vendor/js-test-core/vendor/lucky-luciano/spec/spec_helper.rb +48 -0
  111. data/vendor/js-test-core/vendor/lucky-luciano/spec/spec_suite.rb +4 -0
  112. metadata +198 -0
@@ -0,0 +1,104 @@
1
+ module JsTestCore
2
+ module Resources
3
+ class SeleniumSession < Resource
4
+ map "/selenium_sessions"
5
+
6
+ post "/" do
7
+ do_post params["selenium_browser_start_command"]
8
+ end
9
+
10
+ post "/firefox" do
11
+ do_post "*firefox"
12
+ end
13
+
14
+ post '/iexplore' do |env, name|
15
+ do_post "*iexplore"
16
+ end
17
+
18
+ get "/:session_id" do
19
+ do_get
20
+ end
21
+
22
+ post "/finish" do
23
+ do_finish
24
+ end
25
+
26
+ post "/:session_id/finish" do
27
+ do_finish
28
+ end
29
+
30
+ include FileUtils
31
+ RUNNING = 'running'
32
+ SUCCESSFUL_COMPLETION = 'success'
33
+ FAILURE_COMPLETION = 'failure'
34
+
35
+ protected
36
+
37
+ def do_get
38
+ selenium_session = Models::SeleniumSession.find(session_id)
39
+ if selenium_session
40
+ body = if selenium_session.running?
41
+ "status=#{RUNNING}"
42
+ else
43
+ if selenium_session.successful?
44
+ "status=#{SUCCESSFUL_COMPLETION}"
45
+ else
46
+ "status=#{FAILURE_COMPLETION}&reason=#{selenium_session.run_result}"
47
+ end
48
+ end
49
+ [
50
+ 200,
51
+ {'Content-Length' => body.length},
52
+ body
53
+ ]
54
+ else
55
+ body = Representations::NotFound.new(:message => "Could not find session #{session_id}").to_s
56
+ [
57
+ 404,
58
+ {
59
+ "Content-Type" => "text/html",
60
+ "Content-Length" => body.size.to_s
61
+ },
62
+ body
63
+ ]
64
+ end
65
+ end
66
+
67
+ def do_finish
68
+ if selenium_session = Models::SeleniumSession.find(session_id)
69
+ selenium_session.finish(request['text'])
70
+ else
71
+ STDOUT.puts request['text']
72
+ end
73
+ [200, {}, request['text']]
74
+ end
75
+
76
+ def session_id
77
+ params["session_id"] || request.cookies["session_id"]
78
+ end
79
+
80
+ def do_post(selenium_browser_start_command)
81
+ selenium_session = Models::SeleniumSession.new({
82
+ :spec_url => request['spec_url'].to_s == "" ? full_spec_suite_url : request['spec_url'],
83
+ :selenium_browser_start_command => selenium_browser_start_command,
84
+ :selenium_host => request['selenium_host'].to_s == "" ? 'localhost' : request['selenium_host'].to_s,
85
+ :selenium_port => request['selenium_port'].to_s == "" ? 4444 : Integer(request['selenium_port'])
86
+ })
87
+ selenium_session.start
88
+
89
+ body = "session_id=#{selenium_session.session_id}"
90
+ [
91
+ 200,
92
+ {
93
+ "Content-Length" => body.length
94
+ },
95
+ body
96
+ ]
97
+ end
98
+
99
+ def full_spec_suite_url
100
+ "#{Configuration.root_url}/specs"
101
+ end
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,63 @@
1
+ module JsTestCore
2
+ module Resources
3
+ class SpecFile < ::JsTestCore::Resources::File
4
+ class << self
5
+ def spec_representation_class
6
+ @spec_representation_class ||= JsTestCore::Representations::Spec
7
+ end
8
+
9
+ attr_writer :spec_representation_class
10
+ end
11
+
12
+ map "/specs"
13
+
14
+ get "/?" do
15
+ do_get
16
+ end
17
+
18
+ get "*" do
19
+ do_get
20
+ end
21
+
22
+ protected
23
+
24
+ def do_get
25
+ if ::File.exists?(absolute_path)
26
+ if ::File.directory?(absolute_path)
27
+ spec_files = ::Dir["#{absolute_path}/**/*_spec.js"].map do |file|
28
+ ["#{relative_path}#{file.gsub(absolute_path, "")}"]
29
+ end
30
+ get_generated_spec(absolute_path, spec_files)
31
+ else
32
+ super
33
+ end
34
+ elsif ::File.exists?("#{absolute_path}.js")
35
+ get_generated_spec("#{absolute_path}.js", ["#{relative_path}.js"])
36
+ else
37
+ pass
38
+ end
39
+ end
40
+
41
+ def get_generated_spec(real_path, spec_files)
42
+ html = render_spec(spec_files)
43
+ [
44
+ 200,
45
+ {
46
+ 'Content-Type' => "text/html",
47
+ 'Last-Modified' => ::File.mtime(real_path).rfc822,
48
+ 'Content-Length' => html.length
49
+ },
50
+ html
51
+ ]
52
+ end
53
+
54
+ def render_spec(spec_files)
55
+ self.class.spec_representation_class.new(:spec_files => spec_files).to_s
56
+ end
57
+
58
+ def absolute_path
59
+ @absolute_path ||= ::File.expand_path("#{spec_root_path}#{relative_path.gsub(%r{^/specs}, "")}")
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,11 @@
1
+ module JsTestCore
2
+ module Resources
3
+ class WebRoot < Resource
4
+ map "/"
5
+
6
+ get("") do
7
+ [200, {}, "<html><head></head><body>Welcome to the Js Test Server. Click the following link to run you <a href=/specs>spec suite</a>.</body></html>"]
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,48 @@
1
+ module JsTestCore
2
+ class SeleniumServerConfiguration
3
+ attr_reader :parameters
4
+
5
+ class << self
6
+ def query_string_from(*args, &block)
7
+ new(*args, &block).query_string
8
+ end
9
+ end
10
+
11
+ def initialize(parameters={})
12
+ @parameters = parameters
13
+ end
14
+
15
+
16
+ def query_string
17
+ parts = [selenium_browser_start_command, selenium_host, selenium_port]
18
+ parts << spec_url if url
19
+ parts.join('&')
20
+ end
21
+
22
+ private
23
+
24
+ def selenium_browser_start_command
25
+ "selenium_browser_start_command=#{parameter_or_default_for(:selenium_browser_start_command, '*firefox')}"
26
+ end
27
+
28
+ def selenium_host
29
+ "selenium_host=#{parameter_or_default_for(:selenium_host, 'localhost')}"
30
+ end
31
+
32
+ def selenium_port
33
+ "selenium_port=#{parameter_or_default_for(:selenium_port, 4444)}"
34
+ end
35
+
36
+ def spec_url
37
+ "spec_url=#{url}"
38
+ end
39
+
40
+ def url
41
+ parameters[:spec_url]
42
+ end
43
+
44
+ def parameter_or_default_for(parameter_name, default = nil)
45
+ CGI.escape((parameters[parameter_name] || default).to_s)
46
+ end
47
+ end
48
+ end
@@ -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,6 @@
1
+ require("/javascripts/foo");
2
+ describe("A passing spec", {
3
+ 'passes': function() {
4
+ value_of(Foo.value).should_be(true);
5
+ }
6
+ })
@@ -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,5 @@
1
+ describe("A failing spec", {
2
+ 'fails': function() {
3
+ value_of(true).should_be(false);
4
+ }
5
+ })
@@ -0,0 +1,6 @@
1
+ require("/javascripts/foo");
2
+ describe("A failing spec in foo", {
3
+ 'fails': function() {
4
+ value_of(Foo.value).should_be(false);
5
+ }
6
+ })
@@ -0,0 +1,6 @@
1
+ require("/javascripts/foo");
2
+ describe("A passing spec", {
3
+ 'passes': function() {
4
+ value_of(Foo.value).should_be(true);
5
+ }
6
+ })
@@ -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 :core_path, :spec_root_path, :public_path, :server, :connection
19
+ before(:all) do
20
+ dir = File.dirname(__FILE__)
21
+ @core_path = File.expand_path("#{LIBRARY_ROOT_DIR}/spec/example_core")
22
+ @spec_root_path = File.expand_path("#{LIBRARY_ROOT_DIR}/spec/example_specs")
23
+ @public_path = File.expand_path("#{LIBRARY_ROOT_DIR}/spec/example_public")
24
+ stub(Thread).start.yields
25
+ end
26
+
27
+ before(:each) do
28
+ JsTestCore::Configuration.instance.spec_root_path = spec_root_path
29
+ JsTestCore::Configuration.instance.public_path = public_path
30
+ JsTestCore::Configuration.instance.core_path = core_path
31
+ end
32
+
33
+ def app
34
+ Sinatra::Application
35
+ end
36
+ end
@@ -0,0 +1,27 @@
1
+ class FakeSeleniumDriver
2
+ SESSION_ID = "DEADBEEF"
3
+ attr_reader :session_id
4
+
5
+ def initialize
6
+ @session_id = nil
7
+ end
8
+
9
+ def start
10
+ @session_id = SESSION_ID
11
+ end
12
+
13
+ def stop
14
+ @session_id = nil
15
+ end
16
+
17
+ def open(url)
18
+ end
19
+
20
+ def create_cookie(key_value, options="")
21
+
22
+ end
23
+
24
+ def session_started?
25
+ !!@session_id
26
+ end
27
+ end