js_test_core 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES +11 -0
- data/Rakefile +1 -1
- data/lib/js_test_core.rb +10 -2
- data/lib/js_test_core/client.rb +85 -18
- data/lib/js_test_core/extensions.rb +3 -0
- data/lib/js_test_core/extensions/time.rb +6 -0
- data/lib/js_test_core/resources.rb +4 -4
- data/lib/js_test_core/resources/dir.rb +22 -7
- data/lib/js_test_core/resources/file.rb +24 -16
- data/lib/js_test_core/resources/file_not_found.rb +11 -0
- data/lib/js_test_core/resources/runner.rb +107 -0
- data/lib/js_test_core/resources/session.rb +44 -0
- data/lib/js_test_core/resources/session_finish.rb +17 -0
- data/lib/js_test_core/resources/specs/spec_dir.rb +10 -14
- data/lib/js_test_core/resources/specs/spec_file.rb +1 -1
- data/lib/js_test_core/resources/web_root.rb +51 -39
- data/lib/js_test_core/selenium_server_configuration.rb +48 -0
- data/lib/js_test_core/server.rb +3 -64
- data/lib/js_test_core/thin/js_test_core_connection.rb +4 -38
- data/spec/unit/js_test_core/client_spec.rb +167 -0
- data/spec/unit/{js_spec → js_test_core}/rails_server_spec.rb +0 -0
- data/spec/unit/js_test_core/resources/dir_spec.rb +52 -0
- data/spec/unit/js_test_core/resources/file_not_found_spec.rb +16 -0
- data/spec/unit/js_test_core/resources/file_spec.rb +90 -0
- data/spec/unit/js_test_core/resources/runners/runner_spec.rb +303 -0
- data/spec/unit/js_test_core/resources/session_finish_spec.rb +79 -0
- data/spec/unit/js_test_core/resources/session_spec.rb +82 -0
- data/spec/unit/js_test_core/resources/specs/spec_dir_spec.rb +105 -0
- data/spec/unit/{js_spec → js_test_core}/resources/specs/spec_file_spec.rb +5 -5
- data/spec/unit/js_test_core/resources/web_root_spec.rb +32 -0
- data/spec/unit/js_test_core/selenium_server_configuration_spec.rb +49 -0
- data/spec/unit/{js_spec → js_test_core}/server_spec.rb +18 -32
- data/spec/unit/thin/js_test_core_connection_spec.rb +0 -86
- data/spec/unit/unit_spec_helper.rb +58 -22
- metadata +39 -33
- data/lib/js_test_core/resources/runners.rb +0 -15
- data/lib/js_test_core/resources/runners/firefox_runner.rb +0 -73
- data/lib/js_test_core/resources/suite.rb +0 -24
- data/lib/js_test_core/resources/suite_finish.rb +0 -19
- data/spec/unit/js_spec/client_spec.rb +0 -137
- data/spec/unit/js_spec/resources/dir_spec.rb +0 -42
- data/spec/unit/js_spec/resources/file_spec.rb +0 -88
- data/spec/unit/js_spec/resources/runner_spec.rb +0 -24
- data/spec/unit/js_spec/resources/runners/firefox_runner_spec.rb +0 -161
- data/spec/unit/js_spec/resources/specs/spec_dir_spec.rb +0 -79
- data/spec/unit/js_spec/resources/suite_finish_spec.rb +0 -94
- data/spec/unit/js_spec/resources/suite_spec.rb +0 -44
- data/spec/unit/js_spec/resources/web_root_spec.rb +0 -67
@@ -1,79 +0,0 @@
|
|
1
|
-
require File.expand_path("#{File.dirname(__FILE__)}/../../../unit_spec_helper")
|
2
|
-
|
3
|
-
module JsTestCore
|
4
|
-
module Resources
|
5
|
-
module Specs
|
6
|
-
describe SpecDir do
|
7
|
-
attr_reader :dir, :absolute_path, :relative_path
|
8
|
-
before do
|
9
|
-
@absolute_path = spec_root_path
|
10
|
-
@relative_path = "/specs"
|
11
|
-
@dir = Resources::Specs::SpecDir.new(absolute_path, relative_path)
|
12
|
-
end
|
13
|
-
|
14
|
-
it "has an absolute path" do
|
15
|
-
dir.absolute_path.should == absolute_path
|
16
|
-
end
|
17
|
-
|
18
|
-
it "has a relative path" do
|
19
|
-
dir.relative_path.should == relative_path
|
20
|
-
end
|
21
|
-
|
22
|
-
describe "#locate when passed the name with an extension" do
|
23
|
-
it "when file exists, returns a Resources::File representing it" do
|
24
|
-
file = dir.locate("failing_spec.js")
|
25
|
-
file.relative_path.should == "/specs/failing_spec.js"
|
26
|
-
file.absolute_path.should == "#{spec_root_path}/failing_spec.js"
|
27
|
-
end
|
28
|
-
|
29
|
-
it "when file does not exist, raises error" do
|
30
|
-
lambda { dir.locate("nonexistent.js") }.should raise_error
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
describe "#locate when passed a name without an extension" do
|
35
|
-
it "when name corresponds to a subdirectory, returns a DirectoryRunner for the directory" do
|
36
|
-
subdir = dir.locate("foo")
|
37
|
-
subdir.should == spec_dir("/foo")
|
38
|
-
end
|
39
|
-
|
40
|
-
it "when name does not correspond to a .js file or directory, raises an error" do
|
41
|
-
lambda do
|
42
|
-
dir.locate("nonexistent")
|
43
|
-
end.should raise_error
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
describe "#get" do
|
48
|
-
attr_reader :request, :response
|
49
|
-
before do
|
50
|
-
@request = Rack::Request.new( Rack::MockRequest.env_for('/core') )
|
51
|
-
@response = Rack::Response.new
|
52
|
-
end
|
53
|
-
|
54
|
-
it "raises NotImplementedError" do
|
55
|
-
lambda do
|
56
|
-
dir.get(request, response)
|
57
|
-
end.should raise_error(NotImplementedError)
|
58
|
-
end
|
59
|
-
|
60
|
-
it "can be overridden from a Module without needing to redefine the #get method" do
|
61
|
-
spec_dir_class = Resources::Specs::SpecDir.clone
|
62
|
-
mod = Module.new do
|
63
|
-
def get(request, response)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
spec_dir_class.class_eval do
|
67
|
-
include mod
|
68
|
-
end
|
69
|
-
@dir = spec_dir_class.new(absolute_path, relative_path)
|
70
|
-
|
71
|
-
lambda do
|
72
|
-
dir.get(request, response)
|
73
|
-
end.should_not raise_error
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
@@ -1,94 +0,0 @@
|
|
1
|
-
require File.expand_path("#{File.dirname(__FILE__)}/../../unit_spec_helper")
|
2
|
-
|
3
|
-
module JsTestCore
|
4
|
-
module Resources
|
5
|
-
describe SuiteFinish do
|
6
|
-
attr_reader :stdout, :suite_finish, :suite
|
7
|
-
before do
|
8
|
-
@stdout = StringIO.new
|
9
|
-
SuiteFinish.const_set(:STDOUT, stdout)
|
10
|
-
end
|
11
|
-
|
12
|
-
after do
|
13
|
-
SuiteFinish.__send__(:remove_const, :STDOUT)
|
14
|
-
end
|
15
|
-
|
16
|
-
describe ".post" do
|
17
|
-
describe "when Suite#id == 'user'" do
|
18
|
-
before do
|
19
|
-
@suite = Suite.new('user')
|
20
|
-
@suite_finish = SuiteFinish.new(suite)
|
21
|
-
end
|
22
|
-
|
23
|
-
it "writes the body of the request to stdout" do
|
24
|
-
body = "The text in the POST body"
|
25
|
-
request = Rack::Request.new({'rack.input' => StringIO.new("text=#{body}")})
|
26
|
-
request.body.string.should == "text=#{body}"
|
27
|
-
response = Rack::Response.new
|
28
|
-
|
29
|
-
suite_finish.post(request, response)
|
30
|
-
stdout.string.should == "#{body}\n"
|
31
|
-
end
|
32
|
-
|
33
|
-
it "sets the Content-Length to be 0" do
|
34
|
-
request = Rack::Request.new('rack.input' => StringIO.new(""))
|
35
|
-
response = Rack::Response.new
|
36
|
-
|
37
|
-
response.headers["Content-Length"].should be_nil
|
38
|
-
suite_finish.post(request, response)
|
39
|
-
response.headers["Content-Length"].should == "0"
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe "when Suite#id is not 'user'" do
|
44
|
-
attr_reader :request, :response, :runner, :suite_id, :driver
|
45
|
-
before do
|
46
|
-
runner_request = Rack::Request.new( Rack::MockRequest.env_for('/runners/firefox') )
|
47
|
-
runner_response = Rack::Response.new
|
48
|
-
@suite_id = '12345'
|
49
|
-
@driver = "Selenium Driver"
|
50
|
-
stub(Selenium::SeleniumDriver).new('localhost', 4444, '*firefox', 'http://0.0.0.0:8080') do
|
51
|
-
driver
|
52
|
-
end
|
53
|
-
stub(driver).start
|
54
|
-
stub(driver).open
|
55
|
-
stub(driver).session_id {suite_id}
|
56
|
-
stub(Thread).start.yields
|
57
|
-
Thread.current[:connection] = connection
|
58
|
-
|
59
|
-
@runner = Runners::FirefoxRunner.new
|
60
|
-
runner.post(runner_request, runner_response)
|
61
|
-
|
62
|
-
@suite = Suite.new(suite_id)
|
63
|
-
@suite_finish = SuiteFinish.new(suite)
|
64
|
-
end
|
65
|
-
|
66
|
-
it "resumes the FirefoxRunner" do
|
67
|
-
body = "The text in the POST body"
|
68
|
-
request = Rack::Request.new({'rack.input' => StringIO.new("text=#{body}")})
|
69
|
-
response = Rack::Response.new
|
70
|
-
mock.proxy(Runners::FirefoxRunner).resume(suite_id, body)
|
71
|
-
mock(driver).stop
|
72
|
-
stub(connection).send_data.once
|
73
|
-
stub(connection).close_connection.once
|
74
|
-
|
75
|
-
suite_finish.post(request, response)
|
76
|
-
end
|
77
|
-
|
78
|
-
it "sets the Content-Length to be 0" do
|
79
|
-
request = Rack::Request.new('rack.input' => StringIO.new(""))
|
80
|
-
response = Rack::Response.new
|
81
|
-
stub(Runners::FirefoxRunner).resume
|
82
|
-
stub(driver).stop
|
83
|
-
stub(connection).send_data
|
84
|
-
stub(connection).close_connection
|
85
|
-
|
86
|
-
response.headers["Content-Length"].should be_nil
|
87
|
-
suite_finish.post(request, response)
|
88
|
-
response.headers["Content-Length"].should == "0"
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
require File.expand_path("#{File.dirname(__FILE__)}/../../unit_spec_helper")
|
2
|
-
|
3
|
-
module JsTestCore
|
4
|
-
module Resources
|
5
|
-
describe Suite do
|
6
|
-
attr_reader :stdout
|
7
|
-
before do
|
8
|
-
@stdout = StringIO.new
|
9
|
-
Suite.const_set(:STDOUT, stdout)
|
10
|
-
end
|
11
|
-
|
12
|
-
after do
|
13
|
-
Suite.__send__(:remove_const, :STDOUT)
|
14
|
-
end
|
15
|
-
|
16
|
-
describe ".locate" do
|
17
|
-
it "when passed an identifier, returns an instance of Suite with the identifier" do
|
18
|
-
instance = Suite.locate('foobar')
|
19
|
-
instance.class.should == Suite
|
20
|
-
instance.id.should == 'foobar'
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe "#locate" do
|
25
|
-
attr_reader :suite
|
26
|
-
before do
|
27
|
-
@suite = Suite.new('foobar')
|
28
|
-
end
|
29
|
-
|
30
|
-
it "when passed 'finish', returns a SuiteFinish that has access to the suite" do
|
31
|
-
suite_finish = suite.locate('finish')
|
32
|
-
suite_finish.class.should == SuiteFinish
|
33
|
-
suite_finish.suite.should == suite
|
34
|
-
end
|
35
|
-
|
36
|
-
it "when not passed 'finish', raises ArgumentError" do
|
37
|
-
lambda do
|
38
|
-
suite.locate('invalid')
|
39
|
-
end.should raise_error(ArgumentError, "Invalid path: invalid")
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
@@ -1,67 +0,0 @@
|
|
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(public_path)
|
9
|
-
end
|
10
|
-
|
11
|
-
describe "#locate" do
|
12
|
-
it "when passed 'core', returns a Dir representing the JsTestCore core directory" do
|
13
|
-
runner = web_root.locate('core')
|
14
|
-
runner.should == Resources::Dir.new(JsTestCore::Server.core_path, '/core')
|
15
|
-
end
|
16
|
-
|
17
|
-
it "when passed 'implementations', returns a Dir representing the javascript implementations directory" do
|
18
|
-
runner = web_root.locate('implementations')
|
19
|
-
runner.should == Resources::Dir.new(JsTestCore::Server.implementation_root_path, '/implementations')
|
20
|
-
end
|
21
|
-
|
22
|
-
it "when passed 'results', returns a Suite" do
|
23
|
-
runner = web_root.locate('suites')
|
24
|
-
runner.should == Resources::Suite
|
25
|
-
end
|
26
|
-
|
27
|
-
it "when passed 'runners', returns a Runner" do
|
28
|
-
runner = web_root.locate('runners')
|
29
|
-
runner.should be_instance_of(Resources::Runners)
|
30
|
-
end
|
31
|
-
|
32
|
-
it "when passed a directory that is in the public_path, returns a Dir representing that directory" do
|
33
|
-
runner = web_root.locate('stylesheets')
|
34
|
-
runner.should == Resources::Dir.new("#{JsTestCore::Server.public_path}/stylesheets", '/stylesheets')
|
35
|
-
end
|
36
|
-
|
37
|
-
it "when passed a file that is in the public_path, returns a File representing that file" do
|
38
|
-
runner = web_root.locate('robots.txt')
|
39
|
-
runner.should == Resources::File.new("#{JsTestCore::Server.public_path}/robots.txt", '/robots.txt')
|
40
|
-
end
|
41
|
-
|
42
|
-
it "when not passed 'core' or 'specs', raises an error" do
|
43
|
-
lambda do
|
44
|
-
web_root.locate('invalid')
|
45
|
-
end.should raise_error
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
describe ".dispatch_specs" do
|
50
|
-
it "causes #locate /specs to dispatch to a Spec::SpecDir" do
|
51
|
-
WebRoot.dispatch_specs
|
52
|
-
|
53
|
-
resource = web_root.locate('specs')
|
54
|
-
resource.should == spec_dir('')
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
describe "when .dispatch_specs is not called" do
|
59
|
-
it "does not cause #locate to dispatch to /specs" do
|
60
|
-
lambda do
|
61
|
-
web_root.locate('specs')
|
62
|
-
end.should raise_error
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|