polonium 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,3 +1,6 @@
1
+ 0.2.1
2
+ * ExternalServerRunner start_server and stop_server commands are configurable
3
+
1
4
  0.2.0
2
5
  * Added ExternalServerRunner.
3
6
  * Removed mysql specific setup logic.
data/Rakefile CHANGED
@@ -26,7 +26,7 @@ def run_suite
26
26
  end
27
27
 
28
28
  PKG_NAME = "polonium"
29
- PKG_VERSION = "0.2.0"
29
+ PKG_VERSION = "0.2.1"
30
30
  PKG_FILES = FileList[
31
31
  '[A-Z]*',
32
32
  '*.rb',
@@ -1,10 +1,35 @@
1
1
  module Polonium
2
2
  module ServerRunners
3
3
  class ExternalServerRunner < ServerRunner
4
+ DEFAULT_START_SERVER_COMMAND = lambda do |configuration|
5
+ "cd #{configuration.rails_root}; script/server -e #{configuration.rails_env} -p #{configuration.internal_app_server_port} -c #{configuration.rails_root}"
6
+ end
7
+ DEFAULT_STOP_SERVER_COMMAND = lambda do |configuration|
8
+ "ps ax | grep 'script/server -e #{configuration.rails_env}' | sed /grep/d | awk '{print $1}' | xargs kill -9 2>/dev/null"
9
+ end
10
+
11
+ class << self
12
+ def start_server_command(&blk)
13
+ if blk
14
+ @start_server_command = blk
15
+ else
16
+ @start_server_command ||= DEFAULT_START_SERVER_COMMAND
17
+ end
18
+ end
19
+
20
+ def stop_server_command(&blk)
21
+ if blk
22
+ @stop_server_command = blk
23
+ else
24
+ @stop_server_command ||= DEFAULT_STOP_SERVER_COMMAND
25
+ end
26
+ end
27
+ end
28
+
4
29
  protected
5
30
  def start_server
6
31
  stop_server
7
- system("cd #{configuration.rails_root}; script/server -e #{configuration.rails_env} -p #{configuration.internal_app_server_port} -c #{configuration.rails_root}")
32
+ system(self.class.start_server_command.call(configuration))
8
33
  rescue Exception => e
9
34
  puts e.message
10
35
  puts e.backtrace
@@ -12,8 +37,7 @@ module Polonium
12
37
  end
13
38
 
14
39
  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)
40
+ system(self.class.stop_server_command.call(configuration))
17
41
  end
18
42
  end
19
43
  end
@@ -3,30 +3,71 @@ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
3
3
  module Polonium
4
4
  module ServerRunners
5
5
  describe ExternalServerRunner do
6
- attr_reader :configuration, :rails_env, :rails_root, :runner, :start_server_cmd, :stop_server_cmd
6
+ attr_reader :configuration, :rails_env, :rails_root, :runner, :start_server_command, :stop_server_command, :original_start_server_command, :original_stop_server_command
7
7
  before do
8
8
  @configuration = Configuration.new
9
9
  @rails_env = configuration.rails_env = 'test'
10
10
  @rails_root = configuration.rails_root = File.dirname(__FILE__)
11
- @start_server_cmd = "cd #{rails_root}; script/server -e #{rails_env} -p #{configuration.internal_app_server_port} -c #{rails_root}"
12
- @stop_server_cmd = "ps ax | grep 'script/server -e #{rails_env}' | sed /grep/d | awk '{print $1}' | xargs kill -9 2>/dev/null"
11
+
12
+ @start_server_command = "cd #{rails_root}; script/server -e #{rails_env} -p #{configuration.internal_app_server_port} -c #{rails_root}"
13
+ @stop_server_command = "ps ax | grep 'script/server -e #{rails_env}' | sed /grep/d | awk '{print $1}' | xargs kill -9 2>/dev/null"
13
14
 
14
15
  @runner = ExternalServerRunner.new(configuration)
15
16
  end
16
17
 
18
+ after do
19
+ ExternalServerRunner.start_server_command(&ExternalServerRunner::DEFAULT_START_SERVER_COMMAND)
20
+ ExternalServerRunner.stop_server_command(&ExternalServerRunner::DEFAULT_STOP_SERVER_COMMAND)
21
+ end
22
+
17
23
  describe "#start" do
18
24
  it "stops the server, then starts an external rails server" do
19
- mock(runner).system(stop_server_cmd).ordered
20
- mock(runner).system(start_server_cmd).ordered
25
+ mock(runner).system(stop_server_command).ordered
26
+ mock(runner).system(start_server_command).ordered
21
27
  runner.start
22
28
  end
29
+
30
+ context "with a custom start_server_command" do
31
+ it "stops the server, then starts an external rails server with the custom command" do
32
+ ExternalServerRunner.start_server_command do
33
+ "custom start server command"
34
+ end
35
+
36
+ mock(runner).system(stop_server_command).ordered
37
+ mock(runner).system("custom start server command").ordered
38
+ runner.start
39
+ end
40
+ end
41
+
42
+ context "with a custom stop_server_command" do
43
+ it "stops the server with the custom command, then starts an external rails server" do
44
+ ExternalServerRunner.stop_server_command do
45
+ "custom stop server command"
46
+ end
47
+
48
+ mock(runner).system("custom stop server command").ordered
49
+ mock(runner).system(start_server_command).ordered
50
+ runner.start
51
+ end
52
+ end
23
53
  end
24
54
 
25
55
  describe "#stop" do
26
56
  it "stops the server" do
27
- mock(runner).system(stop_server_cmd).ordered
57
+ mock(runner).system(stop_server_command)
28
58
  runner.stop
29
59
  end
60
+
61
+ context "with a custom stop_server_command" do
62
+ it "stops the server with the custom command" do
63
+ ExternalServerRunner.stop_server_command do
64
+ "custom stop server command"
65
+ end
66
+
67
+ mock(runner).system("custom stop server command")
68
+ runner.stop
69
+ end
70
+ end
30
71
  end
31
72
  end
32
73
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: polonium
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pivotal Labs