screw-unit 0.3.1 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. data/CHANGES +7 -1
  2. data/core/CHANGES +10 -0
  3. data/core/example/models/man.js +2 -2
  4. data/core/lib/jquery.print.js +2 -2
  5. data/core/lib/screw.behaviors.js +3 -2
  6. data/core/lib/screw.builder.js +15 -15
  7. data/core/lib/screw.css +2 -2
  8. data/core/lib/screw.events.js +3 -2
  9. data/core/lib/screw.matchers.js +53 -11
  10. data/core/spec/behaviors_spec.js +11 -1
  11. data/core/spec/matchers_spec.js +144 -9
  12. data/core/spec/print_spec.js +14 -8
  13. data/lib/screw_unit/resources/spec.rb +66 -3
  14. data/spec/functional/functional_spec_helper.rb +1 -1
  15. data/spec/unit/js_test_core/specs/spec_dir_spec.rb +7 -8
  16. data/spec/unit/js_test_core/specs/spec_file_spec.rb +5 -6
  17. data/spec/unit/unit_spec_helper.rb +1 -3
  18. data/vendor/js-test-core/CHANGES +5 -0
  19. data/vendor/js-test-core/Rakefile +1 -1
  20. data/vendor/js-test-core/lib/js_test_core/client.rb +19 -16
  21. data/vendor/js-test-core/lib/js_test_core/resources.rb +2 -2
  22. data/vendor/js-test-core/lib/js_test_core/resources/file.rb +9 -18
  23. data/vendor/js-test-core/lib/js_test_core/resources/runner.rb +17 -15
  24. data/vendor/js-test-core/lib/js_test_core/resources/{suite.rb → session.rb} +8 -4
  25. data/vendor/js-test-core/lib/js_test_core/resources/{suite_finish.rb → session_finish.rb} +5 -5
  26. data/vendor/js-test-core/lib/js_test_core/resources/web_root.rb +6 -3
  27. data/vendor/js-test-core/spec/unit/js_test_core/client_spec.rb +22 -21
  28. data/vendor/js-test-core/spec/unit/js_test_core/resources/file_spec.rb +0 -38
  29. data/vendor/js-test-core/spec/unit/js_test_core/resources/runners/runner_spec.rb +83 -63
  30. data/vendor/js-test-core/spec/unit/js_test_core/resources/{suite_finish_spec.rb → session_finish_spec.rb} +15 -18
  31. data/vendor/js-test-core/spec/unit/js_test_core/resources/session_spec.rb +82 -0
  32. data/vendor/js-test-core/spec/unit/js_test_core/resources/specs/spec_dir_spec.rb +3 -3
  33. data/vendor/js-test-core/spec/unit/unit_spec_helper.rb +37 -10
  34. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/resource.rb +4 -0
  35. metadata +88 -89
  36. data/core/lib/screw.assets.js +0 -36
  37. data/core/lib/screw.server.js +0 -21
  38. data/vendor/js-test-core/spec/unit/js_test_core/resources/suite_spec.rb +0 -86
@@ -48,9 +48,9 @@ Screw.Unit(function() {
48
48
 
49
49
  describe('when given a function', function() {
50
50
  it("returns the function's signature", function() {
51
- expect($.print(function() {})).to(equal, 'function ()');
52
- expect($.print(function foo() {})).to(equal, 'function foo()');
53
- expect($.print(function foo(bar) {})).to(equal, 'function foo(bar)');
51
+ expect($.print(function() {})).to(match, /function\s*\(\)/);
52
+ expect($.print(function foo() {})).to(match, /function\s*foo\(\)/);
53
+ expect($.print(function foo(bar) {})).to(match, /function\s*foo\(bar\)/);
54
54
  });
55
55
  });
56
56
 
@@ -66,16 +66,22 @@ Screw.Unit(function() {
66
66
  });
67
67
  });
68
68
 
69
+ describe('when given 0', function() {
70
+ it('should print the string "0"', function() {
71
+ expect($.print(0)).to(equal, '0');
72
+ });
73
+ });
74
+
69
75
  describe('when given an element', function() {
70
76
  it("returns the string representation of the element", function() {
71
- expect($.print($('<div>').get(0))).to(equal, '<div>');
72
- expect($.print($('<div foo="bar">').get(0))).to(equal, '<div>');
73
- expect($.print($('<div class="foo" id="bar">').get(0))).to(equal, '<div class="foo" id="bar">');
77
+ expect($.print($('<div></div>').get(0))).to(equal, '<div>');
78
+ expect($.print($('<div foo="bar"></div>').get(0))).to(equal, '<div>');
79
+ expect($.print($('<div class="foo" id="bar"></div>').get(0))).to(equal, '<div class="foo" id="bar">');
74
80
  });
75
81
 
76
82
  describe('when the element is an img', function() {
77
83
  it('prints out the img src attribute', function() {
78
- expect($.print($('<img src="test.png">'))).to(match, /<img src=".+?test.png">/);
84
+ expect($.print($('<img src="test.png"/>'))).to(match, /<img src=".+?test.png">/);
79
85
  })
80
86
  });
81
87
  });
@@ -118,7 +124,7 @@ Screw.Unit(function() {
118
124
 
119
125
  describe('when given a jQuery', function() {
120
126
  it("returns the printed array of elements engirthed in '$()'", function() {
121
- expect($.print($('<div>'))).to(equal, '$([ <div> ])');
127
+ expect($.print($('<div></div>'))).to(equal, '$([ <div> ])');
122
128
  });
123
129
  });
124
130
 
@@ -2,6 +2,7 @@ module ScrewUnit
2
2
  module Resources
3
3
  module Spec
4
4
  def get
5
+ # TODO: BT/JN - Remove the Screw.Assets when we implement rendering of script and link tags from yml files.
5
6
  html = <<-HTML
6
7
  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
7
8
  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
@@ -15,9 +16,71 @@ module ScrewUnit
15
16
  <script src="/core/screw.matchers.js"></script>
16
17
  <script src="/core/screw.events.js"></script>
17
18
  <script src="/core/screw.behaviors.js"></script>
18
- <script src="/core/screw.assets.js"></script>
19
- <script src="/core/screw.server.js"></script>
20
- <link rel="stylesheet" href="/core/screw.css">
19
+ <script type="text/javascript">
20
+ (function($) {
21
+ Screw.Assets = {};
22
+ Screw.Assets.use_cache_buster = false; // TODO: NS/CTI - make this configurable from the UI.
23
+ var required_paths = [];
24
+ var included_stylesheets = {};
25
+ var cache_buster = parseInt(new Date().getTime()/(1*1000));
26
+
27
+ function tag(name, attributes) {
28
+ var html = "<" + name;
29
+ for(var attribute in attributes) {
30
+ html += (" " + attribute + "='" + attributes[attribute]) + "'";
31
+ };
32
+ html += "></";
33
+ html += name;
34
+ html += ">";
35
+ return html;
36
+ }
37
+
38
+ Screw.Assets.require = function(javascript_path, onload) {
39
+ if(!required_paths[javascript_path]) {
40
+ var full_path = javascript_path + ".js";
41
+ if (Screw.Assets.use_cache_buster) {
42
+ full_path += '?' + cache_buster;
43
+ }
44
+ document.write(tag("script", {src: full_path, type: 'text/javascript'}));
45
+ if(onload) {
46
+ var scripts = document.getElementsByTagName('script');
47
+ scripts[scripts.length-1].onload = onload;
48
+ }
49
+ required_paths[javascript_path] = true;
50
+ }
51
+ };
52
+
53
+ Screw.Assets.stylesheet = function(stylesheet_path) {
54
+ if(!included_stylesheets[stylesheet_path]) {
55
+ var full_path = stylesheet_path + ".css";
56
+ if(Screw.Assets.use_cache_buster) {
57
+ full_path += '?' + cache_buster;
58
+ }
59
+ document.write(tag("link", {rel: 'stylesheet', type: 'text/css', href: full_path}));
60
+ included_stylesheets[stylesheet_path] = true;
61
+ }
62
+ };
63
+
64
+ window.require = Screw.Assets.require;
65
+ window.stylesheet = Screw.Assets.stylesheet;
66
+ })(jQuery);
67
+
68
+ (function($) {
69
+ var ajax = $.ajax;
70
+ $(Screw).bind('after', function() {
71
+ var error_text = $(".error").map(function(i, element) {
72
+ return element.innerHTML;
73
+ }).get().join("\\n");
74
+
75
+ ajax({
76
+ type: "POST",
77
+ url: '/session/finish',
78
+ data: {"text": error_text}
79
+ });
80
+ });
81
+ })(jQuery);
82
+ </script>
83
+ <link rel="stylesheet" href="/core/screw.css" />
21
84
  HTML
22
85
  spec_files.each do |file|
23
86
  html << %{<script type="text/javascript" src="#{file.relative_path}"></script>\n}
@@ -26,7 +26,7 @@ module WaitFor
26
26
  end
27
27
  end
28
28
 
29
- module Spec::Example::ExampleMethods
29
+ class Spec::ExampleGroup
30
30
  include WaitFor
31
31
  attr_reader :spec_root_path, :implementation_root_path, :public_path
32
32
  before(:all) do
@@ -19,17 +19,16 @@ module JsTestCore
19
19
  end
20
20
 
21
21
  it "returns script tags for each test javascript file" do
22
- doc.at("script[@src='/specs/failing_spec.js']").should exist
23
- doc.at("script[@src='/specs/foo/failing_spec.js']").should exist
24
- doc.at("script[@src='/specs/foo/passing_spec.js']").should exist
22
+ doc.at("script[@src='/specs/failing_spec.js']").should_not be_nil
23
+ doc.at("script[@src='/specs/foo/failing_spec.js']").should_not be_nil
24
+ doc.at("script[@src='/specs/foo/passing_spec.js']").should_not be_nil
25
25
  end
26
26
 
27
27
  it "returns the screw unit template" do
28
- doc.at("link[@href='/core/screw.css']").should exist
29
- doc.at("script[@src='/core/screw.builder.js']").should exist
30
- doc.at("script[@src='/core/screw.events.js']").should exist
31
- doc.at("script[@src='/core/screw.behaviors.js']").should exist
32
- doc.at("script[@src='/core/screw.assets.js']").should exist
28
+ doc.at("link[@href='/core/screw.css']").should_not be_nil
29
+ doc.at("script[@src='/core/screw.builder.js']").should_not be_nil
30
+ doc.at("script[@src='/core/screw.events.js']").should_not be_nil
31
+ doc.at("script[@src='/core/screw.behaviors.js']").should_not be_nil
33
32
  doc.at("body/#screw_unit_content").should_not be_nil
34
33
  end
35
34
  end
@@ -17,15 +17,14 @@ module JsTestCore
17
17
  end
18
18
 
19
19
  it "returns script tags for the test javascript file" do
20
- doc.at("script[@src='/specs/failing_spec.js']").should exist
20
+ doc.at("script[@src='/specs/failing_spec.js']").should_not be_nil
21
21
  end
22
22
 
23
23
  it "returns the screw unit template" do
24
- doc.at("link[@href='/core/screw.css']").should exist
25
- doc.at("script[@src='/core/screw.builder.js']").should exist
26
- doc.at("script[@src='/core/screw.events.js']").should exist
27
- doc.at("script[@src='/core/screw.behaviors.js']").should exist
28
- doc.at("script[@src='/core/screw.assets.js']").should exist
24
+ doc.at("link[@href='/core/screw.css']").should_not be_nil
25
+ doc.at("script[@src='/core/screw.builder.js']").should_not be_nil
26
+ doc.at("script[@src='/core/screw.events.js']").should_not be_nil
27
+ doc.at("script[@src='/core/screw.behaviors.js']").should_not be_nil
29
28
  doc.at("body/#screw_unit_content").should_not be_nil
30
29
  end
31
30
  end
@@ -22,7 +22,7 @@ module Spec
22
22
  end
23
23
  end
24
24
 
25
- class Spec::Example::ExampleGroup
25
+ class Spec::ExampleGroup
26
26
  class << self
27
27
  def thin_logging
28
28
  @thin_logging = true if @thin_logging.nil?
@@ -31,9 +31,7 @@ class Spec::Example::ExampleGroup
31
31
 
32
32
  attr_writer :thin_logging
33
33
  end
34
- end
35
34
 
36
- module Spec::Example::ExampleMethods
37
35
  attr_reader :spec_root_path, :implementation_root_path, :public_path, :server, :connection
38
36
  before(:all) do
39
37
  dir = File.dirname(__FILE__)
@@ -1,4 +1,9 @@
1
1
  0.2.0
2
+ - Renamed Suite to Session to follow Selenium conventions
3
+ - Renamed SuiteFinish to SessionFinish to follow Selenium conventions
4
+ - Added /session, which uses the session_id cookie to derive the current session.
5
+ - Added /session/finished to be used to simplify client/server interactions.
6
+ - Remove File caching because it doesn't cause a noticable performance benefit over a local network and because it sometimes doesn't write over stale files.
2
7
  - Client accepts selenium_browser_start_command parameter, which allows the user to parameterize the selenium_browser_start_command
3
8
  - Added support for running specs in Internet Explorer via POST /runners/iexplore
4
9
  - Resource file download performance improvements via caching and chunked sending
@@ -26,7 +26,7 @@ def run_suite
26
26
  end
27
27
 
28
28
  PKG_NAME = "js_test_core"
29
- PKG_VERSION = "0.1.1"
29
+ PKG_VERSION = "0.2.0"
30
30
  PKG_FILES = FileList[
31
31
  '[A-Z]*',
32
32
  '*.rb',
@@ -6,7 +6,7 @@ module JsTestCore
6
6
  class InvalidStatusResponse < ClientException
7
7
  end
8
8
 
9
- class SuiteNotFound < ClientException
9
+ class SessionNotFound < ClientException
10
10
  end
11
11
 
12
12
  class << self
@@ -44,7 +44,7 @@ module JsTestCore
44
44
  end
45
45
  end
46
46
 
47
- attr_reader :parameters, :query_string, :http, :suite_start_response, :last_poll_status, :last_poll_reason, :last_poll
47
+ attr_reader :parameters, :query_string, :http, :session_start_response, :last_poll_status, :last_poll_reason, :last_poll
48
48
  def initialize(parameters)
49
49
  @parameters = parameters
50
50
  @query_string = SeleniumServerConfiguration.query_string_from(parameters)
@@ -53,7 +53,7 @@ module JsTestCore
53
53
  def run
54
54
  Net::HTTP.start(DEFAULT_HOST, DEFAULT_PORT) do |@http|
55
55
  start_runner
56
- wait_for_suite_to_finish
56
+ wait_for_session_to_finish
57
57
  end
58
58
  report_result
59
59
  end
@@ -68,19 +68,22 @@ module JsTestCore
68
68
 
69
69
  protected
70
70
  def start_runner
71
- @suite_start_response = http.post('/runners', query_string)
71
+ @session_start_response = http.post('/runners', query_string)
72
72
  end
73
73
 
74
- def wait_for_suite_to_finish
75
- poll while suite_not_completed?
74
+ def wait_for_session_to_finish
75
+ while session_not_completed?
76
+ poll
77
+ sleep 0.25
78
+ end
76
79
  end
77
80
 
78
81
  def report_result
79
82
  case last_poll_status
80
- when Resources::Suite::SUCCESSFUL_COMPLETION
83
+ when Resources::Session::SUCCESSFUL_COMPLETION
81
84
  STDOUT.puts "SUCCESS"
82
85
  true
83
- when Resources::Suite::FAILURE_COMPLETION
86
+ when Resources::Session::FAILURE_COMPLETION
84
87
  STDOUT.puts "FAILURE"
85
88
  STDOUT.puts last_poll_reason
86
89
  false
@@ -89,26 +92,26 @@ module JsTestCore
89
92
  end
90
93
  end
91
94
 
92
- def suite_not_completed?
93
- last_poll_status.nil? || last_poll_status == Resources::Suite::RUNNING
95
+ def session_not_completed?
96
+ last_poll_status.nil? || last_poll_status == Resources::Session::RUNNING
94
97
  end
95
98
 
96
99
  def poll
97
- @last_poll = http.get("/suites/#{suite_id}")
98
- ensure_suite_exists!
100
+ @last_poll = http.get("/sessions/#{session_id}")
101
+ ensure_session_exists!
99
102
  parts = parts_from_query(last_poll.body)
100
103
  @last_poll_status = parts['status']
101
104
  @last_poll_reason = parts['reason']
102
105
  end
103
106
 
104
- def ensure_suite_exists!
107
+ def ensure_session_exists!
105
108
  if (400..499).include?(Integer(last_poll.code))
106
- raise SuiteNotFound, "Could not find suite with id #{suite_id}"
109
+ raise SessionNotFound, "Could not find session with id #{session_id}"
107
110
  end
108
111
  end
109
112
 
110
- def suite_id
111
- @suite_id ||= parts_from_query(suite_start_response.body)['suite_id']
113
+ def session_id
114
+ @session_id ||= parts_from_query(session_start_response.body)['session_id']
112
115
  end
113
116
  end
114
117
  end
@@ -6,5 +6,5 @@ require "#{dir}/resources/file_not_found"
6
6
  require "#{dir}/resources/specs/spec_file"
7
7
  require "#{dir}/resources/specs/spec_dir"
8
8
  require "#{dir}/resources/web_root"
9
- require "#{dir}/resources/suite"
10
- require "#{dir}/resources/suite_finish"
9
+ require "#{dir}/resources/session"
10
+ require "#{dir}/resources/session_finish"
@@ -17,24 +17,15 @@ module JsTestCore
17
17
  content_type = MIME_TYPES[extension] || 'text/html'
18
18
 
19
19
  connection.terminate_after_sending do
20
- if !rack_request.env["HTTP_IF_MODIFIED_SINCE"].to_s.empty? && Time.parse(rack_request.env["HTTP_IF_MODIFIED_SINCE"]) >= ::File.mtime(absolute_path)
21
- connection.send_head(
22
- 304,
23
- 'Content-Type' => content_type,
24
- 'Last-Modified' => ::File.mtime(absolute_path).rfc822,
25
- 'Content-Length' => 0
26
- )
27
- else
28
- connection.send_head(
29
- 200,
30
- 'Content-Type' => content_type,
31
- 'Last-Modified' => ::File.mtime(absolute_path).rfc822,
32
- 'Content-Length' => ::File.size(absolute_path)
33
- )
34
- ::File.open(absolute_path) do |file|
35
- while !file.eof?
36
- connection.send_data(file.read(1024))
37
- end
20
+ connection.send_head(
21
+ 200,
22
+ 'Content-Type' => content_type,
23
+ 'Last-Modified' => ::File.mtime(absolute_path).rfc822,
24
+ 'Content-Length' => ::File.size(absolute_path)
25
+ )
26
+ ::File.open(absolute_path) do |file|
27
+ while !file.eof?
28
+ connection.send_data(file.read(1024))
38
29
  end
39
30
  end
40
31
  end
@@ -18,7 +18,7 @@ module JsTestCore
18
18
  end
19
19
 
20
20
  def post
21
- spec_url = rack_request['spec_url'].to_s == "" ? spec_suite_url : rack_request['spec_url']
21
+ spec_url = rack_request['spec_url'].to_s == "" ? full_spec_suite_url : rack_request['spec_url']
22
22
  parsed_spec_url = URI.parse(spec_url)
23
23
  selenium_host = rack_request['selenium_host'].to_s == "" ? 'localhost' : rack_request['selenium_host'].to_s
24
24
  selenium_port = rack_request['selenium_port'].to_s == "" ? 4444 : Integer(rack_request['selenium_port'])
@@ -34,17 +34,19 @@ module JsTestCore
34
34
  rescue Errno::ECONNREFUSED => e
35
35
  raise Errno::ECONNREFUSED, "Cannot connect to Selenium Server at #{http_address}. To start the selenium server, run `selenium`."
36
36
  end
37
- Thread.start do
38
- driver.open(spec_url)
39
- end
40
37
  runner = Runner.new(:driver => driver)
41
38
  Runner.register(runner)
39
+ Thread.start do
40
+ driver.open("/")
41
+ driver.create_cookie("session_id=#{runner.session_id}")
42
+ driver.open(parsed_spec_url.path)
43
+ end
42
44
  connection.send_head
43
- connection.send_body("suite_id=#{runner.suite_id}")
45
+ connection.send_body("session_id=#{runner.session_id}")
44
46
  end
45
47
 
46
48
  protected
47
- def spec_suite_url
49
+ def full_spec_suite_url
48
50
  "#{Server.root_url}/specs"
49
51
  end
50
52
  end
@@ -54,14 +56,14 @@ module JsTestCore
54
56
  instances[id.to_s]
55
57
  end
56
58
 
57
- def finalize(suite_id, text)
58
- if runner = find(suite_id)
59
+ def finalize(session_id, text)
60
+ if runner = find(session_id)
59
61
  runner.finalize(text)
60
62
  end
61
63
  end
62
64
 
63
65
  def register(runner)
64
- instances[runner.suite_id] = runner
66
+ instances[runner.session_id] = runner
65
67
  end
66
68
 
67
69
  protected
@@ -72,7 +74,7 @@ module JsTestCore
72
74
 
73
75
  include FileUtils
74
76
  property :driver
75
- attr_reader :profile_dir, :suite_run_result
77
+ attr_reader :profile_dir, :session_run_result
76
78
 
77
79
  def after_initialize
78
80
  profile_base = "#{::Dir.tmpdir}/js_test_core/#{self.class.name}"
@@ -80,24 +82,24 @@ module JsTestCore
80
82
  @profile_dir = "#{profile_base}/#{Time.now.to_i}"
81
83
  end
82
84
 
83
- def finalize(suite_run_result)
85
+ def finalize(session_run_result)
84
86
  driver.stop
85
- @suite_run_result = suite_run_result
87
+ @session_run_result = session_run_result.to_s
86
88
  end
87
89
 
88
90
  def running?
89
- suite_run_result.nil?
91
+ driver.session_started?
90
92
  end
91
93
 
92
94
  def successful?
93
- !running? && suite_run_result.empty?
95
+ !running? && session_run_result.empty?
94
96
  end
95
97
 
96
98
  def failed?
97
99
  !running? && !successful?
98
100
  end
99
101
 
100
- def suite_id
102
+ def session_id
101
103
  driver.session_id
102
104
  end
103
105
  end