js_spec 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +6 -0
- data/README +23 -1
- data/Rakefile +5 -3
- data/bin/js_spec +1 -5
- data/bin/js_spec_server +0 -0
- data/core/JSSpecExtensions.js +70 -25
- data/core/jquery.js +2992 -0
- data/init.rb +0 -0
- data/lib/js_spec/client.rb +50 -0
- data/lib/js_spec/rack/response.rb +5 -0
- data/lib/js_spec/rails_server.rb +3 -3
- data/lib/js_spec/resources/dir.rb +43 -43
- data/lib/js_spec/resources/file.rb +16 -16
- data/lib/js_spec/resources/runners/firefox1_runner.rb +8 -0
- data/lib/js_spec/resources/runners/firefox_runner.rb +49 -72
- data/lib/js_spec/resources/runners.rb +6 -7
- data/lib/js_spec/resources/spec_dir_runner.rb +7 -7
- data/lib/js_spec/resources/spec_file_runner.rb +7 -7
- data/lib/js_spec/resources/spec_runner.rb +16 -11
- data/lib/js_spec/resources/suite.rb +14 -14
- data/lib/js_spec/resources/suite_finish.rb +12 -12
- data/lib/js_spec/server.rb +29 -17
- data/lib/js_spec/thin/backends/js_spec_server.rb +9 -0
- data/lib/js_spec/thin/js_spec_connection.rb +43 -0
- data/lib/js_spec.rb +14 -2
- data/spec/integration/integration_spec.rb +14 -0
- data/spec/integration/integration_spec_helper.rb +52 -0
- data/spec/integration_suite.rb +10 -0
- data/spec/spec_suite.rb +1 -0
- data/spec/unit/js_spec/client_spec.rb +137 -0
- data/spec/unit/{rails_server_spec.rb → js_spec/rails_server_spec.rb} +8 -7
- data/spec/unit/{resources → js_spec/resources}/dir_spec.rb +1 -1
- data/spec/unit/{resources → js_spec/resources}/file_spec.rb +9 -6
- data/spec/unit/js_spec/resources/runner_spec.rb +24 -0
- data/spec/unit/js_spec/resources/runners/firefox_runner_spec.rb +152 -0
- data/spec/unit/js_spec/resources/spec_dir_runner_spec.rb +48 -0
- data/spec/unit/{resources → js_spec/resources}/spec_file_runner_spec.rb +1 -1
- data/spec/unit/{resources → js_spec/resources}/suite_finish_spec.rb +5 -5
- data/spec/unit/{resources → js_spec/resources}/suite_spec.rb +1 -1
- data/spec/unit/{resources → js_spec/resources}/web_root_spec.rb +1 -1
- data/spec/unit/{server_spec.rb → js_spec/server_spec.rb} +29 -92
- data/spec/unit/rack/response_spec.rb +30 -0
- data/spec/unit/thin/js_spec_connection_spec.rb +50 -0
- data/spec/unit/unit_spec_helper.rb +40 -5
- metadata +107 -60
- data/spec/unit/resources/runner_spec.rb +0 -24
- data/spec/unit/resources/runners/firefox_runner_spec.rb +0 -87
- data/spec/unit/resources/spec_dir_runner_spec.rb +0 -43
@@ -0,0 +1,43 @@
|
|
1
|
+
module Thin
|
2
|
+
class JsSpecConnection < Connection
|
3
|
+
def process
|
4
|
+
# Add client info to the request env
|
5
|
+
@request.remote_address = remote_address
|
6
|
+
|
7
|
+
env = @request.env
|
8
|
+
env['js_spec.connection'] = self
|
9
|
+
status, headers, body = @app.call(env)
|
10
|
+
unless status.to_i == 0
|
11
|
+
send_response(status, headers, body)
|
12
|
+
end
|
13
|
+
rescue
|
14
|
+
handle_error
|
15
|
+
end
|
16
|
+
|
17
|
+
def send_response(status, headers, body)
|
18
|
+
@response.status, @response.headers, @response.body = status, headers, body
|
19
|
+
@response.persistent! if @request.persistent?
|
20
|
+
@response.each do |chunk|
|
21
|
+
trace { chunk }
|
22
|
+
send_data chunk
|
23
|
+
end
|
24
|
+
# If no more request on that same connection, we close it.
|
25
|
+
close_connection_after_writing unless persistent?
|
26
|
+
rescue
|
27
|
+
handle_error
|
28
|
+
ensure
|
29
|
+
@request.close rescue nil
|
30
|
+
@response.close rescue nil
|
31
|
+
|
32
|
+
# Prepare the connection for another request if the client
|
33
|
+
# supports HTTP pipelining (persistent connection).
|
34
|
+
post_init if persistent?
|
35
|
+
end
|
36
|
+
|
37
|
+
def handle_error
|
38
|
+
log "!! Unexpected error while processing request: #{$!.message}"
|
39
|
+
log_error
|
40
|
+
close_connection rescue nil
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/js_spec.rb
CHANGED
@@ -1,15 +1,22 @@
|
|
1
1
|
require "rubygems"
|
2
|
-
require "
|
3
|
-
require "mongrel"
|
2
|
+
require "thin"
|
4
3
|
require "fileutils"
|
5
4
|
require "tmpdir"
|
6
5
|
require "timeout"
|
7
6
|
require "uuid"
|
7
|
+
require "cgi"
|
8
|
+
require "net/http"
|
9
|
+
require "selenium"
|
10
|
+
require "optparse"
|
8
11
|
|
9
12
|
dir = File.dirname(__FILE__)
|
13
|
+
require "#{dir}/js_spec/thin/js_spec_connection"
|
14
|
+
require "#{dir}/js_spec/thin/backends/js_spec_server"
|
15
|
+
require "#{dir}/js_spec/rack/response"
|
10
16
|
require "#{dir}/js_spec/resources/runners"
|
11
17
|
require "#{dir}/js_spec/resources/runners/firefox_runner"
|
12
18
|
|
19
|
+
require "#{dir}/js_spec/client"
|
13
20
|
require "#{dir}/js_spec/server"
|
14
21
|
require "#{dir}/js_spec/rails_server"
|
15
22
|
require "#{dir}/js_spec/resources/spec_runner"
|
@@ -20,3 +27,8 @@ require "#{dir}/js_spec/resources/dir"
|
|
20
27
|
require "#{dir}/js_spec/resources/web_root"
|
21
28
|
require "#{dir}/js_spec/resources/suite"
|
22
29
|
require "#{dir}/js_spec/resources/suite_finish"
|
30
|
+
|
31
|
+
module JsSpec
|
32
|
+
DEFAULT_HOST = "127.0.0.1"
|
33
|
+
DEFAULT_PORT = 8080
|
34
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/integration_spec_helper")
|
2
|
+
|
3
|
+
describe "JsSpec" do
|
4
|
+
it "runs a full passing Suite" do
|
5
|
+
mock(JsSpec::Client).puts("SUCCESS")
|
6
|
+
JsSpec::Client.run(:spec_url => "#{root_url}/specs/foo/passing_spec")
|
7
|
+
end
|
8
|
+
|
9
|
+
it "runs a full failing Suite" do
|
10
|
+
mock(JsSpec::Client).puts("FAILURE")
|
11
|
+
mock(JsSpec::Client).puts(/A failing spec in foo fails/)
|
12
|
+
JsSpec::Client.run(:spec_url => "#{root_url}/specs/foo/failing_spec")
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
dir = File.dirname(__FILE__)
|
3
|
+
$LOAD_PATH.unshift "#{dir}/../../../plugins/rspec/lib"
|
4
|
+
require "spec"
|
5
|
+
|
6
|
+
$LOAD_PATH.unshift "#{dir}/../../lib"
|
7
|
+
require "js_spec"
|
8
|
+
require "hpricot"
|
9
|
+
require "lsof"
|
10
|
+
|
11
|
+
Spec::Runner.configure do |config|
|
12
|
+
config.mock_with :rr
|
13
|
+
end
|
14
|
+
|
15
|
+
Thin::Logging.silent = false
|
16
|
+
Thin::Logging.debug = true
|
17
|
+
|
18
|
+
module WaitFor
|
19
|
+
extend self
|
20
|
+
def wait_for(time=5)
|
21
|
+
Timeout.timeout(time) do
|
22
|
+
loop do
|
23
|
+
value = yield
|
24
|
+
return value if value
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
module Spec::Example::ExampleMethods
|
31
|
+
include WaitFor
|
32
|
+
attr_reader :spec_root_path, :implementation_root_path, :public_path
|
33
|
+
before(:all) do
|
34
|
+
dir = File.dirname(__FILE__)
|
35
|
+
@spec_root_path = "#{dir}/../example_specs"
|
36
|
+
@public_path = "#{dir}/../example_public"
|
37
|
+
@implementation_root_path = "#{public_path}/javascripts"
|
38
|
+
unless $js_spec_server_started
|
39
|
+
Thread.start do
|
40
|
+
JsSpec::Server.run(spec_root_path, implementation_root_path, public_path)
|
41
|
+
end
|
42
|
+
$js_spec_server_started = true
|
43
|
+
end
|
44
|
+
wait_for do
|
45
|
+
Lsof.running?(8080)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def root_url
|
50
|
+
"http://#{JsSpec::DEFAULT_HOST}:#{JsSpec::DEFAULT_PORT}"
|
51
|
+
end
|
52
|
+
end
|
data/spec/spec_suite.rb
CHANGED
@@ -0,0 +1,137 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../unit_spec_helper")
|
2
|
+
|
3
|
+
module JsSpec
|
4
|
+
describe Client do
|
5
|
+
describe '.run' do
|
6
|
+
describe 'when successful' do
|
7
|
+
before do
|
8
|
+
request = Object.new
|
9
|
+
mock(request).post("/runners/firefox", "selenium_host=localhost&selenium_port=4444")
|
10
|
+
response = Object.new
|
11
|
+
mock(response).body {""}
|
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
|
19
|
+
|
20
|
+
it "prints 'SUCCESS'" do
|
21
|
+
mock(Client).puts("SUCCESS")
|
22
|
+
Client.run
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe 'when unsuccessful' do
|
27
|
+
before do
|
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
|
35
|
+
|
36
|
+
it "returns false" do
|
37
|
+
Client.run.should be_false
|
38
|
+
end
|
39
|
+
|
40
|
+
it "prints 'FAILURE' and the error message(s)" do
|
41
|
+
mock(Client).puts("FAILURE")
|
42
|
+
mock(Client).puts("the failure message")
|
43
|
+
Client.run
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "arguments" do
|
48
|
+
attr_reader :request, :response
|
49
|
+
before do
|
50
|
+
@request = Object.new
|
51
|
+
@response = Object.new
|
52
|
+
mock(response).body {""}
|
53
|
+
mock(Net::HTTP).start(DEFAULT_HOST, DEFAULT_PORT).yields(request) {response}
|
54
|
+
stub(Client).puts
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "when passed a custom spec_url" do
|
58
|
+
it "passes the spec_url as a post parameter" do
|
59
|
+
spec_url = 'http://foobar.com/foo'
|
60
|
+
mock(request).post(
|
61
|
+
"/runners/firefox",
|
62
|
+
"selenium_host=localhost&selenium_port=4444&spec_url=#{CGI.escape(spec_url)}"
|
63
|
+
)
|
64
|
+
Client.run(:spec_url => spec_url)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "when passed a custom selenium host" do
|
69
|
+
it "passes the selenium_host as a post parameter" do
|
70
|
+
selenium_host = 'test-runner'
|
71
|
+
mock(request).post(
|
72
|
+
"/runners/firefox",
|
73
|
+
"selenium_host=test-runner&selenium_port=4444"
|
74
|
+
)
|
75
|
+
Client.run(:selenium_host => selenium_host)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe "when passed a custom selenium port" do
|
80
|
+
it "passes the selenium_port as a post parameter" do
|
81
|
+
selenium_port = 5000
|
82
|
+
mock(request).post(
|
83
|
+
"/runners/firefox",
|
84
|
+
"selenium_host=localhost&selenium_port=5000"
|
85
|
+
)
|
86
|
+
Client.run(:selenium_port => selenium_port)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
describe ".run_argv" do
|
94
|
+
attr_reader :request, :response
|
95
|
+
before do
|
96
|
+
@request = Object.new
|
97
|
+
@response = Object.new
|
98
|
+
mock(response).body {""}
|
99
|
+
mock(Net::HTTP).start(DEFAULT_HOST, DEFAULT_PORT).yields(request) {response}
|
100
|
+
stub(Client).puts
|
101
|
+
end
|
102
|
+
|
103
|
+
describe "when passed a custom spec_url" do
|
104
|
+
it "passes the spec_url as a post parameter" do
|
105
|
+
spec_url = 'http://foobar.com/foo'
|
106
|
+
mock(request).post(
|
107
|
+
"/runners/firefox",
|
108
|
+
"selenium_host=localhost&selenium_port=4444&spec_url=#{CGI.escape(spec_url)}"
|
109
|
+
)
|
110
|
+
Client.run_argv(['--spec_url', spec_url])
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe "when passed a custom selenium host" do
|
115
|
+
it "passes the selenium_host as a post parameter" do
|
116
|
+
selenium_host = 'test-runner'
|
117
|
+
mock(request).post(
|
118
|
+
"/runners/firefox",
|
119
|
+
"selenium_host=test-runner&selenium_port=4444"
|
120
|
+
)
|
121
|
+
Client.run_argv(['--selenium_host', selenium_host])
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
describe "when passed a custom selenium port" do
|
126
|
+
it "passes the selenium_port as a post parameter" do
|
127
|
+
selenium_port = 5000
|
128
|
+
mock(request).post(
|
129
|
+
"/runners/firefox",
|
130
|
+
"selenium_host=localhost&selenium_port=5000"
|
131
|
+
)
|
132
|
+
Client.run_argv(['--selenium_port', selenium_port.to_s])
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.expand_path("#{File.dirname(__FILE__)}
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../unit_spec_helper")
|
2
2
|
|
3
3
|
module JsSpec
|
4
4
|
describe RailsServer do
|
@@ -13,19 +13,20 @@ module JsSpec
|
|
13
13
|
Server.instance = nil
|
14
14
|
end
|
15
15
|
|
16
|
-
it "initializes the RailsServer and runs the
|
17
|
-
host =
|
18
|
-
port =
|
19
|
-
server_instance =
|
16
|
+
it "initializes the RailsServer and runs the Thin Handler and sets Server.instance to the RailsServer instance" do
|
17
|
+
host = DEFAULT_HOST
|
18
|
+
port = DEFAULT_PORT
|
19
|
+
server_instance = nil
|
20
20
|
mock.proxy(RailsServer).new(
|
21
21
|
rails_root,
|
22
22
|
host,
|
23
23
|
port
|
24
24
|
) do |new_instance|
|
25
|
-
server_instance
|
25
|
+
server_instance = new_instance
|
26
26
|
end
|
27
|
-
mock(Rack::Handler::Mongrel).run(server_instance, {:Host => host, :Port => port})
|
28
27
|
|
28
|
+
mock(EventMachine).run.yields
|
29
|
+
mock(EventMachine).start_server(host, port, ::Thin::JsSpecConnection)
|
29
30
|
RailsServer.run(rails_root)
|
30
31
|
Server.instance.should == server_instance
|
31
32
|
end
|
@@ -1,12 +1,15 @@
|
|
1
|
-
require File.expand_path("#{File.dirname(__FILE__)}
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../unit_spec_helper")
|
2
2
|
|
3
3
|
module JsSpec
|
4
4
|
module Resources
|
5
5
|
describe File do
|
6
|
-
attr_reader :file
|
6
|
+
attr_reader :request, :file
|
7
7
|
|
8
8
|
before do
|
9
|
+
stub(EventMachine).send_data
|
10
|
+
stub(EventMachine).close_connection
|
9
11
|
@file = Resources::File.new(absolute_path, relative_path)
|
12
|
+
@request = create_request('get', relative_path)
|
10
13
|
end
|
11
14
|
|
12
15
|
def absolute_path
|
@@ -33,24 +36,24 @@ module JsSpec
|
|
33
36
|
attr_reader :response
|
34
37
|
before do
|
35
38
|
@response = Rack::Response.new
|
36
|
-
mock.proxy(Server).response.returns(@response)
|
37
39
|
end
|
38
40
|
|
39
41
|
it "returns the contents of the file" do
|
40
|
-
file.get
|
42
|
+
file.get(request, response)
|
43
|
+
response.body.should == ::File.read(absolute_path)
|
41
44
|
end
|
42
45
|
|
43
46
|
describe "when File has an extension" do
|
44
47
|
describe '.js' do
|
45
48
|
it "sets Content-Type to text/javascript" do
|
46
|
-
file.get
|
49
|
+
file.get(request,response)
|
47
50
|
response.content_type.should == "text/javascript"
|
48
51
|
end
|
49
52
|
end
|
50
53
|
|
51
54
|
describe '.css' do
|
52
55
|
it "sets Content-Type to text/css" do
|
53
|
-
file.get
|
56
|
+
file.get(request, response)
|
54
57
|
response.content_type.should == "text/css"
|
55
58
|
end
|
56
59
|
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../unit_spec_helper")
|
2
|
+
|
3
|
+
module JsSpec
|
4
|
+
module Resources
|
5
|
+
describe Runners do
|
6
|
+
attr_reader :runner
|
7
|
+
before do
|
8
|
+
@runner = Runners.new
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#locate" do
|
12
|
+
it "when passed 'firefox', returns a Firefox1Runner" do
|
13
|
+
runner.locate('firefox').is_a?(Runners::FirefoxRunner).should be_true
|
14
|
+
end
|
15
|
+
|
16
|
+
it "when not passed 'firefox', raises an error" do
|
17
|
+
lambda do
|
18
|
+
runner.locate('invalid')
|
19
|
+
end.should raise_error
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,152 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../../unit_spec_helper")
|
2
|
+
|
3
|
+
module JsSpec
|
4
|
+
module Resources
|
5
|
+
describe Runners::FirefoxRunner do
|
6
|
+
attr_reader :runner, :request, :response, :driver
|
7
|
+
|
8
|
+
before do
|
9
|
+
Thread.current[:connection] = connection
|
10
|
+
@driver = "Selenium Driver"
|
11
|
+
stub(Selenium::SeleniumDriver).new('localhost', 4444, '*firefox', 'http://127.0.0.1:8080') do
|
12
|
+
driver
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#post" do
|
17
|
+
attr_reader :firefox_profile_path
|
18
|
+
before do
|
19
|
+
@request = Rack::Request.new( Rack::MockRequest.env_for('/runners/firefox') )
|
20
|
+
@response = Rack::Response.new
|
21
|
+
@runner = Runners::FirefoxRunner.new(request, response)
|
22
|
+
stub(Thread).start.yields
|
23
|
+
end
|
24
|
+
|
25
|
+
it "keeps the connection open" do
|
26
|
+
stub(driver).start
|
27
|
+
stub(driver).open
|
28
|
+
dont_allow(EventMachine).send_data
|
29
|
+
dont_allow(EventMachine).close_connection
|
30
|
+
runner.post(request, response)
|
31
|
+
|
32
|
+
response.should_not be_ready
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "when a selenium_host parameter is passed into the request" do
|
36
|
+
before do
|
37
|
+
request['selenium_host'] = "another-machine"
|
38
|
+
stub(driver).start
|
39
|
+
stub(driver).open
|
40
|
+
end
|
41
|
+
|
42
|
+
it "starts the Selenium Driver with the passed in selenium_host" do
|
43
|
+
mock(Selenium::SeleniumDriver).new('another-machine', 4444, '*firefox', 'http://127.0.0.1:8080') do
|
44
|
+
driver
|
45
|
+
end
|
46
|
+
runner.post(request, response)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "when a selenium_host parameter is not passed into the request" do
|
51
|
+
before do
|
52
|
+
request['selenium_host'].should be_nil
|
53
|
+
stub(driver).start
|
54
|
+
stub(driver).open
|
55
|
+
end
|
56
|
+
|
57
|
+
it "starts the Selenium Driver from localhost" do
|
58
|
+
mock(Selenium::SeleniumDriver).new('localhost', 4444, '*firefox', 'http://127.0.0.1:8080') do
|
59
|
+
driver
|
60
|
+
end
|
61
|
+
runner.post(request, response)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "when a selenium_port parameter is passed into the request" do
|
66
|
+
before do
|
67
|
+
request['selenium_port'] = "4000"
|
68
|
+
stub(driver).start
|
69
|
+
stub(driver).open
|
70
|
+
end
|
71
|
+
|
72
|
+
it "starts the Selenium Driver with the passed in selenium_port" do
|
73
|
+
mock(Selenium::SeleniumDriver).new('localhost', 4000, '*firefox', 'http://127.0.0.1:8080') do
|
74
|
+
driver
|
75
|
+
end
|
76
|
+
runner.post(request, response)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe "when a selenium_port parameter is not passed into the request" do
|
81
|
+
before do
|
82
|
+
request['selenium_port'].should be_nil
|
83
|
+
stub(driver).start
|
84
|
+
stub(driver).open
|
85
|
+
end
|
86
|
+
|
87
|
+
it "starts the Selenium Driver from localhost" do
|
88
|
+
mock(Selenium::SeleniumDriver).new('localhost', 4444, '*firefox', 'http://127.0.0.1:8080') do
|
89
|
+
driver
|
90
|
+
end
|
91
|
+
runner.post(request, response)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe "when a spec_url is passed into the request" do
|
96
|
+
before do
|
97
|
+
request['spec_url'] = "http://another-host:8080/specs/subdir"
|
98
|
+
end
|
99
|
+
|
100
|
+
it "runs Selenium with the passed in host and part to run the specified spec suite in Firefox" do
|
101
|
+
mock(Selenium::SeleniumDriver).new('localhost', 4444, '*firefox', 'http://another-host:8080') do
|
102
|
+
driver
|
103
|
+
end
|
104
|
+
mock(driver).start
|
105
|
+
mock(driver).open("http://another-host:8080/specs/subdir?guid=#{runner.guid}")
|
106
|
+
|
107
|
+
runner.post(request, response)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
describe "when a spec_url is not passed into the request" do
|
112
|
+
before do
|
113
|
+
request['spec_url'].should be_nil
|
114
|
+
mock(Selenium::SeleniumDriver).new('localhost', 4444, '*firefox', 'http://127.0.0.1:8080') do
|
115
|
+
driver
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
it "uses Selenium to run the entire spec suite in Firefox" do
|
120
|
+
mock(driver).start
|
121
|
+
mock(driver).open("http://127.0.0.1:8080/specs?guid=#{runner.guid}")
|
122
|
+
|
123
|
+
runner.post(request, response)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
describe "#finalize" do
|
129
|
+
before do
|
130
|
+
@request = Rack::Request.new( Rack::MockRequest.env_for('/runners/firefox') )
|
131
|
+
@response = Rack::Response.new
|
132
|
+
@runner = Runners::FirefoxRunner.new(request, response)
|
133
|
+
stub(driver).start
|
134
|
+
stub(driver).open
|
135
|
+
runner.post(request, response)
|
136
|
+
end
|
137
|
+
|
138
|
+
it "kills the browser, sends the response body, and close the connection" do
|
139
|
+
mock(driver).stop
|
140
|
+
data = ""
|
141
|
+
stub(EventMachine).send_data do |signature, data, data_length|
|
142
|
+
data << data
|
143
|
+
end
|
144
|
+
mock(connection).close_connection_after_writing
|
145
|
+
|
146
|
+
runner.finalize("The text")
|
147
|
+
data.should include("The text")
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../unit_spec_helper")
|
2
|
+
|
3
|
+
module JsSpec
|
4
|
+
module Resources
|
5
|
+
describe SpecDirRunner do
|
6
|
+
attr_reader :dir, :runner
|
7
|
+
|
8
|
+
before do
|
9
|
+
stub(EventMachine).send_data
|
10
|
+
stub(EventMachine).close_connection
|
11
|
+
@dir = Dir.new(spec_root_path, '/specs')
|
12
|
+
@runner = SpecDirRunner.new(dir)
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "#spec_files" do
|
16
|
+
it "returns a File for each *_spec.js file in the directory" do
|
17
|
+
spec_files = runner.spec_files
|
18
|
+
|
19
|
+
spec_files.should contain_spec_file_with_correct_paths("/failing_spec.js")
|
20
|
+
spec_files.should contain_spec_file_with_correct_paths("/foo/failing_spec.js")
|
21
|
+
spec_files.should contain_spec_file_with_correct_paths("/foo/passing_spec.js")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#get" do
|
26
|
+
attr_reader :html, :doc
|
27
|
+
before do
|
28
|
+
request = request('get', '/specs')
|
29
|
+
response = Rack::Response.new
|
30
|
+
runner.get(request, response)
|
31
|
+
@html = response.body
|
32
|
+
@doc = Hpricot(html)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "returns script tags for each test javascript file" do
|
36
|
+
doc.at("script[@src='/specs/failing_spec.js']").should exist
|
37
|
+
end
|
38
|
+
|
39
|
+
it "returns the js specs template" do
|
40
|
+
doc.at("link[@href='/core/JSSpec.css']").should exist
|
41
|
+
doc.at("script[@src='/core/JSSpec.js']").should exist
|
42
|
+
doc.at("script[@src='/core/JSSpecExtensions.js']").should exist
|
43
|
+
doc.at("body").inner_html.should be_empty
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.expand_path("#{File.dirname(__FILE__)}
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../unit_spec_helper")
|
2
2
|
|
3
3
|
module JsSpec
|
4
4
|
module Resources
|
@@ -21,9 +21,9 @@ module JsSpec
|
|
21
21
|
body = "The text in the POST body"
|
22
22
|
request = Rack::Request.new({'rack.input' => StringIO.new("text=#{body}")})
|
23
23
|
request.body.string.should == "text=#{body}"
|
24
|
-
|
24
|
+
response = Rack::Response.new
|
25
25
|
|
26
|
-
suite_finish.post
|
26
|
+
suite_finish.post(request, response)
|
27
27
|
stdout.string.should == "#{body}\n"
|
28
28
|
end
|
29
29
|
|
@@ -31,9 +31,9 @@ module JsSpec
|
|
31
31
|
body = "The text in the POST body"
|
32
32
|
request = Rack::Request.new({'rack.input' => StringIO.new("text=#{body}")})
|
33
33
|
request.body.string.should == "text=#{body}"
|
34
|
-
|
34
|
+
response = Rack::Response.new
|
35
35
|
|
36
|
-
suite_finish.post.should == ""
|
36
|
+
suite_finish.post(request, response).should == ""
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|