polonium 0.1.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.
Files changed (34) hide show
  1. data/CHANGES +10 -0
  2. data/README +38 -0
  3. data/Rakefile +68 -0
  4. data/lib/polonium.rb +28 -0
  5. data/lib/polonium/configuration.rb +271 -0
  6. data/lib/polonium/driver.rb +155 -0
  7. data/lib/polonium/dsl/selenium_dsl.rb +33 -0
  8. data/lib/polonium/dsl/test_unit_dsl.rb +58 -0
  9. data/lib/polonium/element.rb +207 -0
  10. data/lib/polonium/extensions/module.rb +8 -0
  11. data/lib/polonium/extensions/testrunnermediator.rb +22 -0
  12. data/lib/polonium/mongrel_selenium_server_runner.rb +37 -0
  13. data/lib/polonium/page.rb +84 -0
  14. data/lib/polonium/selenium_helper.rb +5 -0
  15. data/lib/polonium/server_runner.rb +33 -0
  16. data/lib/polonium/tasks/selenium_test_task.rb +21 -0
  17. data/lib/polonium/test_case.rb +93 -0
  18. data/lib/polonium/wait_for.rb +40 -0
  19. data/lib/polonium/webrick_selenium_server_runner.rb +33 -0
  20. data/spec/polonium/extensions/module_spec.rb +29 -0
  21. data/spec/polonium/extensions/testrunnermediator_spec.rb +19 -0
  22. data/spec/polonium/mongrel_selenium_server_runner_spec.rb +35 -0
  23. data/spec/polonium/selenium_configuration_spec.rb +359 -0
  24. data/spec/polonium/selenium_driver_spec.rb +104 -0
  25. data/spec/polonium/selenium_element_spec.rb +551 -0
  26. data/spec/polonium/selenium_page_spec.rb +249 -0
  27. data/spec/polonium/selenium_server_runner_spec.rb +42 -0
  28. data/spec/polonium/selenium_test_case_class_method_spec.rb +41 -0
  29. data/spec/polonium/selenium_test_case_spec.rb +870 -0
  30. data/spec/polonium/selenium_test_case_spec_helper.rb +16 -0
  31. data/spec/polonium/webrick_selenium_server_runner_spec.rb +117 -0
  32. data/spec/spec_helper.rb +63 -0
  33. data/spec/spec_suite.rb +6 -0
  34. metadata +82 -0
@@ -0,0 +1,5 @@
1
+ # Expand the path to environment so that Ruby does not load it multiple times
2
+ # File.expand_path can be removed if Ruby 1.9 is in use.
3
+ if (Object.const_defined?(:ActiveRecord) && !ActiveRecord::Base.allow_concurrency)
4
+ raise "Since Selenium spawns an internal app server, we need ActiveRecord to be multi-threaded. Please set 'ActiveRecord::Base.allow_concurrency = true' in your environment file (e.g. test.rb)."
5
+ end
@@ -0,0 +1,33 @@
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
@@ -0,0 +1,21 @@
1
+
2
+ module Polonium
3
+ module Tasks
4
+ class PoloniumTestTask
5
+ attr_reader :rails_env, :rails_root
6
+
7
+ def initialize(rails_env = RAILS_ENV, rails_root = RAILS_ROOT)
8
+ @rails_env = rails_env
9
+ @rails_root = rails_root
10
+ end
11
+
12
+ def invoke(suite_relative_path = "test/selenium/selenium_suite")
13
+ rails_env.replace "test"
14
+ require "#{rails_root}/" + suite_relative_path
15
+
16
+ passed = Test::Unit::AutoRunner.run
17
+ raise "Test failures" unless passed
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,93 @@
1
+ module Polonium
2
+ # The Test Case class that runs your Selenium tests.
3
+ # You are able to use all methods provided by Selenium::SeleneseInterpreter with some additions.
4
+ class TestCase < Test::Unit::TestCase
5
+ module ClassMethods
6
+ def subclasses
7
+ @subclasses ||= []
8
+ end
9
+
10
+ def inherited(subclass)
11
+ # keep a list of all subclasses on the fly, so we can run them all later from the Runner
12
+ subclasses << subclass unless subclasses.include?(subclass)
13
+ super
14
+ end
15
+
16
+ def all_subclasses_as_suite(configuration)
17
+ suite = Test::Unit::TestSuite.new
18
+ all_descendant_classes.each do |test_case_class|
19
+ test_case_class.suite.tests.each do |test_case|
20
+ test_case.configuration = configuration
21
+ suite << test_case
22
+ end
23
+ end
24
+ suite
25
+ end
26
+
27
+ def all_descendant_classes
28
+ extract_subclasses(self)
29
+ end
30
+
31
+ def extract_subclasses(parent_class)
32
+ classes = []
33
+ parent_class.subclasses.each do |subclass|
34
+ classes << subclass
35
+ classes.push(*extract_subclasses(subclass))
36
+ end
37
+ classes
38
+ end
39
+
40
+ unless Object.const_defined?(:RAILS_ROOT)
41
+ attr_accessor :use_transactional_fixtures, :use_instantiated_fixtures
42
+ end
43
+ end
44
+ extend ClassMethods
45
+
46
+ self.use_transactional_fixtures = false
47
+ self.use_instantiated_fixtures = true
48
+
49
+ include TestUnitDsl
50
+ def setup
51
+ # set "setup_once" to true
52
+ # to prevent fixtures from being re-loaded and data deleted from the DB.
53
+ # this is handy if you want to generate a DB full of sample data
54
+ # from the tests. Make sure none of your selenium tests manually
55
+ # reset data!
56
+ #TODO: make this configurable
57
+ setup_once = false
58
+
59
+ 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
60
+ unless setup_once
61
+ ActiveRecord::Base.connection.update('SET FOREIGN_KEY_CHECKS = 0')
62
+ super
63
+ ActiveRecord::Base.connection.update('SET FOREIGN_KEY_CHECKS = 1')
64
+ else
65
+ unless InstanceMethods.const_defined?("ALREADY_SETUP_ONCE")
66
+ super
67
+ InstanceMethods.const_set("ALREADY_SETUP_ONCE", true)
68
+ end
69
+ end
70
+ @selenium_driver = configuration.driver
71
+ end
72
+
73
+ def teardown
74
+ selenium_driver.stop if should_stop_driver?
75
+ super
76
+ if @beginning
77
+ duration = (time_class.now - @beginning).to_f
78
+ puts "#{duration} seconds"
79
+ end
80
+ end
81
+
82
+ def selenium_test_case
83
+ @selenium_test_case ||= TestCase
84
+ end
85
+
86
+ def run(result, &block)
87
+ return if @method_name.nil? || @method_name.to_sym == :default_test
88
+ super
89
+ end
90
+ end
91
+ end
92
+
93
+ TestCase = Polonium::TestCase
@@ -0,0 +1,40 @@
1
+ module Polonium
2
+ module WaitFor
3
+ Context = Struct.new(:message)
4
+ # Poll continuously for the return value of the block to be true. You can use this to assert that a client side
5
+ # or server side condition was met.
6
+ # wait_for do
7
+ # User.count == 5
8
+ # end
9
+ def wait_for(params={})
10
+ timeout = params[:timeout] || default_wait_for_time
11
+ message = params[:message] || "Timeout exceeded"
12
+ configuration = Context.new(message)
13
+ begin_time = time_class.now
14
+ while (time_class.now - begin_time) < timeout
15
+ return if yield(configuration)
16
+ sleep 0.25
17
+ end
18
+ flunk(configuration.message + " (after #{timeout} sec)")
19
+ true
20
+ end
21
+
22
+ def default_wait_for_time
23
+ 5
24
+ end
25
+
26
+ def time_class
27
+ Time
28
+ end
29
+
30
+ # The default Selenium Core client side timeout.
31
+ def default_timeout
32
+ @default_timeout ||= 20000
33
+ end
34
+ attr_writer :default_timeout
35
+
36
+ def flunk(message)
37
+ raise Test::Unit::AssertionFailedError, message
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,33 @@
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
@@ -0,0 +1,29 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
2
+
3
+ describe Module do
4
+ describe "#deprecate" do
5
+ it "creates a method that calls another method with a deprecation warning" do
6
+ klass = Class.new do
7
+ def car
8
+ :beep
9
+ end
10
+ deprecate :horse, :car
11
+ end
12
+ obj = klass.new
13
+ mock(obj).warn("horse is deprecated. Use car instead.")
14
+ obj.horse.should == :beep
15
+ end
16
+
17
+ it "proxies arguments to the new method" do
18
+ klass = Class.new do
19
+ def car(name, location='here')
20
+ "You have a #{name} located at #{location}"
21
+ end
22
+ deprecate :horse, :car
23
+ end
24
+ obj = klass.new
25
+ mock(obj).warn("horse is deprecated. Use car instead.")
26
+ obj.horse('mustang').should == "You have a mustang located at here"
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,19 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
2
+
3
+ describe Test::Unit::UI::TestRunnerMediator do
4
+ attr_reader :driver
5
+ before do
6
+ @driver = Polonium::Configuration.instance
7
+ end
8
+
9
+ it "start the server runner before suite and stops it after the suite" do
10
+ suite = Test::Unit::TestSuite.new
11
+ mediator = Test::Unit::UI::TestRunnerMediator.new(suite)
12
+
13
+ runner = driver.create_server_runner
14
+ mock(driver).create_server_runner {runner}
15
+ mock(runner).stop
16
+ mock(driver).stop_driver_if_necessary(true)
17
+ mediator.run_suite
18
+ end
19
+ end
@@ -0,0 +1,35 @@
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
@@ -0,0 +1,359 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
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
+ describe Configuration do
23
+ attr_reader :configuration
24
+ before(:each) do
25
+ @configuration = Configuration.new
26
+ @old_rails_root = RAILS_ROOT if Object.const_defined? :RAILS_ROOT
27
+ silence_warnings { Object.const_set :RAILS_ROOT, "foobar" }
28
+ require 'webrick_server'
29
+ end
30
+
31
+ after(:each) do
32
+ if @old_rails_root
33
+ silence_warnings { Object.const_set :RAILS_ROOT, @old_rails_root }
34
+ else
35
+ Object.instance_eval {remove_const :RAILS_ROOT}
36
+ end
37
+ end
38
+
39
+ it "registers and notifies after_driver_started callbacks" do
40
+ proc1_args = nil
41
+ proc1 = lambda {|*args| proc1_args = args}
42
+ proc2_args = nil
43
+ proc2 = lambda {|*args| proc2_args = args}
44
+
45
+ configuration.after_driver_started(&proc1)
46
+ configuration.after_driver_started(&proc2)
47
+
48
+ expected_driver = Object.new
49
+ configuration.notify_after_driver_started(expected_driver)
50
+ proc1_args.should == [expected_driver]
51
+ proc2_args.should == [expected_driver]
52
+ end
53
+
54
+ it "defaults to true for verify_remote_app_server_is_running" do
55
+ configuration.verify_remote_app_server_is_running.should == true
56
+ end
57
+
58
+ it "defaults app_server_initialization to a Proc" do
59
+ configuration.app_server_initialization.should be_instance_of(Proc)
60
+ end
61
+
62
+ it "creates a Selenese driver and notify listeners" do
63
+ configuration.selenium_server_host = "selenium_server_host.com"
64
+ configuration.selenium_server_port = 80
65
+ configuration.browser = "iexplore"
66
+ configuration.external_app_server_host = "browser_host.com"
67
+ configuration.external_app_server_port = 80
68
+
69
+ driver = configuration.create_driver
70
+ driver.server_host.should == "selenium_server_host.com"
71
+ driver.server_port.should == 80
72
+ driver.browser_start_command.should == "*iexplore"
73
+ driver.browser_url.should == "http://browser_host.com:80"
74
+ end
75
+
76
+ it "creates, initializes. and notifies listeners for a Selenese driver " do
77
+ passed_driver = nil
78
+ configuration.after_driver_started {|driver| passed_driver = driver}
79
+
80
+ stub_driver = Object.new
81
+ start_called = false
82
+ stub(stub_driver).start.returns {start_called = true}
83
+ stub(configuration).create_driver.returns {stub_driver}
84
+ driver = configuration.create_and_initialize_driver
85
+ driver.should == stub_driver
86
+ passed_driver.should == driver
87
+ start_called.should == true
88
+ end
89
+
90
+ it "creates a Webrick Server Runner" do
91
+ configuration.selenium_server_port = 4000
92
+ configuration.selenium_server_host = "localhost"
93
+ dir = File.dirname(__FILE__)
94
+ configuration.rails_root = dir
95
+ configuration.rails_env = "test"
96
+
97
+ runner = configuration.create_webrick_runner
98
+ runner.should be_an_instance_of(WebrickSeleniumServerRunner)
99
+ runner.configuration.should == configuration
100
+ runner.thread_class.should == Thread
101
+ runner.socket.should == Socket
102
+ runner.dispatch_servlet.should == DispatchServlet
103
+ runner.environment_path.should == File.expand_path("#{dir}/config/environment")
104
+ end
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
149
+ end
150
+ end
151
+
152
+ describe Configuration, "#establish_environment" do
153
+ attr_reader :configuration
154
+ before(:each) do
155
+ @old_configuration = Configuration.instance
156
+ Configuration.instance = nil
157
+ @configuration = Configuration.instance
158
+ configuration = @configuration
159
+ end
160
+
161
+ after(:each) do
162
+ Configuration.instance = @old_configuration
163
+ end
164
+
165
+ it "establish_environment__webrick_host" do
166
+ should_establish_environment('internal_app_server_host', '192.168.10.1', :internal_app_server_host )
167
+ end
168
+
169
+ it "initializes webrick_port" do
170
+ should_establish_environment('internal_app_server_port', 1337, :internal_app_server_port )
171
+ end
172
+
173
+ it "initializes internal_app_server_port" do
174
+ should_establish_environment('external_app_server_port', 1337, :external_app_server_port )
175
+ end
176
+
177
+ it "initializes internal_app_server_host" do
178
+ should_establish_environment('external_app_server_host', 'sammich.com', :external_app_server_host)
179
+ end
180
+
181
+ it "initializes selenium_server_host" do
182
+ should_establish_environment('selenium_server_host', 'sammich.com')
183
+ end
184
+
185
+ it "initializes selenium_server_host" do
186
+ should_establish_environment('selenium_server_port', 1337)
187
+ end
188
+
189
+ it "initializes app_server_engine" do
190
+ should_establish_environment('app_server_engine', :webrick, :app_server_engine)
191
+ end
192
+
193
+ it "initializes browser" do
194
+ configuration.env = stub_env
195
+ stub_env['browser'] = 'konqueror'
196
+ Configuration.__send__(:establish_environment)
197
+ configuration.browser.should == 'konqueror'
198
+ end
199
+
200
+ it "initializes keep_browser_open_on_failure" do
201
+ configuration.env = stub_env
202
+ env_var = 'keep_browser_open_on_failure'
203
+ stub_env[env_var] = 'false'
204
+ Configuration.send :establish_environment
205
+ configuration.send(env_var).should == false
206
+ configuration.send(env_var).should == false
207
+
208
+ stub_env[env_var] = 'true'
209
+ Configuration.send :establish_environment
210
+ configuration.send(env_var).should == true
211
+ configuration.send(env_var).should == true
212
+
213
+ stub_env[env_var] = 'blah'
214
+ Configuration.send :establish_environment
215
+ configuration.send(env_var).should == true
216
+ configuration.send(env_var).should == true
217
+ end
218
+
219
+ it "initializes verify_remote_app_server_is_running" do
220
+ configuration.env = stub_env
221
+ env_var = 'verify_remote_app_server_is_running'
222
+ stub_env[env_var] = 'false'
223
+ Configuration.send :establish_environment
224
+ configuration.send(env_var).should == false
225
+ configuration.send(env_var).should == false
226
+
227
+ stub_env[env_var] = 'true'
228
+ Configuration.send :establish_environment
229
+ configuration.send(env_var).should == true
230
+ configuration.send(env_var).should == true
231
+
232
+ stub_env[env_var] = 'blah'
233
+ Configuration.send :establish_environment
234
+ configuration.send(env_var).should == true
235
+ configuration.send(env_var).should == true
236
+ end
237
+
238
+ it "internal_app_server_host" do
239
+ should_lazily_load configuration, :internal_app_server_host, "0.0.0.0"
240
+ end
241
+
242
+ it "internal_app_server_port" do
243
+ should_lazily_load configuration, :internal_app_server_port, 4000
244
+ end
245
+
246
+ it "external_app_server_host" do
247
+ should_lazily_load configuration, :external_app_server_host, "localhost"
248
+ end
249
+
250
+ it "external_app_server_port" do
251
+ should_lazily_load configuration, :external_app_server_port, 4000
252
+ end
253
+
254
+ it "browsers__lazy_loaded" do
255
+ should_lazily_load configuration, :browser, Configuration::FIREFOX
256
+ end
257
+
258
+ it "keep_browser_open_on_failure" do
259
+ should_lazily_load configuration, :keep_browser_open_on_failure, false
260
+ end
261
+
262
+ it "formatted_browser" do
263
+ configuration.browser = Configuration::IEXPLORE
264
+ configuration.formatted_browser.should == "*iexplore"
265
+ end
266
+
267
+ it "browser_url" do
268
+ configuration.external_app_server_host = "test.com"
269
+ configuration.external_app_server_port = 101
270
+ configuration.browser_url.should == "http://test.com:101"
271
+ end
272
+
273
+ it "driver__when_in_test_browser_mode__should_be_nil" do
274
+ configuration.test_browser_mode
275
+ configuration.driver.should be_nil
276
+ end
277
+
278
+ protected
279
+ def should_establish_environment(env_var, expected_value, method_name=nil )
280
+ method_name = env_var unless method_name
281
+ configuration.env = stub_env
282
+ stub_env[env_var] = expected_value
283
+ Configuration.send :establish_environment
284
+ Configuration.instance.send(method_name).should == expected_value
285
+ end
286
+
287
+ def stub_env
288
+ @stub_env ||= {}
289
+ end
290
+
291
+ def should_lazily_load(object, method_name, default_value)
292
+ object.send(method_name).should == default_value
293
+ test_object = Object.new
294
+ object.send("#{method_name}=", test_object)
295
+ object.send(method_name).should == test_object
296
+ end
297
+ end
298
+
299
+ describe Configuration, "#stop_driver_if_necessary" do
300
+ attr_reader :configuration
301
+ before(:each) do
302
+ @configuration = Configuration.new
303
+ end
304
+
305
+ it "when suite passes, should stop driver" do
306
+ driver = ::Polonium::Driver.new('http://test.host', 4000, "*firefox", 'http://test.host')
307
+ mock(driver).stop.once
308
+ configuration.driver = driver
309
+
310
+ configuration.stop_driver_if_necessary true
311
+ end
312
+
313
+ it "when suite fails and keep browser open on failure, should not stop driver" do
314
+ driver = ::Polonium::Driver.new('http://test.host', 4000, "*firefox", 'http://test.host')
315
+ mock(driver).stop.never
316
+ configuration.driver = driver
317
+ configuration.keep_browser_open_on_failure = true
318
+
319
+ configuration.stop_driver_if_necessary false
320
+ end
321
+
322
+ it "when suite fails and not keep browser open on failure, should stop driver" do
323
+ driver = ::Polonium::Driver.new('http://test.host', 4000, "*firefox", 'http://test.host')
324
+ mock(driver).stop
325
+ configuration.driver = driver
326
+ configuration.keep_browser_open_on_failure = false
327
+
328
+ configuration.stop_driver_if_necessary false
329
+ end
330
+
331
+ end
332
+
333
+ describe Configuration, "#create_server_runner where application server engine is mongrel" do
334
+ it "creates a mongrel server runner" do
335
+ configuration = Configuration.new
336
+ configuration.app_server_engine = :mongrel
337
+ runner = configuration.create_server_runner
338
+ runner.should be_instance_of(MongrelSeleniumServerRunner)
339
+ end
340
+ end
341
+
342
+ describe Configuration, "#create_server_runner where application server engine is webrick" do
343
+ before do
344
+ Object.const_set :RAILS_ROOT, "foobar"
345
+ require 'webrick_server'
346
+ end
347
+
348
+ after do
349
+ Object.instance_eval {remove_const :RAILS_ROOT}
350
+ end
351
+
352
+ it "creates a webrick server runner" do
353
+ configuration = Configuration.new
354
+ configuration.app_server_engine = :webrick
355
+ runner = configuration.create_server_runner
356
+ runner.should be_instance_of(WebrickSeleniumServerRunner)
357
+ end
358
+ end
359
+ end