polonium 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 +7 -0
- data/README +27 -12
- data/Rakefile +2 -2
- data/init.rb +9 -0
- data/lib/polonium/adapters/rspec.rb +19 -13
- data/lib/polonium/adapters/test_unit.rb +1 -1
- data/lib/polonium/configuration.rb +32 -97
- data/lib/polonium/driver.rb +25 -28
- data/lib/polonium/dsl/selenium_dsl.rb +67 -8
- data/lib/polonium/element.rb +60 -30
- data/lib/polonium/page.rb +13 -2
- data/lib/polonium/server_runners/external_server_runner.rb +20 -0
- data/lib/polonium/server_runners/mongrel_server_runner.rb +63 -0
- data/lib/polonium/server_runners/server_runner.rb +36 -0
- data/lib/polonium/server_runners/webrick_server_runner.rb +49 -0
- data/lib/polonium/test_case.rb +1 -19
- data/lib/polonium/wait_for.rb +4 -1
- data/lib/polonium.rb +6 -4
- data/spec/polonium/configuration_spec.rb +41 -99
- data/spec/polonium/driver_spec.rb +112 -62
- data/spec/polonium/element_spec.rb +69 -24
- data/spec/polonium/server_runners/external_server_runner_spec.rb +33 -0
- data/spec/polonium/server_runners/mongrel_server_runner_spec.rb +69 -0
- data/spec/polonium/server_runners/server_runner_spec.rb +36 -0
- data/spec/polonium/server_runners/webrick_server_runner_spec.rb +121 -0
- data/spec/polonium/test_case_spec.rb +538 -649
- data/spec/rspec/options_spec.rb +23 -22
- data/spec/spec_helper.rb +0 -18
- data/spec/spec_suite.rb +1 -1
- data/spec/test_unit/testrunnermediator_spec.rb +2 -2
- metadata +50 -41
- data/lib/polonium/dsl/test_unit_dsl.rb +0 -61
- data/lib/polonium/mongrel_selenium_server_runner.rb +0 -37
- data/lib/polonium/server_runner.rb +0 -33
- data/lib/polonium/webrick_selenium_server_runner.rb +0 -33
- data/spec/polonium/mongrel_selenium_server_runner_spec.rb +0 -35
- data/spec/polonium/server_runner_spec.rb +0 -42
- data/spec/polonium/webrick_selenium_server_runner_spec.rb +0 -117
data/lib/polonium/element.rb
CHANGED
@@ -9,16 +9,15 @@ module Polonium
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def assert_element_present(params={})
|
12
|
-
driver.
|
12
|
+
driver.assert_element_present(locator, params)
|
13
13
|
end
|
14
14
|
|
15
15
|
def assert_element_not_present(params={})
|
16
|
-
driver.
|
16
|
+
driver.assert_element_not_present(locator, params)
|
17
17
|
end
|
18
18
|
|
19
19
|
def assert_value(expected_value)
|
20
|
-
|
21
|
-
wait_for do |configuration|
|
20
|
+
wait_for_element do |configuration|
|
22
21
|
actual_value = driver.get_value(locator)
|
23
22
|
configuration.message = "Expected '#{locator}' to be '#{expected_value}' but was '#{actual_value}'"
|
24
23
|
has_value? expected_value, actual_value
|
@@ -26,18 +25,25 @@ module Polonium
|
|
26
25
|
end
|
27
26
|
|
28
27
|
def assert_attribute(expected_name, expected_value)
|
29
|
-
assert_element_present
|
30
28
|
attr_locator = "#{locator}@#{expected_name}"
|
31
|
-
|
29
|
+
wait_for_element do |configuration|
|
32
30
|
actual = driver.get_attribute(attr_locator) #todo: actual value
|
33
31
|
configuration.message = "Expected attribute '#{attr_locator}' to be '#{expected_value}' but was '#{actual}'"
|
34
32
|
values_match? actual, expected_value
|
35
33
|
end
|
36
34
|
end
|
37
35
|
|
36
|
+
def assert_attribute_does_not_contain(attribute_name, illegal_value)
|
37
|
+
attr_locator = "#{locator}@#{attribute_name}"
|
38
|
+
wait_for_element do |configuration|
|
39
|
+
actual = driver.get_attribute(attr_locator) #todo: actual value
|
40
|
+
configuration.message = "Expected attribute '#{attr_locator}' to not contain '#{illegal_value}' but was '#{actual}'"
|
41
|
+
!actual.match(illegal_value)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
38
45
|
def assert_selected(expected_value)
|
39
|
-
|
40
|
-
wait_for do |configuration|
|
46
|
+
wait_for_element do |configuration|
|
41
47
|
actual = driver.get_selected_label(locator)
|
42
48
|
configuration.message = "Expected '#{locator}' to be selected with '#{expected_value}' but was '#{actual}"
|
43
49
|
values_match? actual, expected_value
|
@@ -45,42 +51,37 @@ module Polonium
|
|
45
51
|
end
|
46
52
|
|
47
53
|
def assert_visible(options={})
|
48
|
-
assert_element_present
|
49
54
|
options = {
|
50
55
|
:message => "Expected '#{locator}' to be visible, but it wasn't"
|
51
56
|
}.merge(options)
|
52
|
-
|
57
|
+
wait_for_element(options) do
|
53
58
|
driver.is_visible(locator)
|
54
59
|
end
|
55
60
|
end
|
56
61
|
|
57
62
|
def assert_not_visible(options={})
|
58
|
-
assert_element_present
|
59
63
|
options = {
|
60
64
|
:message => "Expected '#{locator}' to be hidden, but it wasn't"
|
61
65
|
}.merge(options)
|
62
|
-
|
66
|
+
wait_for_element(options) do
|
63
67
|
!driver.is_visible(locator)
|
64
68
|
end
|
65
69
|
end
|
66
70
|
|
67
71
|
def assert_checked
|
68
|
-
|
69
|
-
wait_for(:message => "Expected '#{locator}' to be checked") do
|
72
|
+
wait_for_element(:message => "Expected '#{locator}' to be checked") do
|
70
73
|
driver.is_checked(locator)
|
71
74
|
end
|
72
75
|
end
|
73
76
|
|
74
77
|
def assert_not_checked
|
75
|
-
|
76
|
-
wait_for(:message => "Expected '#{locator}' to not be checked") do
|
78
|
+
wait_for_element(:message => "Expected '#{locator}' to not be checked") do
|
77
79
|
!driver.is_checked(locator)
|
78
80
|
end
|
79
81
|
end
|
80
82
|
|
81
83
|
def assert_text(expected_text, options={})
|
82
|
-
|
83
|
-
wait_for(options) do |configuration|
|
84
|
+
wait_for_element(options) do |configuration|
|
84
85
|
actual = driver.get_text(locator)
|
85
86
|
configuration.message = "Expected text '#{expected_text}' to be full contents of #{locator} but was '#{actual}')"
|
86
87
|
values_match? actual, expected_text
|
@@ -89,34 +90,32 @@ module Polonium
|
|
89
90
|
|
90
91
|
def assert_contains(expected_text, options={})
|
91
92
|
return assert_contains_in_order(*expected_text) if expected_text.is_a? Array
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
93
|
+
wait_for_element(options) do |configuration|
|
94
|
+
if contains?(expected_text)
|
95
|
+
true
|
96
|
+
else
|
97
|
+
configuration.message = "#{locator} should contain #{expected_text}"
|
98
|
+
false
|
99
|
+
end
|
98
100
|
end
|
99
101
|
end
|
100
102
|
|
101
103
|
def assert_does_not_contain(expected_text, options={})
|
102
|
-
|
103
|
-
wait_for(options) do
|
104
|
+
wait_for_element(options) do
|
104
105
|
!contains?(expected_text)
|
105
106
|
end
|
106
107
|
end
|
107
108
|
|
108
109
|
def assert_next_sibling(expected_sibling_id, options = {})
|
109
|
-
assert_element_present
|
110
110
|
eval_js = "this.page().findElement('#{locator}').nextSibling.id"
|
111
|
-
|
111
|
+
wait_for_element(:message => "id '#{locator}' should be next to '#{expected_sibling_id}'") do
|
112
112
|
actual_sibling_id = driver.get_eval(eval_js)
|
113
113
|
expected_sibling_id == actual_sibling_id
|
114
114
|
end
|
115
115
|
end
|
116
116
|
|
117
117
|
def assert_contains_in_order(*text_fragments)
|
118
|
-
|
119
|
-
wait_for do |configuration|
|
118
|
+
wait_for_element do |configuration|
|
120
119
|
success = false
|
121
120
|
|
122
121
|
html = driver.get_text(locator)
|
@@ -139,7 +138,26 @@ module Polonium
|
|
139
138
|
success
|
140
139
|
end
|
141
140
|
end
|
141
|
+
|
142
|
+
def assert_number_of_children(expected_number)
|
143
|
+
eval_js = "this.page().findElement('#{locator}').childNodes.length"
|
144
|
+
wait_for_element(:message => "id '#{locator}' should contain exactly #{expected_number} children") do
|
145
|
+
actual_number = driver.get_eval(eval_js)
|
146
|
+
expected_number == actual_number.to_i
|
147
|
+
end
|
148
|
+
end
|
142
149
|
|
150
|
+
def click
|
151
|
+
driver.click locator
|
152
|
+
end
|
153
|
+
|
154
|
+
def type(text)
|
155
|
+
driver.type(locator, text)
|
156
|
+
end
|
157
|
+
|
158
|
+
def select(option_locator)
|
159
|
+
driver.select(locator, option_locator)
|
160
|
+
end
|
143
161
|
|
144
162
|
def is_present?
|
145
163
|
driver.is_element_present(locator)
|
@@ -169,6 +187,18 @@ module Polonium
|
|
169
187
|
end
|
170
188
|
|
171
189
|
protected
|
190
|
+
def wait_for_element(options={})
|
191
|
+
wait_for(options) do |configuration|
|
192
|
+
if is_present?
|
193
|
+
configuration.message = ""
|
194
|
+
yield(configuration)
|
195
|
+
else
|
196
|
+
configuration.message = "Expected element '#{locator}' to be present, but it was not"
|
197
|
+
false
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
172
202
|
def method_missing(method_name, *args, &blk)
|
173
203
|
if driver.respond_to?(method_name)
|
174
204
|
driver_args = [locator] + args
|
data/lib/polonium/page.rb
CHANGED
@@ -2,7 +2,18 @@ module Polonium
|
|
2
2
|
class Page
|
3
3
|
include WaitFor, ValuesMatch
|
4
4
|
attr_reader :driver
|
5
|
-
PAGE_LOADED_COMMAND =
|
5
|
+
PAGE_LOADED_COMMAND = <<-JS
|
6
|
+
(function(selenium) {
|
7
|
+
BrowserBot.prototype.bodyText = function() {
|
8
|
+
if (!this.getDocument().body) {
|
9
|
+
return "";
|
10
|
+
}
|
11
|
+
return getText(this.getDocument().body);
|
12
|
+
};
|
13
|
+
selenium.browserbot.bodyText = BrowserBot.prototype.bodyText;
|
14
|
+
return selenium.browserbot.getDocument().body ? true : false;
|
15
|
+
})(this);
|
16
|
+
JS
|
6
17
|
|
7
18
|
def initialize(driver)
|
8
19
|
@driver = driver
|
@@ -91,4 +102,4 @@ module Polonium
|
|
91
102
|
end
|
92
103
|
end
|
93
104
|
end
|
94
|
-
end
|
105
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Polonium
|
2
|
+
module ServerRunners
|
3
|
+
class ExternalServerRunner < ServerRunner
|
4
|
+
protected
|
5
|
+
def start_server
|
6
|
+
stop_server
|
7
|
+
system("cd #{configuration.rails_root}; script/server -e #{configuration.rails_env} -p #{configuration.internal_app_server_port} -c #{configuration.rails_root}")
|
8
|
+
rescue Exception => e
|
9
|
+
puts e.message
|
10
|
+
puts e.backtrace
|
11
|
+
raise e
|
12
|
+
end
|
13
|
+
|
14
|
+
def stop_server
|
15
|
+
cmd = "ps ax | grep 'script/server -e #{configuration.rails_env}' | sed /grep/d | awk '{print $1}' | xargs kill -9 2>/dev/null"
|
16
|
+
system(cmd)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Polonium
|
2
|
+
module ServerRunners
|
3
|
+
class MongrelServerRunner < ServerRunner
|
4
|
+
def start
|
5
|
+
mongrel_configurator = create_mongrel_configurator
|
6
|
+
initialize_server(mongrel_configurator)
|
7
|
+
|
8
|
+
Thread.start do
|
9
|
+
start_server(mongrel_configurator)
|
10
|
+
end
|
11
|
+
@started = true
|
12
|
+
end
|
13
|
+
|
14
|
+
protected
|
15
|
+
def start_server(mongrel_configurator)
|
16
|
+
mongrel_configurator.run
|
17
|
+
mongrel_configurator.log "Mongrel running at #{configuration.internal_app_server_host}:#{configuration.internal_app_server_port}"
|
18
|
+
mongrel_configurator.join
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize_server(config)
|
22
|
+
configuration = self.configuration
|
23
|
+
config.listener do |*args|
|
24
|
+
mongrel = (args.first || self)
|
25
|
+
mongrel.log "Starting Rails in environment #{defaults[:environment]} ..."
|
26
|
+
mongrel.uri "/", :handler => mongrel.rails
|
27
|
+
mongrel.log "Rails loaded."
|
28
|
+
|
29
|
+
mongrel.log "Loading any Rails specific GemPlugins"
|
30
|
+
mongrel.load_plugins
|
31
|
+
configuration.app_server_initialization.call(mongrel)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def stop_server
|
36
|
+
end
|
37
|
+
|
38
|
+
def create_mongrel_configurator #:nodoc:
|
39
|
+
dir = File.dirname(__FILE__)
|
40
|
+
require 'mongrel/rails'
|
41
|
+
settings = {
|
42
|
+
:host => configuration.internal_app_server_host,
|
43
|
+
:port => configuration.internal_app_server_port,
|
44
|
+
:cwd => configuration.rails_root,
|
45
|
+
:log_file => "#{configuration.rails_root}/log/mongrel.log",
|
46
|
+
:pid_file => "#{configuration.rails_root}/log/mongrel.pid",
|
47
|
+
:environment => configuration.rails_env,
|
48
|
+
:docroot => "#{configuration.rails_root}/public",
|
49
|
+
:mime_map => nil,
|
50
|
+
:daemon => false,
|
51
|
+
:debug => false,
|
52
|
+
:includes => ["mongrel"],
|
53
|
+
:config_script => nil
|
54
|
+
}
|
55
|
+
|
56
|
+
configurator = Mongrel::Rails::RailsConfigurator.new(settings) do
|
57
|
+
log "Starting Mongrel in #{defaults[:environment]} mode at #{defaults[:host]}:#{defaults[:port]}"
|
58
|
+
end
|
59
|
+
configurator
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Polonium
|
2
|
+
module ServerRunners
|
3
|
+
class ServerRunner
|
4
|
+
attr_reader :configuration
|
5
|
+
def initialize(configuration)
|
6
|
+
@configuration = configuration
|
7
|
+
@started = false
|
8
|
+
end
|
9
|
+
|
10
|
+
def start
|
11
|
+
Thread.start do
|
12
|
+
start_server
|
13
|
+
end
|
14
|
+
@started = true
|
15
|
+
end
|
16
|
+
|
17
|
+
def stop
|
18
|
+
stop_server
|
19
|
+
@started = false
|
20
|
+
end
|
21
|
+
|
22
|
+
def started?
|
23
|
+
@started
|
24
|
+
end
|
25
|
+
|
26
|
+
protected
|
27
|
+
def start_server
|
28
|
+
raise NotImplementedError.new("this is abstract!")
|
29
|
+
end
|
30
|
+
|
31
|
+
def stop_server
|
32
|
+
raise NotImplementedError.new("this is abstract!")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Polonium
|
2
|
+
module ServerRunners
|
3
|
+
class WebrickServerRunner < ServerRunner
|
4
|
+
attr_accessor :server
|
5
|
+
|
6
|
+
def initialize(configuration)
|
7
|
+
require 'webrick_server'
|
8
|
+
super
|
9
|
+
end
|
10
|
+
|
11
|
+
protected
|
12
|
+
def start_server
|
13
|
+
@server = create_webrick_server
|
14
|
+
mount_parameters = {
|
15
|
+
:port => configuration.internal_app_server_port,
|
16
|
+
:ip => configuration.internal_app_server_host,
|
17
|
+
:environment => configuration.rails_env.dup,
|
18
|
+
:server_root => configuration.server_root,
|
19
|
+
:server_type => WEBrick::SimpleServer,
|
20
|
+
:charset => "UTF-8",
|
21
|
+
:mime_types => WEBrick::HTTPUtils::DefaultMimeTypes,
|
22
|
+
:working_directory => File.expand_path(configuration.rails_root.to_s)
|
23
|
+
}
|
24
|
+
server.mount('/', DispatchServlet, mount_parameters)
|
25
|
+
|
26
|
+
trap("INT") { stop_server }
|
27
|
+
|
28
|
+
require File.expand_path("#{configuration.rails_root}/config/environment")
|
29
|
+
require "dispatcher"
|
30
|
+
server.start
|
31
|
+
end
|
32
|
+
|
33
|
+
def stop_server
|
34
|
+
server.shutdown if server
|
35
|
+
end
|
36
|
+
|
37
|
+
def create_webrick_server #:nodoc:
|
38
|
+
WEBrick::HTTPServer.new({
|
39
|
+
:Port => configuration.internal_app_server_port,
|
40
|
+
:BindAddress => configuration.internal_app_server_host,
|
41
|
+
:ServerType => WEBrick::SimpleServer,
|
42
|
+
:MimeTypes => WEBrick::HTTPUtils::DefaultMimeTypes,
|
43
|
+
:Logger => configuration.new_logger,
|
44
|
+
:AccessLog => []
|
45
|
+
})
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/polonium/test_case.rb
CHANGED
@@ -12,27 +12,9 @@ module Polonium
|
|
12
12
|
self.use_transactional_fixtures = false
|
13
13
|
self.use_instantiated_fixtures = true
|
14
14
|
|
15
|
-
include
|
15
|
+
include SeleniumDsl
|
16
16
|
def setup
|
17
|
-
# set "setup_once" to true
|
18
|
-
# to prevent fixtures from being re-loaded and data deleted from the DB.
|
19
|
-
# this is handy if you want to generate a DB full of sample data
|
20
|
-
# from the tests. Make sure none of your selenium tests manually
|
21
|
-
# reset data!
|
22
|
-
#TODO: make this configurable
|
23
|
-
setup_once = false
|
24
|
-
|
25
17
|
raise "Cannot use transactional fixtures if ActiveRecord concurrency is turned on (which is required for Selenium tests to work)." if self.class.use_transactional_fixtures
|
26
|
-
unless setup_once
|
27
|
-
ActiveRecord::Base.connection.update('SET FOREIGN_KEY_CHECKS = 0')
|
28
|
-
super
|
29
|
-
ActiveRecord::Base.connection.update('SET FOREIGN_KEY_CHECKS = 1')
|
30
|
-
else
|
31
|
-
unless InstanceMethods.const_defined?("ALREADY_SETUP_ONCE")
|
32
|
-
super
|
33
|
-
InstanceMethods.const_set("ALREADY_SETUP_ONCE", true)
|
34
|
-
end
|
35
|
-
end
|
36
18
|
@selenium_driver = configuration.driver
|
37
19
|
end
|
38
20
|
|
data/lib/polonium/wait_for.rb
CHANGED
@@ -12,7 +12,10 @@ module Polonium
|
|
12
12
|
configuration = Context.new(message)
|
13
13
|
begin_time = time_class.now
|
14
14
|
while (time_class.now - begin_time) < timeout
|
15
|
-
|
15
|
+
if value = yield(configuration)
|
16
|
+
return value
|
17
|
+
end
|
18
|
+
return value if value
|
16
19
|
sleep 0.25
|
17
20
|
end
|
18
21
|
flunk(configuration.message + " (after #{timeout} sec)")
|
data/lib/polonium.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
+
require 'rubygems'
|
1
2
|
require 'socket'
|
2
3
|
require 'logger'
|
3
4
|
require "stringio"
|
5
|
+
require "resolv-replace"
|
4
6
|
|
5
7
|
require "active_record"
|
6
8
|
|
@@ -13,11 +15,11 @@ require "selenium"
|
|
13
15
|
require "polonium/extensions/module"
|
14
16
|
require "polonium/wait_for"
|
15
17
|
require "polonium/driver"
|
16
|
-
require "polonium/server_runner"
|
17
|
-
require "polonium/
|
18
|
-
require "polonium/
|
18
|
+
require "polonium/server_runners/server_runner"
|
19
|
+
require "polonium/server_runners/external_server_runner"
|
20
|
+
require "polonium/server_runners/mongrel_server_runner"
|
21
|
+
require "polonium/server_runners/webrick_server_runner"
|
19
22
|
require "polonium/dsl/selenium_dsl"
|
20
|
-
require "polonium/dsl/test_unit_dsl"
|
21
23
|
require "polonium/configuration"
|
22
24
|
require "polonium/values_match"
|
23
25
|
require "polonium/page"
|
@@ -1,24 +1,6 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
2
2
|
|
3
3
|
module Polonium
|
4
|
-
describe Configuration, ".instance" do
|
5
|
-
attr_reader :configuration
|
6
|
-
before(:each) do
|
7
|
-
Configuration.instance = nil
|
8
|
-
@configuration = Configuration.new
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should create a new Configuration if it hasn't been called yet" do
|
12
|
-
mock(Configuration).new.returns(configuration)
|
13
|
-
Configuration.instance.should == configuration
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should reuse the existing Configuration if it has been called. So new/establish_environment should only be called once." do
|
17
|
-
Configuration.instance.should_not be_nil
|
18
|
-
dont_allow(Configuration).new
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
4
|
describe Configuration do
|
23
5
|
attr_reader :configuration
|
24
6
|
before(:each) do
|
@@ -86,70 +68,27 @@ module Polonium
|
|
86
68
|
passed_driver.should == driver
|
87
69
|
start_called.should == true
|
88
70
|
end
|
71
|
+
end
|
89
72
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
configuration
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
it "creates webrick http server" do
|
107
|
-
configuration.internal_app_server_port = 4000
|
108
|
-
configuration.internal_app_server_host = "localhost"
|
109
|
-
|
110
|
-
mock_logger = "logger"
|
111
|
-
mock(configuration).new_logger {mock_logger}
|
112
|
-
mock(WEBrick::HTTPServer).new({
|
113
|
-
:Port => 4000,
|
114
|
-
:BindAddress => "localhost",
|
115
|
-
:ServerType => WEBrick::SimpleServer,
|
116
|
-
:MimeTypes => WEBrick::HTTPUtils::DefaultMimeTypes,
|
117
|
-
:Logger => mock_logger,
|
118
|
-
:AccessLog => []
|
119
|
-
})
|
120
|
-
server = configuration.create_webrick_server
|
121
|
-
end
|
122
|
-
|
123
|
-
it "creates Mongrel Server Runner" do
|
124
|
-
server = configuration.create_mongrel_runner
|
125
|
-
server.should be_instance_of(MongrelSeleniumServerRunner)
|
126
|
-
server.configuration.should == configuration
|
127
|
-
server.thread_class.should == Thread
|
128
|
-
end
|
129
|
-
|
130
|
-
it "creates Mongrel configurator" do
|
131
|
-
configuration.internal_app_server_host = "localhost"
|
132
|
-
configuration.internal_app_server_port = 4000
|
133
|
-
configuration.rails_env = "test"
|
134
|
-
configuration.rails_root = rails_root = File.dirname(__FILE__)
|
135
|
-
|
136
|
-
configurator = configuration.create_mongrel_configurator
|
137
|
-
configurator.defaults[:host].should == "localhost"
|
138
|
-
configurator.defaults[:port].should == 4000
|
139
|
-
configurator.defaults[:cwd].should == configuration.rails_root
|
140
|
-
configurator.defaults[:log_file].should == "#{configuration.rails_root}/log/mongrel.log"
|
141
|
-
configurator.defaults[:pid_file].should == "#{configuration.rails_root}/log/mongrel.pid"
|
142
|
-
configurator.defaults[:environment].should == "test"
|
143
|
-
configurator.defaults[:docroot].should == "#{rails_root}/public"
|
144
|
-
configurator.defaults[:mime_map].should be_nil
|
145
|
-
configurator.defaults[:daemon].should == false
|
146
|
-
configurator.defaults[:debug].should == false
|
147
|
-
configurator.defaults[:includes].should == ["mongrel"]
|
148
|
-
configurator.defaults[:config_script].should be_nil
|
73
|
+
describe ".instance" do
|
74
|
+
attr_reader :configuration
|
75
|
+
before(:each) do
|
76
|
+
Configuration.instance = nil
|
77
|
+
@configuration = Configuration.new
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should create a new Configuration if it hasn't been called yet" do
|
81
|
+
mock(Configuration).new.returns(configuration)
|
82
|
+
Configuration.instance.should == configuration
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should reuse the existing Configuration if it has been called. So new/establish_environment should only be called once." do
|
86
|
+
Configuration.instance.should_not be_nil
|
87
|
+
dont_allow(Configuration).new
|
149
88
|
end
|
150
89
|
end
|
151
90
|
|
152
|
-
describe
|
91
|
+
describe "#establish_environment" do
|
153
92
|
attr_reader :configuration
|
154
93
|
before(:each) do
|
155
94
|
@old_configuration = Configuration.instance
|
@@ -296,7 +235,7 @@ module Polonium
|
|
296
235
|
end
|
297
236
|
end
|
298
237
|
|
299
|
-
describe
|
238
|
+
describe "#stop_driver_if_necessary" do
|
300
239
|
attr_reader :configuration
|
301
240
|
before(:each) do
|
302
241
|
@configuration = Configuration.new
|
@@ -330,30 +269,33 @@ module Polonium
|
|
330
269
|
|
331
270
|
end
|
332
271
|
|
333
|
-
describe
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
272
|
+
describe "#create_app_server_runner" do
|
273
|
+
describe "when server engine in mongrel" do
|
274
|
+
it "creates a mongrel server runner" do
|
275
|
+
configuration = Configuration.new
|
276
|
+
configuration.app_server_engine = :mongrel
|
277
|
+
runner = configuration.create_app_server_runner
|
278
|
+
runner.class.should == ServerRunners::MongrelServerRunner
|
279
|
+
runner.configuration.should == configuration
|
280
|
+
end
|
339
281
|
end
|
340
|
-
end
|
341
282
|
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
end
|
283
|
+
describe "when server engine is webrick" do
|
284
|
+
before do
|
285
|
+
Object.const_set :RAILS_ROOT, "foobar"
|
286
|
+
end
|
347
287
|
|
348
|
-
|
349
|
-
|
350
|
-
|
288
|
+
after do
|
289
|
+
Object.instance_eval {remove_const :RAILS_ROOT}
|
290
|
+
end
|
351
291
|
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
292
|
+
it "creates a webrick server runner" do
|
293
|
+
configuration = Configuration.new
|
294
|
+
configuration.app_server_engine = :webrick
|
295
|
+
runner = configuration.create_app_server_runner
|
296
|
+
runner.class.should == ServerRunners::WebrickServerRunner
|
297
|
+
runner.configuration.should == configuration
|
298
|
+
end
|
357
299
|
end
|
358
300
|
end
|
359
301
|
end
|