aef-init 1.0.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/COPYING.txt +674 -0
- data/History.txt +11 -0
- data/Manifest.txt +11 -0
- data/README.rdoc +164 -0
- data/Rakefile +19 -0
- data/examples/murmur.rb +51 -0
- data/lib/init.rb +30 -0
- data/lib/init/init.rb +85 -0
- data/spec/bin/mock_daemon.rb +32 -0
- data/spec/bin/simple_init.rb +86 -0
- data/spec/init_spec.rb +133 -0
- metadata +101 -0
data/spec/init_spec.rb
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# Copyright 2009 Alexander E. Fischer <aef@raxys.net>
|
|
2
|
+
#
|
|
3
|
+
# This file is part of Init.
|
|
4
|
+
#
|
|
5
|
+
# Init is free software: you can redistribute it and/or modify
|
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
# (at your option) any later version.
|
|
9
|
+
#
|
|
10
|
+
# This program is distributed in the hope that it will be useful,
|
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
# GNU General Public License for more details.
|
|
14
|
+
#
|
|
15
|
+
# You should have received a copy of the GNU General Public License
|
|
16
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
|
|
18
|
+
require 'lib/init'
|
|
19
|
+
|
|
20
|
+
require 'fileutils'
|
|
21
|
+
require 'tmpdir'
|
|
22
|
+
|
|
23
|
+
require 'rubygems'
|
|
24
|
+
require 'facets/timer'
|
|
25
|
+
|
|
26
|
+
module InitSpecHelper
|
|
27
|
+
# If there is a way to get the executable path of the currently running ruby
|
|
28
|
+
# interpreter, please tell me how.
|
|
29
|
+
warn 'Attention: If the ruby interpreter to be tested with is not ruby in the ' +
|
|
30
|
+
"default path, you have to change this manually in #{__FILE__} line #{__LINE__ + 1}"
|
|
31
|
+
RUBY_PATH = 'ruby'
|
|
32
|
+
|
|
33
|
+
def init_executable
|
|
34
|
+
"#{RUBY_PATH} spec/bin/simple_init.rb"
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
describe Aef::Init do
|
|
39
|
+
before(:each) do
|
|
40
|
+
# Before ruby 1.8.7, the tmpdir standard library had no method to create
|
|
41
|
+
# a temporary directory (mktmpdir).
|
|
42
|
+
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('1.8.7')
|
|
43
|
+
@folder_path = File.join(Dir.tmpdir, 'init_spec')
|
|
44
|
+
Dir.mkdir(@folder_path)
|
|
45
|
+
else
|
|
46
|
+
@folder_path = Dir.mktmpdir('init_spec')
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
after(:each) do
|
|
51
|
+
FileUtils.rm_rf(@folder_path)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
include InitSpecHelper
|
|
55
|
+
|
|
56
|
+
it "should correctly execute the start command" do
|
|
57
|
+
start_output = File.join(@folder_path, 'start_output')
|
|
58
|
+
|
|
59
|
+
lambda {
|
|
60
|
+
`#{init_executable} start #{start_output}`.should be_true
|
|
61
|
+
}.should change{File.exist?(start_output)}.from(false).to(true)
|
|
62
|
+
|
|
63
|
+
File.read(start_output).should eql("#{start_output} --start --example -y\n")
|
|
64
|
+
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
it "should correctly execute the stop command" do
|
|
68
|
+
stop_output = File.join(@folder_path, 'stop_output')
|
|
69
|
+
|
|
70
|
+
lambda {
|
|
71
|
+
`#{init_executable} stop #{stop_output}`.should be_true
|
|
72
|
+
}.should change{File.exist?(stop_output)}.from(false).to(true)
|
|
73
|
+
|
|
74
|
+
File.read(stop_output).should eql("#{stop_output} --stop --example -y\n")
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it "should correctly execute the restart command" do
|
|
78
|
+
restart_output = File.join(@folder_path, 'restart_output')
|
|
79
|
+
|
|
80
|
+
lambda {
|
|
81
|
+
`#{init_executable} restart #{restart_output}`.should be_true
|
|
82
|
+
}.should change{File.exist?(restart_output)}.from(false).to(true)
|
|
83
|
+
|
|
84
|
+
File.read(restart_output).should eql(
|
|
85
|
+
"#{restart_output} --stop --example -y\n#{restart_output} --start --example -y\n")
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
it "should correctly execute the middle command" do
|
|
89
|
+
middle_output = File.join(@folder_path, 'middle_output')
|
|
90
|
+
|
|
91
|
+
lambda {
|
|
92
|
+
`#{init_executable} middle #{middle_output}`.should be_true
|
|
93
|
+
}.should change{File.exist?(middle_output)}.from(false).to(true)
|
|
94
|
+
|
|
95
|
+
File.read(middle_output).should eql(
|
|
96
|
+
"#{middle_output} --middle -e --abc\n")
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
it "should wait 3 seconds between stop and start through the restart command" do
|
|
100
|
+
restart_output = File.join(@folder_path, 'restart_output')
|
|
101
|
+
|
|
102
|
+
timer = Timer.new
|
|
103
|
+
timer.start
|
|
104
|
+
|
|
105
|
+
`#{init_executable} restart #{restart_output}`.should be_true
|
|
106
|
+
|
|
107
|
+
timer.stop
|
|
108
|
+
(timer.total_time.should > 1.5).should be_true
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
it "should display a usage example if a wrong command is specified" do
|
|
112
|
+
usage_information = "Usage: spec/bin/simple_init.rb {middle|restart|start|stop}\n"
|
|
113
|
+
|
|
114
|
+
`#{init_executable} invalid`.should eql(usage_information)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
it "should only offer methods which are defined in Init or it's child classes" do
|
|
118
|
+
usage_information = "Usage: spec/bin/simple_init.rb {middle|restart|start|stop}\n"
|
|
119
|
+
|
|
120
|
+
`#{init_executable} methods`.should eql(usage_information)
|
|
121
|
+
`#{init_executable} frozen?`.should eql(usage_information)
|
|
122
|
+
`#{init_executable} to_a`.should eql(usage_information)
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
it "should only offer methods which are defined as public in Init or it's child classes" do
|
|
126
|
+
usage_information = "Usage: spec/bin/simple_init.rb {middle|restart|start|stop}\n"
|
|
127
|
+
|
|
128
|
+
`#{init_executable} middle_protected`.should eql(usage_information)
|
|
129
|
+
`#{init_executable} middle_private`.should eql(usage_information)
|
|
130
|
+
`#{init_executable} end_protected`.should eql(usage_information)
|
|
131
|
+
`#{init_executable} end_private`.should eql(usage_information)
|
|
132
|
+
end
|
|
133
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: aef-init
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Alexander E. Fischer
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
|
|
12
|
+
date: 2009-04-05 00:00:00 -07:00
|
|
13
|
+
default_executable:
|
|
14
|
+
dependencies:
|
|
15
|
+
- !ruby/object:Gem::Dependency
|
|
16
|
+
name: rspec
|
|
17
|
+
type: :development
|
|
18
|
+
version_requirement:
|
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
20
|
+
requirements:
|
|
21
|
+
- - ">="
|
|
22
|
+
- !ruby/object:Gem::Version
|
|
23
|
+
version: "0"
|
|
24
|
+
version:
|
|
25
|
+
- !ruby/object:Gem::Dependency
|
|
26
|
+
name: facets
|
|
27
|
+
type: :development
|
|
28
|
+
version_requirement:
|
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: "0"
|
|
34
|
+
version:
|
|
35
|
+
- !ruby/object:Gem::Dependency
|
|
36
|
+
name: hoe
|
|
37
|
+
type: :development
|
|
38
|
+
version_requirement:
|
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
40
|
+
requirements:
|
|
41
|
+
- - ">="
|
|
42
|
+
- !ruby/object:Gem::Version
|
|
43
|
+
version: 1.11.0
|
|
44
|
+
version:
|
|
45
|
+
description: Clean and simple *nix init scripts with Ruby
|
|
46
|
+
email:
|
|
47
|
+
- aef@raxys.net
|
|
48
|
+
executables: []
|
|
49
|
+
|
|
50
|
+
extensions: []
|
|
51
|
+
|
|
52
|
+
extra_rdoc_files:
|
|
53
|
+
- History.txt
|
|
54
|
+
- Manifest.txt
|
|
55
|
+
- COPYING.txt
|
|
56
|
+
- README.rdoc
|
|
57
|
+
files:
|
|
58
|
+
- History.txt
|
|
59
|
+
- Manifest.txt
|
|
60
|
+
- README.rdoc
|
|
61
|
+
- COPYING.txt
|
|
62
|
+
- Rakefile
|
|
63
|
+
- lib/init.rb
|
|
64
|
+
- lib/init/init.rb
|
|
65
|
+
- examples/murmur.rb
|
|
66
|
+
- spec/init_spec.rb
|
|
67
|
+
- spec/bin/mock_daemon.rb
|
|
68
|
+
- spec/bin/simple_init.rb
|
|
69
|
+
has_rdoc: true
|
|
70
|
+
homepage: https://rubyforge.org/projects/aef/
|
|
71
|
+
post_install_message:
|
|
72
|
+
rdoc_options:
|
|
73
|
+
- --main
|
|
74
|
+
- README.rdoc
|
|
75
|
+
- --inline-source
|
|
76
|
+
- --line-numbers
|
|
77
|
+
- --title
|
|
78
|
+
- Init
|
|
79
|
+
require_paths:
|
|
80
|
+
- lib
|
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
82
|
+
requirements:
|
|
83
|
+
- - ">="
|
|
84
|
+
- !ruby/object:Gem::Version
|
|
85
|
+
version: "0"
|
|
86
|
+
version:
|
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
88
|
+
requirements:
|
|
89
|
+
- - ">="
|
|
90
|
+
- !ruby/object:Gem::Version
|
|
91
|
+
version: "0"
|
|
92
|
+
version:
|
|
93
|
+
requirements: []
|
|
94
|
+
|
|
95
|
+
rubyforge_project: aef
|
|
96
|
+
rubygems_version: 1.2.0
|
|
97
|
+
signing_key:
|
|
98
|
+
specification_version: 2
|
|
99
|
+
summary: Clean and simple *nix init scripts with Ruby
|
|
100
|
+
test_files: []
|
|
101
|
+
|