Browse code

Accept config file as argument

Cinan Rakosnik authored on 16/12/2012 at 14:09:40
Showing 2 changed files
... ...
@@ -21,6 +21,15 @@ module Rubysermon
21 21
 			@running_mods	= []
22 22
 			@enabled_mods	= []
23 23
 			@db				= nil
24
+
25
+			if not ARGV.empty?
26
+				config_path = ARGV.first
27
+				if File.exists?(config_path)
28
+					@config[:config_path] = config_path
29
+				else
30
+					abort("Wrong config file path. Exiting.")
31
+				end
32
+			end
24 33
 		end
25 34
 
26 35
 		def run
... ...
@@ -2,40 +2,52 @@ require_relative 'test_helper.rb'
2 2
 
3 3
 class Rubysermon_test < MiniTest::Unit::TestCase
4 4
 
5
-	def setup
6
-		skip("Need read configuration path")
7
-		#@app = Rubysermon::App.new
5
+	def teardown
6
+		ARGV.clear
8 7
 	end
9 8
 
10 9
 	def test_wrong_refresh_time
11
-		@app.config_path = "#{TEST_PATH}/fixtures/short_repeat_period.json"
10
+		ARGV[0] = "#{TEST_PATH}/fixtures/short_repeat_period.json"
11
+		app = Rubysermon::App.new
12 12
 
13 13
 		assert_raises(SystemExit) do
14
-			@app.run()
14
+			app.run()
15 15
 		end
16 16
 	end
17 17
 
18 18
 	def test_empty_modules
19
-		@app.config_path = "#{TEST_PATH}/fixtures/empty_modules.json"
19
+		ARGV[0] = "#{TEST_PATH}/fixtures/empty_modules.json"
20
+		app = Rubysermon::App.new
20 21
 
21 22
 		assert_raises(SystemExit) do
22
-			@app.run()
23
+			app.run()
23 24
 		end
24 25
 	end
25 26
 
26 27
 	def test_empty_config1
27
-		@app.config_path = "#{TEST_PATH}/fixtures/empty1.json"
28
+		ARGV[0] = "#{TEST_PATH}/fixtures/empty1.json"
29
+		app = Rubysermon::App.new
28 30
 
29 31
 		assert_raises(SystemExit) do
30
-			@app.run()
32
+			app.run()
31 33
 		end
32 34
 	end
33 35
 
34 36
 	def test_empty_config2
35
-		@app.config_path = "#{TEST_PATH}/fixtures/empty2.json"
37
+		ARGV[0] = "#{TEST_PATH}/fixtures/empty2.json"
38
+		app = Rubysermon::App.new
36 39
 
37 40
 		assert_raises(SystemExit) do
38
-			@app.run()
41
+			app.run()
39 42
 		end
40 43
 	end
44
+
45
+	def test_wrong_config_path
46
+		ARGV[0] = "/wrong_path"
47
+		exception = assert_raises(SystemExit) do
48
+			Rubysermon::App.new
49
+		end
50
+
51
+		assert_equal("Wrong config file path. Exiting.", exception.message)
52
+	end
41 53
 end
42 54
\ No newline at end of file