js_spec 0.2.0 → 0.2.1
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 +7 -0
- data/README +11 -2
- data/Rakefile +1 -1
- data/core/JSSpecExtensions.js +3 -1
- data/lib/js_spec/guid.rb +153 -0
- data/lib/js_spec/rack/commonlogger.rb +5 -0
- data/lib/js_spec/rack.rb +2 -0
- data/lib/js_spec/resources/runners/firefox_runner.rb +10 -6
- data/lib/js_spec/resources/spec_runner.rb +3 -1
- data/lib/js_spec/resources.rb +11 -0
- data/lib/js_spec/server.rb +4 -5
- data/lib/js_spec/thin/js_spec_connection.rb +13 -14
- data/lib/js_spec/thin.rb +3 -0
- data/lib/js_spec.rb +8 -15
- data/spec/unit/js_spec/resources/runners/firefox_runner_spec.rb +8 -8
- data/spec/unit/js_spec/resources/spec_dir_runner_spec.rb +1 -1
- data/spec/unit/thin/js_spec_connection_spec.rb +32 -18
- data/spec/unit/unit_spec_helper.rb +1 -1
- metadata +7 -5
- data/lib/js_spec/rack/response.rb +0 -5
- data/lib/js_spec/resources/runners/firefox1_runner.rb +0 -8
- data/spec/unit/rack/response_spec.rb +0 -30
data/CHANGES
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
0.2.1
|
2
|
+
- Using thin 0.8.1
|
3
|
+
- Fixed server crashing on exception issue.
|
4
|
+
- Add div id=js_spec_content into the body of the runner html.
|
5
|
+
- Fixed timeout issues by immediately sending the head of the response.
|
6
|
+
- Better error message when selenium server is not running
|
7
|
+
|
1
8
|
0.2.0
|
2
9
|
- Using Thin as the server
|
3
10
|
- Using Selenium to run the browsers
|
data/README
CHANGED
@@ -11,13 +11,22 @@ To install the gem, run:
|
|
11
11
|
|
12
12
|
To install the plugin, run:
|
13
13
|
script/plugin install svn://rubyforge.org/var/svn/pivotalrb/js_spec/trunk
|
14
|
+
script/generate js_spec
|
14
15
|
|
15
16
|
The Rails plugin gives you generators when using JsSpec in a Rails environment.
|
16
17
|
|
17
18
|
== Using JsSpec
|
18
|
-
|
19
|
+
First you need to start your JsSpec server.
|
19
20
|
|
20
|
-
|
21
|
+
If you are using js_spec_server as a Rails plugin, you can simply run:
|
22
|
+
script/js_spec_server
|
23
|
+
|
24
|
+
If you are using the js_spec gem, you can run:
|
25
|
+
js_spec_server /path/to/your/javascript/spec/files /path/to/your/javascript/implementation/files
|
26
|
+
|
27
|
+
Once the server is started, there are two possibly ways to run your js spec:
|
28
|
+
* Open your browser to http://localhost:8080/specs
|
29
|
+
* Start the Selenium server by running `selenium` from the command line, then running `js_spec` from the command line
|
21
30
|
|
22
31
|
== JsSpec on CI
|
23
32
|
JS spec uses the Selenium gem to automatically control browsers on different machines.
|
data/Rakefile
CHANGED
data/core/JSSpecExtensions.js
CHANGED
@@ -33,7 +33,9 @@ Spec.register = function(spec_constructor) {
|
|
33
33
|
}
|
34
34
|
}
|
35
35
|
|
36
|
-
Spec.reset = function() {
|
36
|
+
Spec.reset = function() {
|
37
|
+
document.getElementById('js_spec_content').innerHTML = "";
|
38
|
+
}
|
37
39
|
|
38
40
|
var Assets = {
|
39
41
|
require: function(path_from_javascripts, onload) {
|
data/lib/js_spec/guid.rb
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
#
|
2
|
+
# Guid - Ruby library for portable GUID/UUID generation.
|
3
|
+
#
|
4
|
+
# Copyright (c) 2004 David Garamond <davegaramond at icqmail com>
|
5
|
+
#
|
6
|
+
# This library is free software; you can redistribute it and/or modify it
|
7
|
+
# under the same terms as Ruby itself.
|
8
|
+
#
|
9
|
+
|
10
|
+
if RUBY_PLATFORM =~ /[^r]win/i &&
|
11
|
+
module Guid_Win32_
|
12
|
+
require 'Win32API'
|
13
|
+
|
14
|
+
PROV_RSA_FULL = 1
|
15
|
+
CRYPT_VERIFYCONTEXT = 0xF0000000
|
16
|
+
FORMAT_MESSAGE_IGNORE_INSERTS = 0x00000200
|
17
|
+
FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000
|
18
|
+
|
19
|
+
CryptAcquireContext = Win32API.new("advapi32", "CryptAcquireContext",
|
20
|
+
'PPPII', 'L')
|
21
|
+
CryptGenRandom = Win32API.new("advapi32", "CryptGenRandom",
|
22
|
+
'LIP', 'L')
|
23
|
+
CryptReleaseContext = Win32API.new("advapi32", "CryptReleaseContext",
|
24
|
+
'LI', 'L')
|
25
|
+
GetLastError = Win32API.new("kernel32", "GetLastError", '', 'L')
|
26
|
+
FormatMessageA = Win32API.new("kernel32", "FormatMessageA",
|
27
|
+
'LPLLPLPPPPPPPP', 'L')
|
28
|
+
|
29
|
+
def lastErrorMessage
|
30
|
+
code = GetLastError.call
|
31
|
+
msg = "\0" * 1024
|
32
|
+
len = FormatMessageA.call(FORMAT_MESSAGE_IGNORE_INSERTS +
|
33
|
+
FORMAT_MESSAGE_FROM_SYSTEM, 0,
|
34
|
+
code, 0, msg, 1024, nil, nil,
|
35
|
+
nil, nil, nil, nil, nil, nil)
|
36
|
+
msg[0, len].tr("\r", '').chomp
|
37
|
+
end
|
38
|
+
|
39
|
+
def initialize
|
40
|
+
hProvStr = " " * 4
|
41
|
+
if CryptAcquireContext.call(hProvStr, nil, nil, PROV_RSA_FULL,
|
42
|
+
CRYPT_VERIFYCONTEXT) == 0
|
43
|
+
raise SystemCallError, "CryptAcquireContext failed: #{lastErrorMessage}"
|
44
|
+
end
|
45
|
+
hProv, = hProvStr.unpack('L')
|
46
|
+
@bytes = " " * 16
|
47
|
+
if CryptGenRandom.call(hProv, 16, @bytes) == 0
|
48
|
+
raise SystemCallError, "CryptGenRandom failed: #{lastErrorMessage}"
|
49
|
+
end
|
50
|
+
if CryptReleaseContext.call(hProv, 0) == 0
|
51
|
+
raise SystemCallError, "CryptReleaseContext failed: #{lastErrorMessage}"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
module Guid_Unix_
|
58
|
+
@@random_device = nil
|
59
|
+
|
60
|
+
def initialize
|
61
|
+
if !@@random_device
|
62
|
+
if File.exists? "/dev/urandom"
|
63
|
+
@@random_device = File.open "/dev/urandom", "r"
|
64
|
+
elsif File.exists? "/dev/random"
|
65
|
+
@@random_device = File.open "/dev/random", "r"
|
66
|
+
else
|
67
|
+
raise RuntimeError, "Can't find random device"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
@bytes = @@random_device.read(16)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
class Guid
|
76
|
+
if RUBY_PLATFORM =~ /[^r]win/
|
77
|
+
include Guid_Win32_
|
78
|
+
else
|
79
|
+
include Guid_Unix_
|
80
|
+
end
|
81
|
+
|
82
|
+
def hexdigest
|
83
|
+
@bytes.unpack("h*")[0]
|
84
|
+
end
|
85
|
+
|
86
|
+
def to_s
|
87
|
+
@bytes.unpack("h8 h4 h4 h4 h12").join "-"
|
88
|
+
end
|
89
|
+
|
90
|
+
def inspect
|
91
|
+
to_s
|
92
|
+
end
|
93
|
+
|
94
|
+
def raw
|
95
|
+
@bytes
|
96
|
+
end
|
97
|
+
|
98
|
+
def self.from_s(s)
|
99
|
+
raise ArgumentError, "Invalid GUID hexstring" unless
|
100
|
+
s =~ /\A[0-9a-f]{8}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{12}\z/i
|
101
|
+
guid = Guid.allocate
|
102
|
+
guid.instance_eval { @bytes = [s.gsub(/[^0-9a-f]+/i, '')].pack "h*" }
|
103
|
+
guid
|
104
|
+
end
|
105
|
+
|
106
|
+
def self.from_raw(bytes)
|
107
|
+
raise ArgumentError, "Invalid GUID raw bytes, length must be 16 bytes" unless
|
108
|
+
bytes.length == 16
|
109
|
+
guid = Guid.allocate
|
110
|
+
guid.instance_eval { @bytes = bytes }
|
111
|
+
guid
|
112
|
+
end
|
113
|
+
|
114
|
+
def ==(other)
|
115
|
+
@bytes == other.raw
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
if __FILE__ == $0
|
120
|
+
require 'test/unit'
|
121
|
+
|
122
|
+
class GuidTest < Test::Unit::TestCase
|
123
|
+
def test_new
|
124
|
+
g = Guid.new
|
125
|
+
|
126
|
+
# different representations of guid: hexdigest, hex+dashes, raw bytes
|
127
|
+
assert_equal(0, g.to_s =~ /\A[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\z/)
|
128
|
+
assert_equal(16, g.raw.length)
|
129
|
+
assert_equal(0, g.hexdigest =~ /\A[0-9a-f]{32}\z/)
|
130
|
+
assert_equal(g.hexdigest, g.to_s.gsub(/-/, ''))
|
131
|
+
|
132
|
+
# must be different each time we produce (this is just a simple test)
|
133
|
+
g2 = Guid.new
|
134
|
+
assert_equal(true, g != g2)
|
135
|
+
assert_equal(true, g.to_s != g2.to_s)
|
136
|
+
assert_equal(true, g.raw != g2.raw)
|
137
|
+
assert_equal(true, g.hexdigest != g2.hexdigest)
|
138
|
+
assert_equal(1000, (1..1000).select { |i| g != Guid.new }.length)
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_from_s
|
142
|
+
g = Guid.new
|
143
|
+
g2 = Guid.from_s(g.to_s)
|
144
|
+
assert_equal(g, g2)
|
145
|
+
end
|
146
|
+
|
147
|
+
def test_from_raw
|
148
|
+
g = Guid.new
|
149
|
+
g2 = Guid.from_raw(g.raw)
|
150
|
+
assert_equal(g, g2)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
data/lib/js_spec/rack.rb
ADDED
@@ -25,7 +25,7 @@ module JsSpec
|
|
25
25
|
profile_base = "#{::Dir.tmpdir}/js_spec/firefox"
|
26
26
|
mkdir_p profile_base
|
27
27
|
@profile_dir = "#{profile_base}/#{Time.now.to_i}"
|
28
|
-
@guid =
|
28
|
+
@guid = Guid.new.to_s
|
29
29
|
@request = request
|
30
30
|
@response = response
|
31
31
|
@connection = Server.connection
|
@@ -35,25 +35,29 @@ module JsSpec
|
|
35
35
|
FirefoxRunner.register_instance self
|
36
36
|
spec_url = (request && request['spec_url']) ? request['spec_url'] : spec_suite_url
|
37
37
|
parsed_spec_url = URI.parse(spec_url)
|
38
|
+
selenium_port = (request['selenium_port'] || 4444).to_i
|
38
39
|
@driver = Selenium::SeleniumDriver.new(
|
39
40
|
request['selenium_host'] || 'localhost',
|
40
|
-
|
41
|
+
selenium_port,
|
41
42
|
'*firefox',
|
42
43
|
"#{parsed_spec_url.scheme}://#{parsed_spec_url.host}:#{parsed_spec_url.port}"
|
43
44
|
)
|
44
|
-
|
45
|
+
begin
|
46
|
+
driver.start
|
47
|
+
rescue Errno::ECONNREFUSED => e
|
48
|
+
raise Errno::ECONNREFUSED, "Cannot connect to Selenium Server on port #{selenium_port}. To start the selenium server, run `selenium`."
|
49
|
+
end
|
45
50
|
Thread.start do
|
46
51
|
url = "#{spec_url}?guid=#{guid}"
|
47
52
|
driver.open(url)
|
48
53
|
end
|
49
|
-
response.status =
|
54
|
+
response.status = 200
|
50
55
|
end
|
51
56
|
|
52
57
|
def finalize(text)
|
53
58
|
driver.stop
|
54
|
-
response.status = 200
|
55
59
|
response.body = text
|
56
|
-
connection.
|
60
|
+
connection.send_body(response)
|
57
61
|
end
|
58
62
|
|
59
63
|
protected
|
@@ -0,0 +1,11 @@
|
|
1
|
+
dir = File.dirname(__FILE__)
|
2
|
+
require "#{dir}/resources/runners"
|
3
|
+
require "#{dir}/resources/runners/firefox_runner"
|
4
|
+
require "#{dir}/resources/spec_runner"
|
5
|
+
require "#{dir}/resources/spec_file_runner"
|
6
|
+
require "#{dir}/resources/spec_dir_runner"
|
7
|
+
require "#{dir}/resources/file"
|
8
|
+
require "#{dir}/resources/dir"
|
9
|
+
require "#{dir}/resources/web_root"
|
10
|
+
require "#{dir}/resources/suite"
|
11
|
+
require "#{dir}/resources/suite_finish"
|
data/lib/js_spec/server.rb
CHANGED
@@ -33,11 +33,10 @@ module JsSpec
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def run(options)
|
36
|
-
::Thin::Server.
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
)
|
36
|
+
server = ::Thin::Server.new(options[:Host], options[:Port], self)
|
37
|
+
server.backend = ::Thin::Backends::JsSpecServer.new(options[:Host], options[:Port])
|
38
|
+
server.backend.server = server
|
39
|
+
server.start!
|
41
40
|
end
|
42
41
|
|
43
42
|
def call(env)
|
@@ -6,25 +6,23 @@ module Thin
|
|
6
6
|
|
7
7
|
env = @request.env
|
8
8
|
env['js_spec.connection'] = self
|
9
|
-
status, headers, body = @app.call(env)
|
10
|
-
|
11
|
-
|
9
|
+
@response.status, @response.headers, @response.body = @app.call(env)
|
10
|
+
send_data @response.head
|
11
|
+
unless @response.body.empty?
|
12
|
+
send_body @response.body
|
12
13
|
end
|
13
|
-
rescue
|
14
|
-
handle_error
|
14
|
+
rescue Exception => e
|
15
|
+
handle_error e
|
15
16
|
end
|
16
17
|
|
17
|
-
def
|
18
|
-
|
19
|
-
@response.persistent! if @request.persistent?
|
20
|
-
@response.each do |chunk|
|
21
|
-
trace { chunk }
|
18
|
+
def send_body(rack_response)
|
19
|
+
rack_response.each do |chunk|
|
22
20
|
send_data chunk
|
23
21
|
end
|
24
22
|
# If no more request on that same connection, we close it.
|
25
23
|
close_connection_after_writing unless persistent?
|
26
|
-
rescue
|
27
|
-
handle_error
|
24
|
+
rescue Exception => e
|
25
|
+
handle_error e
|
28
26
|
ensure
|
29
27
|
@request.close rescue nil
|
30
28
|
@response.close rescue nil
|
@@ -34,8 +32,9 @@ module Thin
|
|
34
32
|
post_init if persistent?
|
35
33
|
end
|
36
34
|
|
37
|
-
def handle_error
|
38
|
-
log "!! Unexpected error while processing request: #{
|
35
|
+
def handle_error(error)
|
36
|
+
log "!! Unexpected error while processing request: #{error.message}"
|
37
|
+
log error.backtrace
|
39
38
|
log_error
|
40
39
|
close_connection rescue nil
|
41
40
|
end
|
data/lib/js_spec/thin.rb
ADDED
data/lib/js_spec.rb
CHANGED
@@ -1,34 +1,27 @@
|
|
1
1
|
require "rubygems"
|
2
|
+
gem "eventmachine", "0.10.0"
|
3
|
+
gem "thin", "0.8.0"
|
4
|
+
|
2
5
|
require "thin"
|
3
6
|
require "fileutils"
|
4
7
|
require "tmpdir"
|
5
8
|
require "timeout"
|
6
|
-
require "uuid"
|
7
9
|
require "cgi"
|
8
10
|
require "net/http"
|
9
11
|
require "selenium"
|
10
12
|
require "optparse"
|
11
13
|
|
12
14
|
dir = File.dirname(__FILE__)
|
13
|
-
require "#{dir}/js_spec/
|
14
|
-
require "#{dir}/js_spec/thin
|
15
|
-
require "#{dir}/js_spec/rack
|
16
|
-
require "#{dir}/js_spec/resources
|
17
|
-
require "#{dir}/js_spec/resources/runners/firefox_runner"
|
15
|
+
require "#{dir}/js_spec/guid"
|
16
|
+
require "#{dir}/js_spec/thin"
|
17
|
+
require "#{dir}/js_spec/rack"
|
18
|
+
require "#{dir}/js_spec/resources"
|
18
19
|
|
19
20
|
require "#{dir}/js_spec/client"
|
20
21
|
require "#{dir}/js_spec/server"
|
21
22
|
require "#{dir}/js_spec/rails_server"
|
22
|
-
require "#{dir}/js_spec/resources/spec_runner"
|
23
|
-
require "#{dir}/js_spec/resources/spec_file_runner"
|
24
|
-
require "#{dir}/js_spec/resources/spec_dir_runner"
|
25
|
-
require "#{dir}/js_spec/resources/file"
|
26
|
-
require "#{dir}/js_spec/resources/dir"
|
27
|
-
require "#{dir}/js_spec/resources/web_root"
|
28
|
-
require "#{dir}/js_spec/resources/suite"
|
29
|
-
require "#{dir}/js_spec/resources/suite_finish"
|
30
23
|
|
31
24
|
module JsSpec
|
32
|
-
DEFAULT_HOST = "
|
25
|
+
DEFAULT_HOST = "0.0.0.0"
|
33
26
|
DEFAULT_PORT = 8080
|
34
27
|
end
|
@@ -8,7 +8,7 @@ module JsSpec
|
|
8
8
|
before do
|
9
9
|
Thread.current[:connection] = connection
|
10
10
|
@driver = "Selenium Driver"
|
11
|
-
stub(Selenium::SeleniumDriver).new('localhost', 4444, '*firefox', 'http://
|
11
|
+
stub(Selenium::SeleniumDriver).new('localhost', 4444, '*firefox', 'http://0.0.0.0:8080') do
|
12
12
|
driver
|
13
13
|
end
|
14
14
|
end
|
@@ -29,7 +29,7 @@ module JsSpec
|
|
29
29
|
dont_allow(EventMachine).close_connection
|
30
30
|
runner.post(request, response)
|
31
31
|
|
32
|
-
response.
|
32
|
+
response.body.should be_empty
|
33
33
|
end
|
34
34
|
|
35
35
|
describe "when a selenium_host parameter is passed into the request" do
|
@@ -40,7 +40,7 @@ module JsSpec
|
|
40
40
|
end
|
41
41
|
|
42
42
|
it "starts the Selenium Driver with the passed in selenium_host" do
|
43
|
-
mock(Selenium::SeleniumDriver).new('another-machine', 4444, '*firefox', 'http://
|
43
|
+
mock(Selenium::SeleniumDriver).new('another-machine', 4444, '*firefox', 'http://0.0.0.0:8080') do
|
44
44
|
driver
|
45
45
|
end
|
46
46
|
runner.post(request, response)
|
@@ -55,7 +55,7 @@ module JsSpec
|
|
55
55
|
end
|
56
56
|
|
57
57
|
it "starts the Selenium Driver from localhost" do
|
58
|
-
mock(Selenium::SeleniumDriver).new('localhost', 4444, '*firefox', 'http://
|
58
|
+
mock(Selenium::SeleniumDriver).new('localhost', 4444, '*firefox', 'http://0.0.0.0:8080') do
|
59
59
|
driver
|
60
60
|
end
|
61
61
|
runner.post(request, response)
|
@@ -70,7 +70,7 @@ module JsSpec
|
|
70
70
|
end
|
71
71
|
|
72
72
|
it "starts the Selenium Driver with the passed in selenium_port" do
|
73
|
-
mock(Selenium::SeleniumDriver).new('localhost', 4000, '*firefox', 'http://
|
73
|
+
mock(Selenium::SeleniumDriver).new('localhost', 4000, '*firefox', 'http://0.0.0.0:8080') do
|
74
74
|
driver
|
75
75
|
end
|
76
76
|
runner.post(request, response)
|
@@ -85,7 +85,7 @@ module JsSpec
|
|
85
85
|
end
|
86
86
|
|
87
87
|
it "starts the Selenium Driver from localhost" do
|
88
|
-
mock(Selenium::SeleniumDriver).new('localhost', 4444, '*firefox', 'http://
|
88
|
+
mock(Selenium::SeleniumDriver).new('localhost', 4444, '*firefox', 'http://0.0.0.0:8080') do
|
89
89
|
driver
|
90
90
|
end
|
91
91
|
runner.post(request, response)
|
@@ -111,14 +111,14 @@ module JsSpec
|
|
111
111
|
describe "when a spec_url is not passed into the request" do
|
112
112
|
before do
|
113
113
|
request['spec_url'].should be_nil
|
114
|
-
mock(Selenium::SeleniumDriver).new('localhost', 4444, '*firefox', 'http://
|
114
|
+
mock(Selenium::SeleniumDriver).new('localhost', 4444, '*firefox', 'http://0.0.0.0:8080') do
|
115
115
|
driver
|
116
116
|
end
|
117
117
|
end
|
118
118
|
|
119
119
|
it "uses Selenium to run the entire spec suite in Firefox" do
|
120
120
|
mock(driver).start
|
121
|
-
mock(driver).open("http://
|
121
|
+
mock(driver).open("http://0.0.0.0:8080/specs?guid=#{runner.guid}")
|
122
122
|
|
123
123
|
runner.post(request, response)
|
124
124
|
end
|
@@ -40,7 +40,7 @@ module JsSpec
|
|
40
40
|
doc.at("link[@href='/core/JSSpec.css']").should exist
|
41
41
|
doc.at("script[@src='/core/JSSpec.js']").should exist
|
42
42
|
doc.at("script[@src='/core/JSSpecExtensions.js']").should exist
|
43
|
-
doc.at("body").
|
43
|
+
doc.at("body/#js_spec_content").should_not be_nil
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
@@ -14,35 +14,49 @@ module Thin
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
describe "
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
describe "and the call is successful" do
|
18
|
+
describe "and the body is not empty" do
|
19
|
+
attr_reader :somedir_resource
|
20
|
+
before do
|
21
|
+
mock(app = Object.new).call(is_a(Hash)) do
|
22
|
+
[200, {}, 'The Body']
|
23
|
+
end
|
24
|
+
connection.app = app
|
25
|
+
end
|
26
|
+
|
27
|
+
it "sends the response to the socket and closes the connection" do
|
28
|
+
mock(connection).close_connection_after_writing
|
29
|
+
connection.receive_data "GET /specs HTTP/1.1\r\nHost: _\r\n\r\n"
|
30
|
+
result.should include("The Body")
|
22
31
|
end
|
23
|
-
connection.app = app
|
24
32
|
end
|
25
33
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
34
|
+
describe "and the body is empty" do
|
35
|
+
attr_reader :somedir_resource
|
36
|
+
before do
|
37
|
+
mock(app = Object.new).call(is_a(Hash)) do
|
38
|
+
[200, {}, []]
|
39
|
+
end
|
40
|
+
connection.app = app
|
41
|
+
end
|
42
|
+
|
43
|
+
it "keeps the connection open" do
|
44
|
+
dont_allow(connection).close_connection_after_writing
|
45
|
+
connection.receive_data "GET /specs HTTP/1.1\r\nHost: _\r\n\r\n"
|
46
|
+
end
|
30
47
|
end
|
31
48
|
end
|
32
49
|
|
33
|
-
describe "
|
34
|
-
|
35
|
-
before do
|
50
|
+
describe "and the call raises an error" do
|
51
|
+
it "logs the error and closes the connection" do
|
36
52
|
mock(app = Object.new).call(is_a(Hash)) do
|
37
|
-
|
53
|
+
raise "An Error"
|
38
54
|
end
|
39
55
|
connection.app = app
|
40
|
-
|
56
|
+
mock(connection).log(anything).at_least(1)
|
57
|
+
mock(connection).close_connection
|
41
58
|
|
42
|
-
it "does not send data to the socket and keeps it open" do
|
43
|
-
dont_allow(connection).close_connection_after_writing
|
44
59
|
connection.receive_data "GET /specs HTTP/1.1\r\nHost: _\r\n\r\n"
|
45
|
-
result.should_not include("The Body")
|
46
60
|
end
|
47
61
|
end
|
48
62
|
end
|
@@ -53,7 +53,7 @@ module Spec::Example::ExampleMethods
|
|
53
53
|
stub(EventMachine).send_data do
|
54
54
|
raise "Calls to EventMachine.send_data must be mocked or stubbed"
|
55
55
|
end
|
56
|
-
@connection = Thin::JsSpecConnection.new(
|
56
|
+
@connection = Thin::JsSpecConnection.new(Guid.new)
|
57
57
|
stub(EventMachine).send_data {raise "EventMachine.send_data must be handled"}
|
58
58
|
stub(EventMachine).close_connection {raise "EventMachine.close_connection must be handled"}
|
59
59
|
@server = JsSpec::Server.instance
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: js_spec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Takita & Nathan Sobo
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-04-
|
12
|
+
date: 2008-04-22 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -54,13 +54,13 @@ files:
|
|
54
54
|
- CHANGES
|
55
55
|
- README
|
56
56
|
- init.rb
|
57
|
+
- lib/js_spec/rack.rb
|
57
58
|
- lib/js_spec/thin/backends/js_spec_server.rb
|
58
59
|
- lib/js_spec/thin/js_spec_connection.rb
|
59
|
-
- lib/js_spec/rack/
|
60
|
+
- lib/js_spec/rack/commonlogger.rb
|
60
61
|
- lib/js_spec/resources/spec_file_runner.rb
|
61
62
|
- lib/js_spec/resources/spec_runner.rb
|
62
63
|
- lib/js_spec/resources/dir.rb
|
63
|
-
- lib/js_spec/resources/runners/firefox1_runner.rb
|
64
64
|
- lib/js_spec/resources/runners/firefox_runner.rb
|
65
65
|
- lib/js_spec/resources/suite_finish.rb
|
66
66
|
- lib/js_spec/resources/spec_dir_runner.rb
|
@@ -69,6 +69,9 @@ files:
|
|
69
69
|
- lib/js_spec/resources/suite.rb
|
70
70
|
- lib/js_spec/resources/runners.rb
|
71
71
|
- lib/js_spec/rails_server.rb
|
72
|
+
- lib/js_spec/resources.rb
|
73
|
+
- lib/js_spec/thin.rb
|
74
|
+
- lib/js_spec/guid.rb
|
72
75
|
- lib/js_spec/server.rb
|
73
76
|
- lib/js_spec/client.rb
|
74
77
|
- lib/js_spec.rb
|
@@ -89,7 +92,6 @@ files:
|
|
89
92
|
- spec/integration/integration_spec.rb
|
90
93
|
- spec/integration_suite.rb
|
91
94
|
- spec/unit/thin/js_spec_connection_spec.rb
|
92
|
-
- spec/unit/rack/response_spec.rb
|
93
95
|
- spec/unit/js_spec/resources/spec_file_runner_spec.rb
|
94
96
|
- spec/unit/js_spec/resources/file_spec.rb
|
95
97
|
- spec/unit/js_spec/resources/spec_dir_runner_spec.rb
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require File.expand_path("#{File.dirname(__FILE__)}/../unit_spec_helper")
|
2
|
-
|
3
|
-
module Rack
|
4
|
-
describe Response do
|
5
|
-
describe "#ready?" do
|
6
|
-
attr_reader :response
|
7
|
-
describe "when there is a status" do
|
8
|
-
before do
|
9
|
-
@response = Response.new
|
10
|
-
@response.status.should_not be_nil
|
11
|
-
end
|
12
|
-
|
13
|
-
it "returns true" do
|
14
|
-
response.should be_ready
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
describe "when there is no status" do
|
19
|
-
before do
|
20
|
-
@response = Response.new
|
21
|
-
response.status = nil
|
22
|
-
end
|
23
|
-
|
24
|
-
it "returns true" do
|
25
|
-
response.should_not be_ready
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|