Class: TestServantConfig
- Inherits:
-
Test::Unit::TestCase
- Object
- Test::Unit::TestCase
- TestServantConfig
- Includes:
- Rack::Test::Methods
- Defined in:
- lib/belphanior/servant/test/tc_servant_config.rb
Constant Summary collapse
- SERVANT_CONFIG_FILE =
Dir.tmpdir << "/tc_servant_config_out.json"
Instance Method Summary collapse
- #app ⇒ Object
- #setup ⇒ Object
- #teardown ⇒ Object
- #test_config_initialize ⇒ Object
- #test_get_all_configs ⇒ Object
- #test_get_specific_config ⇒ Object
- #test_readonly_block ⇒ Object
- #test_write_config ⇒ Object
Instance Method Details
#app ⇒ Object
14 15 16 |
# File 'lib/belphanior/servant/test/tc_servant_config.rb', line 14 def app Sinatra::Application end |
#setup ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/belphanior/servant/test/tc_servant_config.rb', line 18 def setup app.set :servant_config_file, SERVANT_CONFIG_FILE app.set :servant_config_db, ServantConfigDb.new( <<EOF { "ip":"127.0.0.1", "port": "80" } EOF ) app.load_servant_config end |
#teardown ⇒ Object
31 32 33 34 35 |
# File 'lib/belphanior/servant/test/tc_servant_config.rb', line 31 def teardown if File.exist? SERVANT_CONFIG_FILE File.delete SERVANT_CONFIG_FILE end end |
#test_config_initialize ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/belphanior/servant/test/tc_servant_config.rb', line 37 def test_config_initialize validate = File.open(SERVANT_CONFIG_FILE, "r") content = JSON.parse(validate.read) validate.close assert_equal "127.0.0.1", content["ip"] assert_equal "80", content["port"] end |
#test_get_all_configs ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/belphanior/servant/test/tc_servant_config.rb', line 45 def test_get_all_configs get '/config' assert_equal 200, last_response.status result = JSON.parse(last_response.body) assert_equal("127.0.0.1", result["ip"]) assert_equal("80", result["port"]) end |
#test_get_specific_config ⇒ Object
53 54 55 56 57 |
# File 'lib/belphanior/servant/test/tc_servant_config.rb', line 53 def test_get_specific_config get '/config/port' assert_equal 200, last_response.status assert_equal "80", last_response.body end |
#test_readonly_block ⇒ Object
72 73 74 75 76 |
# File 'lib/belphanior/servant/test/tc_servant_config.rb', line 72 def test_readonly_block app.servant_config_db.set_readonly('port') post '/config/port', '81' assert_equal 500, last_response.status end |
#test_write_config ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/belphanior/servant/test/tc_servant_config.rb', line 59 def test_write_config post '/config/test', "hi" assert_equal 200, last_response.status get '/config/test' assert_equal 200, last_response.status assert_equal 'hi', last_response.body assert(File.exist? SERVANT_CONFIG_FILE) settings_file = File.open(app.servant_config_file, 'r') result = JSON.parse(settings_file.read) settings_file.close assert_equal 'hi', result["test"] end |