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/spec/rspec/options_spec.rb
CHANGED
@@ -1,30 +1,31 @@
|
|
1
1
|
require File.expand_path("#{File.dirname(__FILE__)}/rspec_spec_helper")
|
2
2
|
|
3
|
-
describe Spec::Runner::Options
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
describe Spec::Runner::Options do
|
4
|
+
describe "#run_example" do
|
5
|
+
attr_reader :configuration, :app_server_runner, :the_rspec_options
|
6
|
+
before do
|
7
|
+
@original_configuration = Polonium::Configuration.instance
|
8
|
+
@configuration = Polonium::Configuration.new
|
9
|
+
Polonium::Configuration.instance = configuration
|
10
|
+
@the_rspec_options = Spec::Runner::Options.new(StringIO.new, StringIO.new)
|
11
|
+
the_rspec_options.after_suite_parts.push(*rspec_options.after_suite_parts)
|
9
12
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
the_rspec_options.selenium_configuration = configuration
|
14
|
-
the_rspec_options.selenium_app_runner = app_server_runner
|
15
|
-
end
|
13
|
+
configuration.app_server_engine = :mongrel
|
14
|
+
@app_server_runner = configuration.create_app_server_runner
|
15
|
+
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
after do
|
18
|
+
Polonium::Configuration.instance = @original_configuration
|
19
|
+
end
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
it "stops the app server app_server_runner when finished" do
|
22
|
+
mock.proxy(app_server_runner).stop
|
23
|
+
the_rspec_options.run_examples
|
24
|
+
end
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
it "stops the Selenium driver when finished" do
|
27
|
+
mock.proxy(configuration).stop_driver_if_necessary(true)
|
28
|
+
the_rspec_options.run_examples
|
29
|
+
end
|
29
30
|
end
|
30
31
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -15,24 +15,6 @@ require File.dirname(__FILE__) + "/polonium/test_case_spec_helper"
|
|
15
15
|
|
16
16
|
Test::Unit.run = true
|
17
17
|
|
18
|
-
ProcessStub = Struct.new :host, :port, :name, :cmd, :logdir, :is_running unless Object.const_defined?(:ProcessStub)
|
19
|
-
ProcessStub.class_eval do
|
20
|
-
def is_running?
|
21
|
-
self.is_running
|
22
|
-
end
|
23
|
-
def say(msg, options = {})
|
24
|
-
end
|
25
|
-
def run
|
26
|
-
false
|
27
|
-
end
|
28
|
-
def start
|
29
|
-
self.is_running = true
|
30
|
-
end
|
31
|
-
def stop
|
32
|
-
self.is_running = false
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
18
|
Spec::Runner.configure do |config|
|
37
19
|
config.mock_with :rr
|
38
20
|
end
|
data/spec/spec_suite.rb
CHANGED
@@ -10,8 +10,8 @@ describe Test::Unit::UI::TestRunnerMediator do
|
|
10
10
|
suite = Test::Unit::TestSuite.new
|
11
11
|
mediator = Test::Unit::UI::TestRunnerMediator.new(suite)
|
12
12
|
|
13
|
-
runner = driver.
|
14
|
-
mock(driver).
|
13
|
+
runner = driver.create_app_server_runner
|
14
|
+
mock(driver).create_app_server_runner {runner}
|
15
15
|
mock(runner).stop
|
16
16
|
mock(driver).stop_driver_if_necessary(true)
|
17
17
|
mediator.run_suite
|
metadata
CHANGED
@@ -1,50 +1,45 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.4
|
3
|
-
specification_version: 1
|
4
2
|
name: polonium
|
5
3
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2008-01-29 00:00:00 -08:00
|
8
|
-
summary: Selenium RC with enhanced assertions that also runs your rails app.
|
9
|
-
require_paths:
|
10
|
-
- lib
|
11
|
-
email: opensource@pivotallabs.com
|
12
|
-
homepage: http://pivotallabs.com
|
13
|
-
rubyforge_project: pivotalrb
|
14
|
-
description: Selenium RC with enhanced assertions that also runs your rails app.
|
15
|
-
autorequire:
|
16
|
-
default_executable:
|
17
|
-
bindir: bin
|
18
|
-
has_rdoc: true
|
19
|
-
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">"
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 0.0.0
|
24
|
-
version:
|
4
|
+
version: 0.2.0
|
25
5
|
platform: ruby
|
26
|
-
signing_key:
|
27
|
-
cert_chain:
|
28
|
-
post_install_message:
|
29
6
|
authors:
|
30
7
|
- Pivotal Labs
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-07-18 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Selenium RC with Rails integration and enhanced assertions.
|
17
|
+
email: opensource@pivotallabs.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README
|
24
|
+
- CHANGES
|
31
25
|
files:
|
32
26
|
- CHANGES
|
33
27
|
- README
|
34
28
|
- Rakefile
|
29
|
+
- init.rb
|
30
|
+
- lib/polonium/server_runners/webrick_server_runner.rb
|
31
|
+
- lib/polonium/server_runners/external_server_runner.rb
|
32
|
+
- lib/polonium/server_runners/server_runner.rb
|
33
|
+
- lib/polonium/server_runners/mongrel_server_runner.rb
|
35
34
|
- lib/polonium/dsl/selenium_dsl.rb
|
36
|
-
- lib/polonium/dsl/test_unit_dsl.rb
|
37
35
|
- lib/polonium/adapters/test_unit.rb
|
38
36
|
- lib/polonium/adapters/rspec.rb
|
39
37
|
- lib/polonium/element.rb
|
40
|
-
- lib/polonium/mongrel_selenium_server_runner.rb
|
41
38
|
- lib/polonium/extensions/module.rb
|
42
39
|
- lib/polonium/tasks/selenium_test_task.rb
|
43
40
|
- lib/polonium/page.rb
|
44
41
|
- lib/polonium/driver.rb
|
45
|
-
- lib/polonium/webrick_selenium_server_runner.rb
|
46
42
|
- lib/polonium/values_match.rb
|
47
|
-
- lib/polonium/server_runner.rb
|
48
43
|
- lib/polonium/wait_for.rb
|
49
44
|
- lib/polonium/test_case.rb
|
50
45
|
- lib/polonium/configuration.rb
|
@@ -58,34 +53,48 @@ files:
|
|
58
53
|
- spec/main_spec_suite.rb
|
59
54
|
- spec/test_unit/test_unit_spec_helper.rb
|
60
55
|
- spec/test_unit/testrunnermediator_spec.rb
|
56
|
+
- spec/polonium/server_runners/server_runner_spec.rb
|
57
|
+
- spec/polonium/server_runners/mongrel_server_runner_spec.rb
|
58
|
+
- spec/polonium/server_runners/external_server_runner_spec.rb
|
59
|
+
- spec/polonium/server_runners/webrick_server_runner_spec.rb
|
61
60
|
- spec/polonium/driver_spec.rb
|
62
|
-
- spec/polonium/server_runner_spec.rb
|
63
61
|
- spec/polonium/test_case_spec_helper.rb
|
64
62
|
- spec/polonium/test_case_spec.rb
|
65
63
|
- spec/polonium/page_spec.rb
|
66
64
|
- spec/polonium/element_spec.rb
|
67
65
|
- spec/polonium/extensions/module_spec.rb
|
68
66
|
- spec/polonium/test_case_class_method_spec.rb
|
69
|
-
- spec/polonium/webrick_selenium_server_runner_spec.rb
|
70
67
|
- spec/polonium/values_match_spec.rb
|
71
68
|
- spec/polonium/configuration_spec.rb
|
72
|
-
- spec/polonium/mongrel_selenium_server_runner_spec.rb
|
73
69
|
- spec/rspec_spec_suite.rb
|
74
|
-
|
75
|
-
|
70
|
+
has_rdoc: true
|
71
|
+
homepage: http://pivotallabs.com
|
72
|
+
post_install_message:
|
76
73
|
rdoc_options:
|
77
74
|
- --main
|
78
75
|
- README
|
79
76
|
- --inline-source
|
80
77
|
- --line-numbers
|
81
|
-
|
82
|
-
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: "0"
|
85
|
+
version:
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: "0"
|
91
|
+
version:
|
88
92
|
requirements: []
|
89
93
|
|
90
|
-
|
94
|
+
rubyforge_project: pivotalrb
|
95
|
+
rubygems_version: 1.0.1
|
96
|
+
signing_key:
|
97
|
+
specification_version: 2
|
98
|
+
summary: Selenium RC with Rails integration and enhanced assertions.
|
99
|
+
test_files: []
|
91
100
|
|
@@ -1,61 +0,0 @@
|
|
1
|
-
module Polonium
|
2
|
-
module TestUnitDsl
|
3
|
-
include SeleniumDsl
|
4
|
-
class << self
|
5
|
-
def page_assertion(name)
|
6
|
-
module_eval(
|
7
|
-
"def assert_#{name}(value, params={})\n" +
|
8
|
-
" page.assert_#{name}(value, params)\n" +
|
9
|
-
"end",
|
10
|
-
__FILE__,
|
11
|
-
__LINE__ - 4
|
12
|
-
)
|
13
|
-
end
|
14
|
-
|
15
|
-
def element_assertion(name)
|
16
|
-
module_eval(
|
17
|
-
"def assert_#{name}(locator, *args)\n" +
|
18
|
-
" element(locator).assert_#{name}(*args)\n" +
|
19
|
-
"end",
|
20
|
-
__FILE__,
|
21
|
-
__LINE__ - 4
|
22
|
-
)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
page_assertion :title
|
27
|
-
page_assertion :text_present
|
28
|
-
page_assertion :text_not_present
|
29
|
-
page_assertion :location_ends_with
|
30
|
-
deprecate :assert_location_ends_in, :assert_location_ends_with
|
31
|
-
|
32
|
-
element_assertion :value
|
33
|
-
element_assertion :selected
|
34
|
-
element_assertion :checked
|
35
|
-
element_assertion :not_checked
|
36
|
-
element_assertion :text
|
37
|
-
element_assertion :element_present
|
38
|
-
element_assertion :element_not_present
|
39
|
-
element_assertion :next_sibling
|
40
|
-
element_assertion :contains_in_order
|
41
|
-
element_assertion :visible
|
42
|
-
element_assertion :not_visible
|
43
|
-
|
44
|
-
def assert_attribute(element_locator, attribute_name, expected_value)
|
45
|
-
element(element_locator).assert_attribute(attribute_name, expected_value)
|
46
|
-
end
|
47
|
-
|
48
|
-
# Assert and wait for locator element to contain text.
|
49
|
-
def assert_element_contains(locator, text, options = {})
|
50
|
-
element(locator).assert_contains(text, options)
|
51
|
-
end
|
52
|
-
|
53
|
-
# Assert and wait for locator element to not contain text.
|
54
|
-
def assert_element_does_not_contain(locator, text, options={})
|
55
|
-
element(locator).assert_does_not_contain(text, options)
|
56
|
-
end
|
57
|
-
deprecate :assert_element_does_not_contain_text, :assert_element_does_not_contain
|
58
|
-
deprecate :wait_for_element_to_not_contain_text, :assert_element_does_not_contain
|
59
|
-
deprecate :wait_for_text_in_order, :assert_contains_in_order
|
60
|
-
end
|
61
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
module Polonium
|
2
|
-
class MongrelSeleniumServerRunner < ServerRunner
|
3
|
-
def start
|
4
|
-
mongrel_configurator = configuration.create_mongrel_configurator
|
5
|
-
initialize_server(mongrel_configurator)
|
6
|
-
|
7
|
-
@thread_class.start do
|
8
|
-
start_server(mongrel_configurator)
|
9
|
-
end
|
10
|
-
@started = true
|
11
|
-
end
|
12
|
-
|
13
|
-
protected
|
14
|
-
def start_server(mongrel_configurator)
|
15
|
-
mongrel_configurator.run
|
16
|
-
mongrel_configurator.log "Mongrel running at #{configuration.internal_app_server_host}:#{configuration.internal_app_server_port}"
|
17
|
-
mongrel_configurator.join
|
18
|
-
end
|
19
|
-
|
20
|
-
def initialize_server(config)
|
21
|
-
configuration = self.configuration
|
22
|
-
config.listener do |*args|
|
23
|
-
mongrel = (args.first || self)
|
24
|
-
mongrel.log "Starting Rails in environment #{defaults[:environment]} ..."
|
25
|
-
mongrel.uri "/", :handler => mongrel.rails
|
26
|
-
mongrel.log "Rails loaded."
|
27
|
-
|
28
|
-
mongrel.log "Loading any Rails specific GemPlugins"
|
29
|
-
mongrel.load_plugins
|
30
|
-
configuration.app_server_initialization.call(mongrel)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def stop_server
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
module Polonium
|
2
|
-
class ServerRunner
|
3
|
-
attr_accessor :configuration, :thread_class
|
4
|
-
def initialize
|
5
|
-
@started = false
|
6
|
-
end
|
7
|
-
|
8
|
-
def start
|
9
|
-
@thread_class.start do
|
10
|
-
start_server
|
11
|
-
end
|
12
|
-
@started = true
|
13
|
-
end
|
14
|
-
|
15
|
-
def stop
|
16
|
-
stop_server
|
17
|
-
@started = false
|
18
|
-
end
|
19
|
-
|
20
|
-
def started?
|
21
|
-
@started
|
22
|
-
end
|
23
|
-
|
24
|
-
protected
|
25
|
-
def start_server
|
26
|
-
raise NotImplementedError.new("this is abstract!")
|
27
|
-
end
|
28
|
-
|
29
|
-
def stop_server
|
30
|
-
raise NotImplementedError.new("this is abstract!")
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
module Polonium
|
2
|
-
class WebrickSeleniumServerRunner < ServerRunner
|
3
|
-
attr_accessor :socket, :dispatch_servlet, :environment_path, :server
|
4
|
-
|
5
|
-
protected
|
6
|
-
def start_server
|
7
|
-
socket.do_not_reverse_lookup = true # patch for OS X
|
8
|
-
|
9
|
-
@server = configuration.create_webrick_server
|
10
|
-
mount_parameters = {
|
11
|
-
:port => configuration.internal_app_server_port,
|
12
|
-
:ip => configuration.internal_app_server_host,
|
13
|
-
:environment => configuration.rails_env.dup,
|
14
|
-
:server_root => configuration.server_root,
|
15
|
-
:server_type => WEBrick::SimpleServer,
|
16
|
-
:charset => "UTF-8",
|
17
|
-
:mime_types => WEBrick::HTTPUtils::DefaultMimeTypes,
|
18
|
-
:working_directory => File.expand_path(configuration.rails_root.to_s)
|
19
|
-
}
|
20
|
-
server.mount('/', dispatch_servlet, mount_parameters)
|
21
|
-
|
22
|
-
trap("INT") { stop_server }
|
23
|
-
|
24
|
-
require @environment_path
|
25
|
-
require "dispatcher"
|
26
|
-
server.start
|
27
|
-
end
|
28
|
-
|
29
|
-
def stop_server
|
30
|
-
server.shutdown
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
2
|
-
|
3
|
-
module Polonium
|
4
|
-
describe MongrelSeleniumServerRunner, "#start_server" do
|
5
|
-
attr_reader :configuration
|
6
|
-
before do
|
7
|
-
@configuration = Configuration.new
|
8
|
-
end
|
9
|
-
|
10
|
-
it "initializes server and runs app_server_initialization callback" do
|
11
|
-
mongrel_configurator = configuration.create_mongrel_configurator
|
12
|
-
stub(configuration).create_mongrel_configurator {mongrel_configurator}
|
13
|
-
mock(mongrel_configurator).run
|
14
|
-
stub(mongrel_configurator).log
|
15
|
-
mock(mongrel_configurator).join
|
16
|
-
fake_rails = "fake rails"
|
17
|
-
mock(mongrel_configurator).rails {fake_rails}
|
18
|
-
mock(mongrel_configurator).uri("/", {:handler => fake_rails})
|
19
|
-
mock(mongrel_configurator).load_plugins
|
20
|
-
mock(mongrel_configurator).listener.yields(mongrel_configurator)
|
21
|
-
|
22
|
-
callback_mongrel = nil
|
23
|
-
configuration.app_server_initialization = proc do |mongrel|
|
24
|
-
callback_mongrel = mongrel
|
25
|
-
end
|
26
|
-
runner = configuration.create_mongrel_runner
|
27
|
-
stub(runner).defaults do; {:environment => ""}; end
|
28
|
-
runner.thread_class = mock_thread_class = "mock_thread_class"
|
29
|
-
mock(mock_thread_class).start.yields
|
30
|
-
|
31
|
-
runner.start
|
32
|
-
callback_mongrel.should == mongrel_configurator
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
2
|
-
|
3
|
-
module Polonium
|
4
|
-
describe ServerRunner do
|
5
|
-
before(:each) do
|
6
|
-
@runner = Polonium::ServerRunner.new
|
7
|
-
class << @runner
|
8
|
-
public :start_server, :stop_server
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should initialize started? to be false" do
|
13
|
-
@runner.started?.should == false
|
14
|
-
end
|
15
|
-
|
16
|
-
it "start method should start new thread and set started" do
|
17
|
-
start_server_called = false
|
18
|
-
(class << @runner; self; end).class_eval do
|
19
|
-
define_method :start_server do; start_server_called = true; end
|
20
|
-
end
|
21
|
-
def @runner.stop_server; end
|
22
|
-
mock_thread_class = "mock_thread_class"
|
23
|
-
mock(mock_thread_class).start {|block| block.call}
|
24
|
-
@runner.thread_class = mock_thread_class
|
25
|
-
|
26
|
-
@runner.start
|
27
|
-
start_server_called.should equal(true)
|
28
|
-
@runner.started?.should equal(true)
|
29
|
-
end
|
30
|
-
|
31
|
-
it "stop method should set started? to false" do
|
32
|
-
def @runner.stop_server; end
|
33
|
-
@runner.instance_eval {@started = true}
|
34
|
-
@runner.stop
|
35
|
-
@runner.started?.should == false
|
36
|
-
end
|
37
|
-
|
38
|
-
it "start_server method should raise a NotImplementedError by default" do
|
39
|
-
proc {@runner.start_server}.should raise_error(NotImplementedError)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
@@ -1,117 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
2
|
-
|
3
|
-
module Polonium
|
4
|
-
describe WebrickSeleniumServerRunner do
|
5
|
-
attr_reader :configuration
|
6
|
-
before(:each) do
|
7
|
-
Object.const_set(:RAILS_ROOT, "foobar")
|
8
|
-
end
|
9
|
-
|
10
|
-
after(:each) do
|
11
|
-
Object.instance_eval {remove_const :RAILS_ROOT}
|
12
|
-
end
|
13
|
-
|
14
|
-
it "start method should set socket.do_not_reverse_lookup to true and" do
|
15
|
-
runner = create_runner_that_is_stubbed_so_start_method_works
|
16
|
-
runner.start
|
17
|
-
end
|
18
|
-
|
19
|
-
it "start method should initialize the HttpServer with parameters" do
|
20
|
-
runner = create_runner_that_is_stubbed_so_start_method_works
|
21
|
-
runner.start
|
22
|
-
end
|
23
|
-
|
24
|
-
it "start method should mount and start the server" do
|
25
|
-
runner = create_runner_that_is_stubbed_so_start_method_works
|
26
|
-
runner.start
|
27
|
-
end
|
28
|
-
|
29
|
-
it "start method should require the environment and dispatcher" do
|
30
|
-
runner = create_runner_that_is_stubbed_so_start_method_works
|
31
|
-
|
32
|
-
mock(runner).require("foobar")
|
33
|
-
mock(runner).require("dispatcher")
|
34
|
-
|
35
|
-
runner.environment_path = "foobar"
|
36
|
-
runner.start
|
37
|
-
end
|
38
|
-
|
39
|
-
it "start method should require environment when rails_root is not set" do
|
40
|
-
runner = create_runner_that_is_stubbed_so_start_method_works
|
41
|
-
requires = []
|
42
|
-
stub(runner).require {|val| requires << val}
|
43
|
-
|
44
|
-
runner.start
|
45
|
-
requires.any? {|r| r =~ /\/config\/environment/}.should == true
|
46
|
-
end
|
47
|
-
|
48
|
-
it "start method should trap server.shutdown" do
|
49
|
-
runner = create_runner_that_is_stubbed_so_start_method_works
|
50
|
-
|
51
|
-
(class << runner; self; end).class_eval {attr_reader :trap_signal_name}
|
52
|
-
def runner.trap(signal_name, &block)
|
53
|
-
@trap_signal_name = signal_name
|
54
|
-
block.call
|
55
|
-
end
|
56
|
-
mock(@mock_server).shutdown.once
|
57
|
-
|
58
|
-
runner.start
|
59
|
-
runner.trap_signal_name.should == "INT"
|
60
|
-
end
|
61
|
-
|
62
|
-
it "should shutdown webrick server" do
|
63
|
-
runner = create_runner_that_is_stubbed_so_start_method_works
|
64
|
-
runner.start
|
65
|
-
mock(@mock_server).shutdown.once
|
66
|
-
runner.stop
|
67
|
-
end
|
68
|
-
|
69
|
-
def create_runner_that_is_stubbed_so_start_method_works()
|
70
|
-
configuration = Polonium::Configuration.new
|
71
|
-
runner = configuration.create_webrick_runner
|
72
|
-
class << runner; public :start_server; end
|
73
|
-
|
74
|
-
def runner.require(*args)
|
75
|
-
end
|
76
|
-
|
77
|
-
mock_socket = "mock_socket"
|
78
|
-
runner.socket = mock_socket
|
79
|
-
stub(mock_socket).do_not_reverse_lookup=(true)
|
80
|
-
|
81
|
-
@mock_server = mock_server = "mock_server"
|
82
|
-
(class << configuration; self; end).class_eval do
|
83
|
-
define_method :create_webrick_server do
|
84
|
-
mock_server
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
configuration.internal_app_server_port = 4000
|
89
|
-
configuration.internal_app_server_host = "localhost"
|
90
|
-
configuration.rails_env = "test"
|
91
|
-
stub(@mock_server).mount('/')
|
92
|
-
mock(@mock_server).mount(
|
93
|
-
'/',
|
94
|
-
DispatchServlet,
|
95
|
-
{
|
96
|
-
:port => configuration.internal_app_server_port,
|
97
|
-
:ip => configuration.internal_app_server_host,
|
98
|
-
:environment => configuration.rails_env,
|
99
|
-
:server_root => File.expand_path("#{configuration.rails_root}/public/"),
|
100
|
-
:server_type => WEBrick::SimpleServer,
|
101
|
-
:charset => "UTF-8",
|
102
|
-
:mime_types => WEBrick::HTTPUtils::DefaultMimeTypes,
|
103
|
-
:working_directory => File.expand_path(configuration.rails_root.to_s)
|
104
|
-
}
|
105
|
-
)
|
106
|
-
|
107
|
-
mock(@mock_server).start.once
|
108
|
-
|
109
|
-
mock_thread_class = "mock_thread_class"
|
110
|
-
runner.thread_class = mock_thread_class
|
111
|
-
mock(mock_thread_class).start {|block| block.call}
|
112
|
-
|
113
|
-
return runner
|
114
|
-
end
|
115
|
-
|
116
|
-
end
|
117
|
-
end
|