js_spec 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. data/CHANGES +3 -0
  2. data/Rakefile +3 -2
  3. data/vendor/js-test-core/CHANGES +15 -0
  4. data/vendor/js-test-core/README +12 -0
  5. data/vendor/js-test-core/Rakefile +72 -0
  6. data/vendor/js-test-core/lib/js_test_core.rb +38 -0
  7. data/vendor/js-test-core/lib/js_test_core/client.rb +114 -0
  8. data/vendor/js-test-core/lib/js_test_core/extensions.rb +3 -0
  9. data/vendor/js-test-core/lib/js_test_core/extensions/time.rb +6 -0
  10. data/vendor/js-test-core/lib/js_test_core/rack.rb +2 -0
  11. data/vendor/js-test-core/lib/js_test_core/rack/commonlogger.rb +5 -0
  12. data/vendor/js-test-core/lib/js_test_core/rails_server.rb +22 -0
  13. data/vendor/js-test-core/lib/js_test_core/resources.rb +10 -0
  14. data/vendor/js-test-core/lib/js_test_core/resources/dir.rb +67 -0
  15. data/vendor/js-test-core/lib/js_test_core/resources/file.rb +40 -0
  16. data/vendor/js-test-core/lib/js_test_core/resources/file_not_found.rb +11 -0
  17. data/vendor/js-test-core/lib/js_test_core/resources/runner.rb +105 -0
  18. data/vendor/js-test-core/lib/js_test_core/resources/specs/spec_dir.rb +46 -0
  19. data/vendor/js-test-core/lib/js_test_core/resources/specs/spec_file.rb +17 -0
  20. data/vendor/js-test-core/lib/js_test_core/resources/suite.rb +40 -0
  21. data/vendor/js-test-core/lib/js_test_core/resources/suite_finish.rb +17 -0
  22. data/vendor/js-test-core/lib/js_test_core/resources/web_root.rb +63 -0
  23. data/vendor/js-test-core/lib/js_test_core/selenium.rb +2 -0
  24. data/vendor/js-test-core/lib/js_test_core/selenium/selenium_driver.rb +5 -0
  25. data/vendor/js-test-core/lib/js_test_core/selenium_server_configuration.rb +48 -0
  26. data/vendor/js-test-core/lib/js_test_core/server.rb +50 -0
  27. data/vendor/js-test-core/lib/js_test_core/thin.rb +3 -0
  28. data/vendor/js-test-core/lib/js_test_core/thin/backends/js_test_core_server.rb +9 -0
  29. data/vendor/js-test-core/lib/js_test_core/thin/js_test_core_connection.rb +8 -0
  30. data/vendor/js-test-core/spec/example_core/JsTestCore.css +0 -0
  31. data/vendor/js-test-core/spec/example_core/JsTestCore.js +0 -0
  32. data/vendor/js-test-core/spec/example_public/favicon.ico +0 -0
  33. data/vendor/js-test-core/spec/example_public/javascripts/foo.js +3 -0
  34. data/vendor/js-test-core/spec/example_public/javascripts/large_file.js +59 -0
  35. data/vendor/js-test-core/spec/example_public/javascripts/subdir/bar.js +1 -0
  36. data/vendor/js-test-core/spec/example_public/robots.txt +0 -0
  37. data/vendor/js-test-core/spec/example_public/stylesheets/example.css +3 -0
  38. data/vendor/js-test-core/spec/example_specs/failing_spec.js +5 -0
  39. data/vendor/js-test-core/spec/example_specs/foo/failing_spec.js +6 -0
  40. data/vendor/js-test-core/spec/example_specs/foo/passing_spec.js +6 -0
  41. data/vendor/js-test-core/spec/spec_suite.rb +2 -0
  42. data/vendor/js-test-core/spec/specs/failing_spec.js +0 -0
  43. data/vendor/js-test-core/spec/unit/js_test_core/client_spec.rb +166 -0
  44. data/vendor/js-test-core/spec/unit/js_test_core/rails_server_spec.rb +45 -0
  45. data/vendor/js-test-core/spec/unit/js_test_core/resources/dir_spec.rb +52 -0
  46. data/vendor/js-test-core/spec/unit/js_test_core/resources/file_not_found_spec.rb +16 -0
  47. data/vendor/js-test-core/spec/unit/js_test_core/resources/file_spec.rb +90 -0
  48. data/vendor/js-test-core/spec/unit/js_test_core/resources/runners/runner_spec.rb +283 -0
  49. data/vendor/js-test-core/spec/unit/js_test_core/resources/specs/spec_dir_spec.rb +105 -0
  50. data/vendor/js-test-core/spec/unit/js_test_core/resources/specs/spec_file_spec.rb +42 -0
  51. data/vendor/js-test-core/spec/unit/js_test_core/resources/suite_finish_spec.rb +82 -0
  52. data/vendor/js-test-core/spec/unit/js_test_core/resources/suite_spec.rb +86 -0
  53. data/vendor/js-test-core/spec/unit/js_test_core/resources/web_root_spec.rb +32 -0
  54. data/vendor/js-test-core/spec/unit/js_test_core/selenium_server_configuration_spec.rb +49 -0
  55. data/vendor/js-test-core/spec/unit/js_test_core/server_spec.rb +117 -0
  56. data/vendor/js-test-core/spec/unit/thin/js_test_core_connection_spec.rb +6 -0
  57. data/vendor/js-test-core/spec/unit/unit_spec_helper.rb +134 -0
  58. data/vendor/js-test-core/spec/unit_suite.rb +10 -0
  59. data/vendor/js-test-core/vendor/thin-rest/CHANGES +2 -0
  60. data/vendor/js-test-core/vendor/thin-rest/README +0 -0
  61. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest.rb +9 -0
  62. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/connection.rb +116 -0
  63. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/extensions.rb +3 -0
  64. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/extensions/object.rb +21 -0
  65. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/resource.rb +104 -0
  66. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/resource_invalid.rb +4 -0
  67. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/routing_error.rb +5 -0
  68. data/vendor/js-test-core/vendor/thin-rest/spec/spec_suite.rb +5 -0
  69. data/vendor/js-test-core/vendor/thin-rest/spec/thin_rest/connection_spec.rb +207 -0
  70. data/vendor/js-test-core/vendor/thin-rest/spec/thin_rest/resource_spec.rb +127 -0
  71. data/vendor/js-test-core/vendor/thin-rest/spec/thin_rest_spec_helper.rb +124 -0
  72. metadata +120 -17
@@ -0,0 +1,86 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../unit_spec_helper")
2
+
3
+ module JsTestCore
4
+ module Resources
5
+ describe Suite do
6
+ describe "GET /suites/:suite_id" do
7
+ attr_reader :driver, :suite_id
8
+
9
+ context "when there is no Runner with the :suite_id" do
10
+ it "responds with a 404" do
11
+ suite_id = "invalid_suite_id"
12
+ Runner.find(suite_id).should be_nil
13
+
14
+ mock(connection).send_head(404)
15
+ mock(connection).send_body("")
16
+
17
+ connection.receive_data("GET /suites/#{suite_id} HTTP/1.1\r\nHost: _\r\n\r\n")
18
+ end
19
+ end
20
+
21
+ context "when there is a Runner with the :suite_id" do
22
+ attr_reader :suite_runner
23
+ before do
24
+ @driver = "Selenium Driver"
25
+ @suite_id = "DEADBEEF"
26
+ stub(Selenium::SeleniumDriver).new('localhost', 4444, '*firefox', 'http://0.0.0.0:8080') do
27
+ driver
28
+ end
29
+
30
+ stub(driver).start
31
+ stub(driver).session_id {suite_id}
32
+ connection_that_starts_firefox = create_connection
33
+ stub(connection_that_starts_firefox).send_head
34
+ stub(connection_that_starts_firefox).send_body
35
+ connection_that_starts_firefox.receive_data("POST /runners/firefox HTTP/1.1\r\nHost: _\r\nContent-Length: 0\r\n\r\n")
36
+ @suite_runner = Runner.find(suite_id)
37
+ suite_runner.should be_running
38
+ end
39
+
40
+ context "when a Runner with the :suite_id is running" do
41
+ it "responds with a 200 and status=running" do
42
+ mock(connection).send_head
43
+ mock(connection).send_body("status=#{Resources::Suite::RUNNING}")
44
+
45
+ connection.receive_data("GET /suites/#{suite_id} HTTP/1.1\r\nHost: _\r\n\r\n")
46
+ end
47
+ end
48
+
49
+ context "when a Runner with the :suite_id has completed" do
50
+ context "when the suite has a status of 'success'" do
51
+ before do
52
+ stub(driver).stop
53
+ suite_runner.finalize("")
54
+ suite_runner.should be_successful
55
+ end
56
+
57
+ it "responds with a 200 and status=success" do
58
+ mock(connection).send_head
59
+ mock(connection).send_body("status=#{Resources::Suite::SUCCESSFUL_COMPLETION}")
60
+
61
+ connection.receive_data("GET /suites/#{suite_id} HTTP/1.1\r\nHost: _\r\n\r\n")
62
+ end
63
+ end
64
+
65
+ context "when the suite has a status of 'failure'" do
66
+ attr_reader :reason
67
+ before do
68
+ stub(driver).stop
69
+ @reason = "Failure stuff"
70
+ suite_runner.finalize(reason)
71
+ suite_runner.should be_failed
72
+ end
73
+
74
+ it "responds with a 200 and status=failure and reason" do
75
+ mock(connection).send_head
76
+ mock(connection).send_body("status=#{Resources::Suite::FAILURE_COMPLETION}&reason=#{reason}")
77
+
78
+ connection.receive_data("GET /suites/#{suite_id} HTTP/1.1\r\nHost: _\r\n\r\n")
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,32 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../unit_spec_helper")
2
+
3
+ module JsTestCore
4
+ module Resources
5
+ describe WebRoot do
6
+ attr_reader :web_root
7
+ before(:each) do
8
+ @web_root = WebRoot.new(:connection => connection, :public_path => public_path)
9
+ end
10
+
11
+ describe "GET /stylesheets" do
12
+ it "returns a page with a of files in the directory" do
13
+ mock(connection).send_head()
14
+ mock(connection).send_body(Regexp.new('<a href="example.css">example.css</a>'))
15
+
16
+ connection.receive_data("GET /stylesheets HTTP/1.1\r\nHost: _\r\n\r\n")
17
+ end
18
+ end
19
+
20
+ describe "GET /stylesheets/example.css" do
21
+ it "returns a page with a of files in the directory" do
22
+ path = "#{public_path}/stylesheets/example.css"
23
+ mock(connection).send_head(200, 'Content-Type' => "text/css", 'Content-Length' => ::File.size(path), 'Last-Modified' => ::File.mtime(path).rfc822)
24
+ mock(connection).send_data(::File.read(path))
25
+ stub(EventMachine).close_connection
26
+
27
+ connection.receive_data("GET /stylesheets/example.css HTTP/1.1\r\nHost: _\r\n\r\n")
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,49 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../unit_spec_helper")
2
+
3
+ module JsTestCore
4
+ describe SeleniumServerConfiguration do
5
+ describe '#query_string' do
6
+ context "when not passed explicit options" do
7
+ it "defaults selenium_browser_start_command to '*firefox' and selenium_host to 'localhost' and selenium_port to 4444 and ignores spec_url" do
8
+ configuration = SeleniumServerConfiguration.new
9
+ configuration.query_string.should include("selenium_browser_start_command=#{CGI.escape("*firefox")}")
10
+ configuration.query_string.should include("selenium_host=localhost")
11
+ configuration.query_string.should include("selenium_port=4444")
12
+ configuration.query_string.should_not include("spec_url")
13
+ end
14
+ end
15
+
16
+ context "when passed explicit options" do
17
+ attr_reader :configuration, :selenium_browser_start_command, :selenium_host, :selenium_port, :spec_url
18
+ before do
19
+ @selenium_browser_start_command = "*iexplore"
20
+ @selenium_host = "google.com"
21
+ @selenium_port = "4332"
22
+ @spec_url = "http://foobar.com/foo"
23
+ @configuration = SeleniumServerConfiguration.new(
24
+ :selenium_browser_start_command => selenium_browser_start_command,
25
+ :selenium_host => selenium_host,
26
+ :selenium_port => selenium_port,
27
+ :spec_url => spec_url
28
+ )
29
+ end
30
+
31
+ it "sets the selenium_browser_start_command option" do
32
+ configuration.query_string.should include("selenium_browser_start_command=#{CGI.escape(selenium_browser_start_command)}")
33
+ end
34
+
35
+ it "sets the selenium_host option" do
36
+ configuration.query_string.should include("selenium_host=#{selenium_host}")
37
+ end
38
+
39
+ it "sets the selenium_port option" do
40
+ configuration.query_string.should include("selenium_port=#{selenium_port}")
41
+ end
42
+
43
+ it "sets the spec_url option" do
44
+ configuration.query_string.should include("spec_url=#{spec_url}")
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,117 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../unit_spec_helper")
2
+
3
+ module JsTestCore
4
+ describe Server do
5
+ attr_reader :result
6
+
7
+ before do
8
+ @result = ""
9
+ stub(EventMachine).send_data do |signature, data, data_length|
10
+ @result << data
11
+ end
12
+ stub(EventMachine).close_connection
13
+ end
14
+
15
+ describe ".run" do
16
+ attr_reader :server_instance
17
+ before do
18
+ @server_instance = Server.instance
19
+ Server.instance = nil
20
+ end
21
+
22
+ it "instantiates an instance of Server and starts a Rack Thin handler" do
23
+ host = DEFAULT_HOST
24
+ port = DEFAULT_PORT
25
+
26
+ mock(EventMachine).run.yields
27
+ mock(EventMachine).start_server(host, port, ::Thin::JsTestCoreConnection)
28
+
29
+ Server.run(spec_root_path, implementation_root_path, public_path)
30
+ end
31
+
32
+ it "when passed a custom host and port, sets the host and port to the passed in value" do
33
+ host = 'foobar.com'
34
+ port = 80
35
+
36
+ mock(EventMachine).run.yields
37
+ mock(EventMachine).start_server(host, port, ::Thin::JsTestCoreConnection)
38
+
39
+ Server.run(spec_root_path, implementation_root_path, public_path, {:Host => host, :Port => port})
40
+ end
41
+ end
42
+
43
+ describe ".spec_root" do
44
+ it "returns the Dir " do
45
+ Server.spec_root_path.should == spec_root_path
46
+ end
47
+ end
48
+
49
+ describe ".spec_root_path" do
50
+ it "returns the absolute path of the specs root directory" do
51
+ Server.spec_root_path.should == spec_root_path
52
+ end
53
+ end
54
+
55
+ describe ".public_path" do
56
+ it "returns the expanded path of the public path" do
57
+ Server.public_path.should == public_path
58
+ end
59
+ end
60
+
61
+ describe ".core_path" do
62
+ it "returns the expanded path to the JsTestCore core directory" do
63
+ Server.core_path.should == core_path
64
+ end
65
+ end
66
+
67
+ describe ".implementation_root_path" do
68
+ it "returns the expanded path to the JsTestCore implementations directory" do
69
+ dir = ::File.dirname(__FILE__)
70
+ Server.implementation_root_path.should == implementation_root_path
71
+ end
72
+ end
73
+
74
+ describe "#call" do
75
+ describe "when there is an error" do
76
+ attr_reader :top_line_of_backtrace
77
+ before do
78
+ @top_line_of_backtrace = __LINE__ + 2
79
+ stub.instance_of(Resources::WebRoot).locate('somedir') do
80
+ raise "Foobar"
81
+ end
82
+ end
83
+
84
+ it "shows the full request path in the error message" do
85
+ error = nil
86
+ mock(connection).log_error(is_a(Exception)) do |error_arg|
87
+ error = error_arg
88
+ end
89
+
90
+ get('/somedir')
91
+ error.message.should =~ Regexp.new("/somedir")
92
+ end
93
+
94
+ it "uses the backtrace from where the original error was raised" do
95
+ error = nil
96
+ mock(connection).log_error(is_a(Exception)) do |error_arg|
97
+ error = error_arg
98
+ end
99
+
100
+ get('/somedir')
101
+ no_error = false
102
+ top_of_backtrace = error.backtrace.first.split(":")
103
+ backtrace_file = ::File.expand_path(top_of_backtrace[0])
104
+ backtrace_line = Integer(top_of_backtrace[1])
105
+ backtrace_file.should == __FILE__
106
+ backtrace_line.should == top_line_of_backtrace
107
+ end
108
+ end
109
+ end
110
+
111
+ describe "#root_url" do
112
+ it "returns the url of the site's root" do
113
+ server.root_url.should == "http://#{server.host}:#{server.port}"
114
+ end
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,6 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../unit_spec_helper")
2
+
3
+ module Thin
4
+ describe JsTestCoreConnection do
5
+ end
6
+ end
@@ -0,0 +1,134 @@
1
+ require "rubygems"
2
+ require "spec"
3
+
4
+ dir = File.dirname(__FILE__)
5
+ $LOAD_PATH.unshift File.expand_path("#{dir}/../../lib")
6
+ require "js_test_core"
7
+ require "hpricot"
8
+ require "guid"
9
+
10
+ Spec::Runner.configure do |config|
11
+ config.mock_with :rr
12
+ end
13
+
14
+ module Spec
15
+ module Matchers
16
+ class Exist
17
+ def matches?(actual)
18
+ @actual = actual
19
+ !@actual.nil?
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ class Spec::Example::ExampleGroup
26
+ class << self
27
+ def thin_logging
28
+ @thin_logging = true if @thin_logging.nil?
29
+ @thin_logging
30
+ end
31
+
32
+ attr_writer :thin_logging
33
+ end
34
+ end
35
+
36
+ class JsTestCoreTestDir < JsTestCore::Resources::Dir
37
+ def get
38
+
39
+ end
40
+ end
41
+
42
+ module Spec::Example::ExampleMethods
43
+ attr_reader :core_path, :spec_root_path, :implementation_root_path, :public_path, :server, :connection
44
+ before(:all) do
45
+ dir = File.dirname(__FILE__)
46
+ @core_path = File.expand_path("#{dir}/../example_core")
47
+ JsTestCore.core_path = core_path
48
+ @spec_root_path = File.expand_path("#{dir}/../example_specs")
49
+ @implementation_root_path = File.expand_path("#{dir}/../example_public/javascripts")
50
+ @public_path = File.expand_path("#{dir}/../example_public")
51
+ end
52
+
53
+ before(:each) do
54
+ JsTestCore::Server.instance = JsTestCore::Server.new(spec_root_path, implementation_root_path, public_path)
55
+ stub(EventMachine).run do
56
+ raise "You need to mock calls to EventMachine.run or the process will hang"
57
+ end
58
+ stub(EventMachine).start_server do
59
+ raise "You need to mock calls to EventMachine.start_server or the process will hang"
60
+ end
61
+ stub(EventMachine).send_data do
62
+ raise "Calls to EventMachine.send_data must be mocked or stubbed"
63
+ end
64
+ @connection = create_connection
65
+ stub(EventMachine).send_data {raise "EventMachine.send_data must be handled"}
66
+ stub(EventMachine).close_connection {raise "EventMachine.close_connection must be handled"}
67
+ @server = JsTestCore::Server.instance
68
+ Thin::Logging.silent = !self.class.thin_logging
69
+ Thin::Logging.debug = self.class.thin_logging
70
+ end
71
+
72
+ after(:each) do
73
+ JsTestCore::Resources::WebRoot.dispatch_strategy = nil
74
+ Thin::Logging.silent = true
75
+ Thin::Logging.debug = false
76
+ end
77
+
78
+ def create_connection(guid=Guid.new)
79
+ Thin::JsTestCoreConnection.new(Guid.new)
80
+ end
81
+
82
+ def get(url, params={})
83
+ request(:get, url, params)
84
+ end
85
+
86
+ def post(url, params={})
87
+ request(:post, url, params)
88
+ end
89
+
90
+ def put(url, params={})
91
+ request(:put, url, params)
92
+ end
93
+
94
+ def delete(url, params={})
95
+ request(:delete, url, params)
96
+ end
97
+
98
+ def env_for(method, url, params)
99
+ Rack::MockRequest.env_for(url, params.merge({:method => method.to_s.upcase, 'js_test_core.connection' => connection}))
100
+ end
101
+
102
+ def create_request(method, path, params={})
103
+ body = params.map do |key, value|
104
+ "#{URI.escape(key)}=#{URI.escape(value)}"
105
+ end.join("&")
106
+ connection.receive_data "#{method.to_s.upcase} #{path} HTTP/1.1\r\nHost: _\r\nContent-Length: #{body.length}\r\n\r\n#{body}"
107
+ connection.response
108
+ end
109
+ alias_method :request, :create_request
110
+
111
+ def spec_dir(relative_path="")
112
+ absolute_path = spec_root_path + relative_path
113
+ JsTestCore::Resources::Specs::SpecDir.new(:connection => connection, :absolute_path => absolute_path, :relative_path => "/specs#{relative_path}")
114
+ end
115
+
116
+ def contain_spec_file_with_correct_paths(path_relative_to_spec_root)
117
+ expected_absolute_path = spec_root_path + path_relative_to_spec_root
118
+ expected_relative_path = "/specs" + path_relative_to_spec_root
119
+
120
+ ::Spec::Matchers::SimpleMatcher.new(expected_relative_path) do |globbed_files|
121
+ file = globbed_files.find do |file|
122
+ file.absolute_path == expected_absolute_path
123
+ end
124
+ raise "Did not find file with absolute path of #{expected_absolute_path.inspect}" unless file
125
+ file.relative_path == expected_relative_path
126
+ end
127
+ end
128
+
129
+ def stub_send_data
130
+ stub(EventMachine).send_data do |signature, data, data_length|
131
+ data_length
132
+ end
133
+ end
134
+ end
@@ -0,0 +1,10 @@
1
+ class UnitSuite
2
+ def run
3
+ dir = File.dirname(__FILE__)
4
+ Dir["#{dir}/unit/**/*_spec.rb"].each do |file|
5
+ require file
6
+ end
7
+ end
8
+ end
9
+
10
+ UnitSuite.new.run
@@ -0,0 +1,2 @@
1
+ - Resource.property creates a reader that reads directly from the env hash
2
+ - Resource.property creates a writer that updates the env hash directly