silk 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +17 -0
- data/Gemfile.lock +48 -0
- data/README.rdoc +26 -6
- data/Rakefile +29 -38
- data/VERSION +1 -1
- data/lib/silk.rb +7 -1
- data/lib/silk/exceptions/task_not_found.rb +6 -0
- data/lib/silk/options.rb +19 -1
- data/lib/silk/runner.rb +48 -0
- data/lib/silk/server.rb +34 -35
- data/silk.gemspec +51 -45
- data/test/bin/failure +1 -1
- data/test/bin/successful +1 -1
- data/test/helper.rb +8 -0
- data/test/test_dsl.rb +1 -1
- data/test/test_helper.rb +0 -1
- data/test/test_options.rb +49 -0
- data/test/test_runner.rb +32 -0
- data/test/test_server.rb +10 -4
- data/test/test_silk.rb +9 -0
- metadata +96 -65
- data/.gitignore +0 -21
data/Gemfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
source 'http://rubygems.org'
|
2
|
+
|
3
|
+
gem 'daemons', '>= 0'
|
4
|
+
gem 'json', '>= 0'
|
5
|
+
gem 'sinatra', '>= 0'
|
6
|
+
gem 'SyslogLogger', '>= 0'
|
7
|
+
gem 'rdoc'
|
8
|
+
|
9
|
+
group :development, :test do
|
10
|
+
gem 'shoulda', '>= 0'
|
11
|
+
gem 'mocha', '>= 0'
|
12
|
+
gem 'bundler', '~> 1.0.0'
|
13
|
+
gem 'jeweler', '~> 1.6.4'
|
14
|
+
gem 'rcov', '>= 0'
|
15
|
+
gem 'rack-test', '>= 0'
|
16
|
+
gem 'redgreen', '1.2.2'
|
17
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
SyslogLogger (1.4.0)
|
5
|
+
hoe (>= 1.2.0)
|
6
|
+
daemons (1.1.0)
|
7
|
+
git (1.2.5)
|
8
|
+
hoe (2.6.1)
|
9
|
+
rake (>= 0.8.7)
|
10
|
+
rubyforge (>= 2.0.4)
|
11
|
+
jeweler (1.6.4)
|
12
|
+
bundler (~> 1.0)
|
13
|
+
git (>= 1.2.5)
|
14
|
+
rake
|
15
|
+
json (1.4.6)
|
16
|
+
json_pure (1.4.6)
|
17
|
+
mocha (0.9.12)
|
18
|
+
rack (1.2.3)
|
19
|
+
rack-test (0.5.7)
|
20
|
+
rack (>= 1.0)
|
21
|
+
rake (0.9.2)
|
22
|
+
rcov (0.9.8)
|
23
|
+
rdoc (3.8)
|
24
|
+
redgreen (1.2.2)
|
25
|
+
rubyforge (2.0.4)
|
26
|
+
json_pure (>= 1.1.7)
|
27
|
+
shoulda (2.11.3)
|
28
|
+
sinatra (1.2.6)
|
29
|
+
rack (~> 1.1)
|
30
|
+
tilt (>= 1.2.2, < 2.0)
|
31
|
+
tilt (1.3)
|
32
|
+
|
33
|
+
PLATFORMS
|
34
|
+
ruby
|
35
|
+
|
36
|
+
DEPENDENCIES
|
37
|
+
SyslogLogger
|
38
|
+
bundler (~> 1.0.0)
|
39
|
+
daemons
|
40
|
+
jeweler (~> 1.6.4)
|
41
|
+
json
|
42
|
+
mocha
|
43
|
+
rack-test
|
44
|
+
rcov
|
45
|
+
rdoc
|
46
|
+
redgreen (= 1.2.2)
|
47
|
+
shoulda
|
48
|
+
sinatra
|
data/README.rdoc
CHANGED
@@ -58,15 +58,35 @@ By default it runs on port 8888 and will probably need to be run as root to make
|
|
58
58
|
|
59
59
|
Eventually it'll support SSL certificates etc, but until then, I suggest you either use SSH tunnels, and/or (at the very least) lock down via a firewall. You could also build a rack.up file, and run it behind a web server that gives you more control (Rack.up file is on the todo list).
|
60
60
|
|
61
|
-
== Testing
|
61
|
+
== Testing your recipes
|
62
62
|
|
63
|
-
There
|
63
|
+
There are two ways to test your recipes - you can chose to just run them on the command line, using the -t switch
|
64
64
|
|
65
|
-
|
65
|
+
silk -t --param user=joe --param email=joe@blogs.com --format json
|
66
|
+
|
67
|
+
or via unit tests.
|
68
|
+
|
69
|
+
require 'silk'
|
70
|
+
|
71
|
+
class TestDSL < Test::Unit::TestCase
|
72
|
+
results = Runner.execute('task:name', { 'user' => 'joe', 'email' => 'joe@blogs.com' })
|
73
|
+
end
|
74
|
+
|
75
|
+
the results hash will have three elements: stdout, stderr and a process result object
|
66
76
|
|
67
|
-
|
77
|
+
results[:stdout]
|
78
|
+
results[:stderr]
|
79
|
+
results[:status]
|
68
80
|
|
69
|
-
|
81
|
+
To get the exit status of the task:
|
82
|
+
|
83
|
+
status = results[:status].exitstatus
|
84
|
+
|
85
|
+
== Testing Silk
|
86
|
+
|
87
|
+
There is a test suite. It uses shoulda + mocha + test::rack
|
88
|
+
|
89
|
+
If you are going to submit patches, please try to make sure the tests pass, and that you have created a test covering the changes you have made
|
70
90
|
|
71
91
|
== Note on Patches/Pull Requests
|
72
92
|
|
@@ -81,4 +101,4 @@ This is a really early release, that still needs more testing (This is so far mo
|
|
81
101
|
|
82
102
|
== Copyright
|
83
103
|
|
84
|
-
Copyright (c) 2010 Myles Eftos. See LICENSE for details.
|
104
|
+
Copyright (c) 2010,2011 Myles Eftos. See LICENSE for details.
|
data/Rakefile
CHANGED
@@ -1,31 +1,28 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
2
12
|
require 'rake'
|
3
13
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
gem.add_dependency 'daemons'
|
16
|
-
gem.add_dependency 'json'
|
17
|
-
gem.add_dependency 'sinatra'
|
18
|
-
gem.add_dependency 'SyslogLogger'
|
19
|
-
|
20
|
-
gem.add_development_dependency "shoulda"
|
21
|
-
gem.add_development_dependency "rack-test"
|
22
|
-
gem.add_development_dependency "redgreen"
|
23
|
-
gem.add_development_dependency "mocha"
|
24
|
-
end
|
25
|
-
Jeweler::GemcutterTasks.new
|
26
|
-
rescue LoadError
|
27
|
-
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# dependencies defined in Gemfile
|
17
|
+
gem.name = "silk"
|
18
|
+
gem.executables = "silk"
|
19
|
+
gem.summary = %Q{A framework for creating a hosting console}
|
20
|
+
gem.description = %Q{It allows you to write rake tasks to do common tasks, such as creating email addresses, adding users etc. Silk provides a HTTP wrapper the the rake tasks, and allows communication via JSON objects, which makes it dead easy for them to be called from a web app.}
|
21
|
+
gem.email = "myles@madpilot.com.au"
|
22
|
+
gem.homepage = "http://github.com/madpilot/silk"
|
23
|
+
gem.authors = ["Myles Eftos"]
|
28
24
|
end
|
25
|
+
Jeweler::RubygemsDotOrgTasks.new
|
29
26
|
|
30
27
|
require 'rake/testtask'
|
31
28
|
Rake::TestTask.new(:test) do |test|
|
@@ -34,24 +31,18 @@ Rake::TestTask.new(:test) do |test|
|
|
34
31
|
test.verbose = true
|
35
32
|
end
|
36
33
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
end
|
44
|
-
rescue LoadError
|
45
|
-
task :rcov do
|
46
|
-
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
47
|
-
end
|
34
|
+
require 'rcov/rcovtask'
|
35
|
+
Rcov::RcovTask.new do |test|
|
36
|
+
test.libs << 'test'
|
37
|
+
test.pattern = 'test/**/test_*.rb'
|
38
|
+
test.verbose = true
|
39
|
+
test.rcov_opts << '--exclude "gems/*"'
|
48
40
|
end
|
49
41
|
|
50
|
-
task :test => :check_dependencies
|
51
42
|
task :default => :test
|
52
43
|
|
53
|
-
require '
|
54
|
-
|
44
|
+
require 'rdoc/task'
|
45
|
+
RDoc::Task.new do |rdoc|
|
55
46
|
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
56
47
|
|
57
48
|
rdoc.rdoc_dir = 'rdoc'
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.5
|
data/lib/silk.rb
CHANGED
@@ -5,6 +5,8 @@ require 'rake'
|
|
5
5
|
require 'syslog_logger'
|
6
6
|
require 'daemons'
|
7
7
|
require 'options'
|
8
|
+
require 'runner'
|
9
|
+
require 'exceptions/task_not_found'
|
8
10
|
require 'server'
|
9
11
|
require 'tasks'
|
10
12
|
|
@@ -25,7 +27,11 @@ module Silk
|
|
25
27
|
Daemons.call(options) do
|
26
28
|
$0 = old_proc_name
|
27
29
|
Dir.chdir pwd
|
28
|
-
|
30
|
+
if options[:test]
|
31
|
+
puts Runner.test(options[:test_task], options[:test_params])
|
32
|
+
else
|
33
|
+
Server.run! :host => options[:bind], :port => options[:port], :environment => :production
|
34
|
+
end
|
29
35
|
end
|
30
36
|
end
|
31
37
|
|
data/lib/silk/options.rb
CHANGED
@@ -50,7 +50,25 @@ class Options
|
|
50
50
|
opts.on('-s [server list]', '--server', /.+/, 'handler used for built-in web server') do |server|
|
51
51
|
options[:server] = [ server ]
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
|
+
options[:test] = false
|
55
|
+
options[:test_task] = nil
|
56
|
+
opts.on('-t [task]', '--test', /.+/, 'Test the supplied rake task on the command line') do |test|
|
57
|
+
options[:test] = true
|
58
|
+
options[:test_task] = test
|
59
|
+
options[:ontop] = true
|
60
|
+
end
|
61
|
+
|
62
|
+
options[:test_params] = {}
|
63
|
+
opts.on('--param [param]', '--parameter', /.+/, 'Parameters to pass in to the test task. Enter as key/value pairs, ie user=joe') do |param|
|
64
|
+
k, v = param.split('=')
|
65
|
+
options[:test_params][k] = v
|
66
|
+
end
|
67
|
+
|
68
|
+
opts.on('--format [format]', /.+/, 'Output format') do |format|
|
69
|
+
ENV['format'] = format
|
70
|
+
end
|
71
|
+
|
54
72
|
opts.on('-v', '--version') do
|
55
73
|
File.open(File.join(File.dirname(__FILE__), '..', '..', 'VERSION')) do |fh|
|
56
74
|
puts fh.read
|
data/lib/silk/runner.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
module Silk
|
2
|
+
class Runner
|
3
|
+
def self.execute(task, params)
|
4
|
+
tasks = Silk::Tasks.new
|
5
|
+
raise Silk::Exceptions::TaskNotFound unless tasks.list.include?(task)
|
6
|
+
|
7
|
+
results = { :stdout => '', :stderr => '', :status => nil }
|
8
|
+
params.delete("captures")
|
9
|
+
|
10
|
+
stdout_read, stdout_write = IO.pipe
|
11
|
+
stderr_read, stderr_write = IO.pipe
|
12
|
+
pid = Process.fork do
|
13
|
+
$stdout.reopen stdout_write
|
14
|
+
$stderr.reopen stderr_write
|
15
|
+
stdout_read.close
|
16
|
+
stderr_read.close
|
17
|
+
tasks.run(task, params)
|
18
|
+
end
|
19
|
+
|
20
|
+
stdout_write.close
|
21
|
+
stderr_write.close
|
22
|
+
|
23
|
+
stdout_read.each do |line|
|
24
|
+
results[:stdout] += line
|
25
|
+
end
|
26
|
+
stderr_read.each do |line|
|
27
|
+
results[:stderr] += line
|
28
|
+
end
|
29
|
+
|
30
|
+
pid, status = Process.waitpid2(pid)
|
31
|
+
results[:status] = status
|
32
|
+
results[:stdout].strip!
|
33
|
+
results[:stderr].strip!
|
34
|
+
|
35
|
+
return results
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.test(task, params)
|
39
|
+
results = self.execute(task, params)
|
40
|
+
|
41
|
+
if results[:status].exitstatus != 0
|
42
|
+
"Error: #{results[:stderr]}"
|
43
|
+
else
|
44
|
+
"Success: #{results[:stdout]}"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/silk/server.rb
CHANGED
@@ -3,12 +3,12 @@ require 'sinatra/base'
|
|
3
3
|
|
4
4
|
module Silk
|
5
5
|
class Server < Sinatra::Base
|
6
|
-
|
6
|
+
def process(context, params)
|
7
7
|
options = Silk.options
|
8
8
|
task = nil
|
9
9
|
format = 'text'
|
10
10
|
|
11
|
-
query =
|
11
|
+
query = context.split('.')
|
12
12
|
format = query.pop if query.size > 1
|
13
13
|
task = query.join('.').gsub("/", ":")
|
14
14
|
|
@@ -20,43 +20,42 @@ module Silk
|
|
20
20
|
else
|
21
21
|
content_type('text/plain')
|
22
22
|
end
|
23
|
-
|
24
|
-
tasks = Silk::Tasks.new
|
25
|
-
unless tasks.list.include?(task)
|
26
|
-
not_found("Not Found")
|
27
|
-
end
|
28
|
-
|
29
|
-
results = { :stdout => '', :stderr => '' }
|
30
|
-
params.delete("captures")
|
23
|
+
|
31
24
|
ENV['format'] = format
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
25
|
+
|
26
|
+
begin
|
27
|
+
results = Runner.execute(task, params)
|
28
|
+
headers('X_PROCESS_EXIT_STATUS' => results[:status].exitstatus.to_s)
|
29
|
+
|
30
|
+
if results[:status].exitstatus != 0
|
31
|
+
error(500, results[:stderr])
|
32
|
+
else
|
33
|
+
results[:stdout]
|
34
|
+
end
|
42
35
|
|
43
|
-
|
44
|
-
|
45
|
-
stdout_read.each do |line|
|
46
|
-
results[:stdout] += line
|
47
|
-
end
|
48
|
-
stderr_read.each do |line|
|
49
|
-
results[:stderr] += line
|
36
|
+
rescue Silk::Exceptions::TaskNotFound
|
37
|
+
not_found("Not found")
|
50
38
|
end
|
51
|
-
|
39
|
+
end
|
40
|
+
|
41
|
+
get %r{\/(.+)} do |context|
|
42
|
+
process context, params
|
43
|
+
end
|
44
|
+
|
45
|
+
post %r{\/(.+)} do |context|
|
46
|
+
process context, params
|
47
|
+
end
|
52
48
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
49
|
+
put %r{\/(.+)} do |context|
|
50
|
+
process context, params
|
51
|
+
end
|
52
|
+
|
53
|
+
delete %r{\/(.+)} do |context|
|
54
|
+
process context, params
|
55
|
+
end
|
56
|
+
|
57
|
+
not_found do
|
58
|
+
'Not found'
|
60
59
|
end
|
61
60
|
end
|
62
61
|
end
|
data/silk.gemspec
CHANGED
@@ -1,96 +1,102 @@
|
|
1
1
|
# Generated by jeweler
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{silk}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.5"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Myles Eftos"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2011-07-30}
|
13
13
|
s.default_executable = %q{silk}
|
14
14
|
s.description = %q{It allows you to write rake tasks to do common tasks, such as creating email addresses, adding users etc. Silk provides a HTTP wrapper the the rake tasks, and allows communication via JSON objects, which makes it dead easy for them to be called from a web app.}
|
15
15
|
s.email = %q{myles@madpilot.com.au}
|
16
16
|
s.executables = ["silk"]
|
17
17
|
s.extra_rdoc_files = [
|
18
18
|
"LICENSE",
|
19
|
-
|
19
|
+
"README.rdoc"
|
20
20
|
]
|
21
21
|
s.files = [
|
22
22
|
".document",
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
23
|
+
"Gemfile",
|
24
|
+
"Gemfile.lock",
|
25
|
+
"LICENSE",
|
26
|
+
"README.rdoc",
|
27
|
+
"Rakefile",
|
28
|
+
"VERSION",
|
29
|
+
"bin/silk",
|
30
|
+
"install.rb",
|
31
|
+
"lib/silk.rb",
|
32
|
+
"lib/silk/dsl.rake",
|
33
|
+
"lib/silk/exceptions/task_not_found.rb",
|
34
|
+
"lib/silk/options.rb",
|
35
|
+
"lib/silk/runner.rb",
|
36
|
+
"lib/silk/server.rb",
|
37
|
+
"lib/silk/tasks.rb",
|
38
|
+
"silk.gemspec",
|
39
|
+
"test/bin/failure",
|
40
|
+
"test/bin/successful",
|
41
|
+
"test/helper.rb",
|
42
|
+
"test/rakefiles/test.rake",
|
43
|
+
"test/test_dsl.rb",
|
44
|
+
"test/test_helper.rb",
|
45
|
+
"test/test_options.rb",
|
46
|
+
"test/test_runner.rb",
|
47
|
+
"test/test_server.rb",
|
48
|
+
"test/test_silk.rb",
|
49
|
+
"test/test_tasks.rb"
|
46
50
|
]
|
47
51
|
s.homepage = %q{http://github.com/madpilot/silk}
|
48
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
49
52
|
s.require_paths = ["lib"]
|
50
|
-
s.rubygems_version = %q{1.3.
|
53
|
+
s.rubygems_version = %q{1.3.6}
|
51
54
|
s.summary = %q{A framework for creating a hosting console}
|
52
|
-
s.test_files = [
|
53
|
-
"test/helper.rb",
|
54
|
-
"test/test_dsl.rb",
|
55
|
-
"test/test_helper.rb",
|
56
|
-
"test/test_options.rb",
|
57
|
-
"test/test_server.rb",
|
58
|
-
"test/test_silk.rb",
|
59
|
-
"test/test_tasks.rb"
|
60
|
-
]
|
61
55
|
|
62
56
|
if s.respond_to? :specification_version then
|
63
57
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
64
58
|
s.specification_version = 3
|
65
59
|
|
66
|
-
if Gem::Version.new(Gem::
|
60
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
67
61
|
s.add_runtime_dependency(%q<daemons>, [">= 0"])
|
68
62
|
s.add_runtime_dependency(%q<json>, [">= 0"])
|
69
63
|
s.add_runtime_dependency(%q<sinatra>, [">= 0"])
|
70
64
|
s.add_runtime_dependency(%q<SyslogLogger>, [">= 0"])
|
65
|
+
s.add_runtime_dependency(%q<rdoc>, [">= 0"])
|
71
66
|
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
72
|
-
s.add_development_dependency(%q<rack-test>, [">= 0"])
|
73
|
-
s.add_development_dependency(%q<redgreen>, [">= 0"])
|
74
67
|
s.add_development_dependency(%q<mocha>, [">= 0"])
|
68
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
69
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
|
70
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
71
|
+
s.add_development_dependency(%q<rack-test>, [">= 0"])
|
72
|
+
s.add_development_dependency(%q<redgreen>, ["= 1.2.2"])
|
75
73
|
else
|
76
74
|
s.add_dependency(%q<daemons>, [">= 0"])
|
77
75
|
s.add_dependency(%q<json>, [">= 0"])
|
78
76
|
s.add_dependency(%q<sinatra>, [">= 0"])
|
79
77
|
s.add_dependency(%q<SyslogLogger>, [">= 0"])
|
78
|
+
s.add_dependency(%q<rdoc>, [">= 0"])
|
80
79
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
81
|
-
s.add_dependency(%q<rack-test>, [">= 0"])
|
82
|
-
s.add_dependency(%q<redgreen>, [">= 0"])
|
83
80
|
s.add_dependency(%q<mocha>, [">= 0"])
|
81
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
82
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
83
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
84
|
+
s.add_dependency(%q<rack-test>, [">= 0"])
|
85
|
+
s.add_dependency(%q<redgreen>, ["= 1.2.2"])
|
84
86
|
end
|
85
87
|
else
|
86
88
|
s.add_dependency(%q<daemons>, [">= 0"])
|
87
89
|
s.add_dependency(%q<json>, [">= 0"])
|
88
90
|
s.add_dependency(%q<sinatra>, [">= 0"])
|
89
91
|
s.add_dependency(%q<SyslogLogger>, [">= 0"])
|
92
|
+
s.add_dependency(%q<rdoc>, [">= 0"])
|
90
93
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
91
|
-
s.add_dependency(%q<rack-test>, [">= 0"])
|
92
|
-
s.add_dependency(%q<redgreen>, [">= 0"])
|
93
94
|
s.add_dependency(%q<mocha>, [">= 0"])
|
95
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
96
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
97
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
98
|
+
s.add_dependency(%q<rack-test>, [">= 0"])
|
99
|
+
s.add_dependency(%q<redgreen>, ["= 1.2.2"])
|
94
100
|
end
|
95
101
|
end
|
96
102
|
|
data/test/bin/failure
CHANGED
data/test/bin/successful
CHANGED
data/test/helper.rb
CHANGED
@@ -1,4 +1,12 @@
|
|
1
1
|
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
2
10
|
require 'test/unit'
|
3
11
|
require 'shoulda'
|
4
12
|
|
data/test/test_dsl.rb
CHANGED
@@ -209,7 +209,7 @@ class TestDSL < Test::Unit::TestCase
|
|
209
209
|
assert_equal 'Success!', result.stdout.strip
|
210
210
|
end
|
211
211
|
|
212
|
-
should 'set the
|
212
|
+
should 'set the stderr value' do
|
213
213
|
result = @context.run File.join(File.dirname(__FILE__), '..', 'test', 'bin', 'failure')
|
214
214
|
assert_equal 'Fail :(', result.stderr.strip
|
215
215
|
end
|
data/test/test_helper.rb
CHANGED
data/test/test_options.rb
CHANGED
@@ -158,6 +158,55 @@ class TestOptions < Test::Unit::TestCase
|
|
158
158
|
assert_equal [ 'iis' ], options[:server]
|
159
159
|
end
|
160
160
|
|
161
|
+
should 'set the test flag if -t is set' do
|
162
|
+
ARGV << '-t'
|
163
|
+
options = Options.parse
|
164
|
+
assert options[:test]
|
165
|
+
end
|
166
|
+
|
167
|
+
should 'set the test flag if --test is set' do
|
168
|
+
ARGV << '--test'
|
169
|
+
ARGV << "test:task"
|
170
|
+
options = Options.parse
|
171
|
+
assert options[:test]
|
172
|
+
assert_equal "test:task", options[:test_task]
|
173
|
+
end
|
174
|
+
|
175
|
+
should 'set the ontop flag if -t is set' do
|
176
|
+
ARGV << '-t'
|
177
|
+
ARGV << "test:task"
|
178
|
+
options = Options.parse
|
179
|
+
assert_equal true, options[:ontop]
|
180
|
+
assert_equal "test:task", options[:test_task]
|
181
|
+
end
|
182
|
+
|
183
|
+
should 'set the optop flag if --test is set' do
|
184
|
+
ARGV << '--test'
|
185
|
+
options = Options.parse
|
186
|
+
assert_equal true, options[:ontop]
|
187
|
+
end
|
188
|
+
|
189
|
+
should 'add params to the test_params array if --param is set' do
|
190
|
+
ARGV << '--param'
|
191
|
+
ARGV << 'user=joe'
|
192
|
+
options = Options.parse
|
193
|
+
assert_equal 'joe', options[:test_params]['user']
|
194
|
+
end
|
195
|
+
|
196
|
+
should 'add params to the test_params array if --paramaters is set' do
|
197
|
+
ARGV << '--parameter'
|
198
|
+
ARGV << 'user=joe'
|
199
|
+
options = Options.parse
|
200
|
+
assert_equal 'joe', options[:test_params]['user']
|
201
|
+
end
|
202
|
+
|
203
|
+
should 'set the format environment variable if --format is set' do
|
204
|
+
ARGV << '--format'
|
205
|
+
ARGV << 'json'
|
206
|
+
options = Options.parse
|
207
|
+
assert_equal 'json', ENV['format']
|
208
|
+
end
|
209
|
+
|
161
210
|
should 'display the VERSION of -v is set' do
|
162
211
|
ARGV << '-v'
|
163
212
|
|
data/test/test_runner.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TestRunner < Test::Unit::TestCase
|
4
|
+
context 'TestRunner' do
|
5
|
+
setup do
|
6
|
+
Silk.options = { :recipe_paths => File.join(File.dirname(File.expand_path(__FILE__)), 'rakefiles') }
|
7
|
+
ENV['format'] = nil
|
8
|
+
end
|
9
|
+
|
10
|
+
should "raise TaskNotFound exception if the task isn't found" do
|
11
|
+
assert_raise Silk::Exceptions::TaskNotFound do
|
12
|
+
Silk::Runner.execute('task:does:not:exist', {})
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
should 'fill the stdout on success' do
|
17
|
+
assert_nothing_raised do
|
18
|
+
results = Silk::Runner.execute('level_1:level_2', {})
|
19
|
+
assert_equal 'text', results[:stdout].strip
|
20
|
+
assert_equal 0, results[:status].exitstatus
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
should 'fill the stderr on error' do
|
25
|
+
assert_nothing_raised do
|
26
|
+
results = Silk::Runner.execute('errors:return', {})
|
27
|
+
assert_equal 'Error', results[:stderr].strip
|
28
|
+
assert_equal 1, results[:status].exitstatus
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/test/test_server.rb
CHANGED
@@ -12,32 +12,38 @@ class TestServer < Test::Unit::TestCase
|
|
12
12
|
Silk.options = { :recipe_paths => File.join(File.dirname(File.expand_path(__FILE__)), 'rakefiles') }
|
13
13
|
end
|
14
14
|
|
15
|
+
should 'return simple 404 if the task is not found' do
|
16
|
+
get '/'
|
17
|
+
assert last_response.not_found?
|
18
|
+
assert_match "Not found", last_response.body
|
19
|
+
end
|
20
|
+
|
15
21
|
context 'mime_types' do
|
16
22
|
should "return 'text/plain' if there is no format" do
|
17
23
|
get '/level_1/level_2'
|
18
24
|
assert last_response.ok?
|
19
|
-
|
25
|
+
assert_match /text\/plain/, last_response.headers['Content-Type']
|
20
26
|
assert_equal "text", last_response.body
|
21
27
|
end
|
22
28
|
|
23
29
|
should "return 'text/plain' if the format isn't recognised" do
|
24
30
|
get '/level_1/level_2.csv'
|
25
31
|
assert last_response.ok?
|
26
|
-
|
32
|
+
assert_match /text\/plain/, last_response.headers['Content-Type']
|
27
33
|
assert_equal "text", last_response.body
|
28
34
|
end
|
29
35
|
|
30
36
|
should "return 'application/json' if there is no format" do
|
31
37
|
get '/level_1/level_2.json'
|
32
38
|
assert last_response.ok?
|
33
|
-
|
39
|
+
assert_match /application\/json/, last_response.headers['Content-Type']
|
34
40
|
assert_equal "json".to_json, last_response.body
|
35
41
|
end
|
36
42
|
|
37
43
|
should "return 'application/xml' if there is no format" do
|
38
44
|
get '/level_1/level_2.xml'
|
39
45
|
assert last_response.ok?
|
40
|
-
|
46
|
+
assert_match /application\/xml/, last_response.headers['Content-Type']
|
41
47
|
assert_equal "<xml>xml</xml>", last_response.body
|
42
48
|
end
|
43
49
|
end
|
data/test/test_silk.rb
CHANGED
@@ -44,6 +44,15 @@ class TestSilk < Test::Unit::TestCase
|
|
44
44
|
Silk::Server.expects(:run!).with({ :host => '1.2.3.4', :port => 80, :environment => :production })
|
45
45
|
Silk.run
|
46
46
|
end
|
47
|
+
|
48
|
+
should 'use run the test runner if in test mode' do
|
49
|
+
logger_mock = mock
|
50
|
+
options = { :test => true, :test_task => 'test:task', :test_params => { 'test' => 'param' } }
|
51
|
+
Options.stubs(:parse).returns(options)
|
52
|
+
Logger.stubs(:new).returns(logger_mock)
|
53
|
+
Silk::Runner.expects(:test).with('test:task', { 'test' => 'param' })
|
54
|
+
Silk.run
|
55
|
+
end
|
47
56
|
end
|
48
57
|
end
|
49
58
|
end
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: silk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 23
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 0
|
8
7
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
8
|
+
- 5
|
9
|
+
version: 0.0.5
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Myles Eftos
|
@@ -15,121 +14,159 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date:
|
17
|
+
date: 2011-07-30 00:00:00 +08:00
|
19
18
|
default_executable: silk
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
22
|
-
|
23
|
-
prerelease: false
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
21
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
26
22
|
requirements:
|
27
23
|
- - ">="
|
28
24
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 3
|
30
25
|
segments:
|
31
26
|
- 0
|
32
27
|
version: "0"
|
28
|
+
requirement: *id001
|
29
|
+
name: daemons
|
30
|
+
prerelease: false
|
33
31
|
type: :runtime
|
34
|
-
version_requirements: *id001
|
35
32
|
- !ruby/object:Gem::Dependency
|
36
|
-
|
37
|
-
prerelease: false
|
38
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
-
none: false
|
33
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
40
34
|
requirements:
|
41
35
|
- - ">="
|
42
36
|
- !ruby/object:Gem::Version
|
43
|
-
hash: 3
|
44
37
|
segments:
|
45
38
|
- 0
|
46
39
|
version: "0"
|
40
|
+
requirement: *id002
|
41
|
+
name: json
|
42
|
+
prerelease: false
|
47
43
|
type: :runtime
|
48
|
-
version_requirements: *id002
|
49
44
|
- !ruby/object:Gem::Dependency
|
50
|
-
|
51
|
-
prerelease: false
|
52
|
-
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
-
none: false
|
45
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
54
46
|
requirements:
|
55
47
|
- - ">="
|
56
48
|
- !ruby/object:Gem::Version
|
57
|
-
hash: 3
|
58
49
|
segments:
|
59
50
|
- 0
|
60
51
|
version: "0"
|
52
|
+
requirement: *id003
|
53
|
+
name: sinatra
|
54
|
+
prerelease: false
|
61
55
|
type: :runtime
|
62
|
-
version_requirements: *id003
|
63
56
|
- !ruby/object:Gem::Dependency
|
57
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
segments:
|
62
|
+
- 0
|
63
|
+
version: "0"
|
64
|
+
requirement: *id004
|
64
65
|
name: SyslogLogger
|
65
66
|
prerelease: false
|
66
|
-
|
67
|
-
|
67
|
+
type: :runtime
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
68
70
|
requirements:
|
69
71
|
- - ">="
|
70
72
|
- !ruby/object:Gem::Version
|
71
|
-
hash: 3
|
72
73
|
segments:
|
73
74
|
- 0
|
74
75
|
version: "0"
|
76
|
+
requirement: *id005
|
77
|
+
name: rdoc
|
78
|
+
prerelease: false
|
75
79
|
type: :runtime
|
76
|
-
version_requirements: *id004
|
77
80
|
- !ruby/object:Gem::Dependency
|
78
|
-
|
79
|
-
prerelease: false
|
80
|
-
requirement: &id005 !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
81
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
82
82
|
requirements:
|
83
83
|
- - ">="
|
84
84
|
- !ruby/object:Gem::Version
|
85
|
-
hash: 3
|
86
85
|
segments:
|
87
86
|
- 0
|
88
87
|
version: "0"
|
88
|
+
requirement: *id006
|
89
|
+
name: shoulda
|
90
|
+
prerelease: false
|
89
91
|
type: :development
|
90
|
-
version_requirements: *id005
|
91
92
|
- !ruby/object:Gem::Dependency
|
92
|
-
|
93
|
-
prerelease: false
|
94
|
-
requirement: &id006 !ruby/object:Gem::Requirement
|
95
|
-
none: false
|
93
|
+
version_requirements: &id007 !ruby/object:Gem::Requirement
|
96
94
|
requirements:
|
97
95
|
- - ">="
|
98
96
|
- !ruby/object:Gem::Version
|
99
|
-
hash: 3
|
100
97
|
segments:
|
101
98
|
- 0
|
102
99
|
version: "0"
|
100
|
+
requirement: *id007
|
101
|
+
name: mocha
|
102
|
+
prerelease: false
|
103
103
|
type: :development
|
104
|
-
version_requirements: *id006
|
105
104
|
- !ruby/object:Gem::Dependency
|
106
|
-
|
105
|
+
version_requirements: &id008 !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ~>
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
segments:
|
110
|
+
- 1
|
111
|
+
- 0
|
112
|
+
- 0
|
113
|
+
version: 1.0.0
|
114
|
+
requirement: *id008
|
115
|
+
name: bundler
|
116
|
+
prerelease: false
|
117
|
+
type: :development
|
118
|
+
- !ruby/object:Gem::Dependency
|
119
|
+
version_requirements: &id009 !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ~>
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
segments:
|
124
|
+
- 1
|
125
|
+
- 6
|
126
|
+
- 4
|
127
|
+
version: 1.6.4
|
128
|
+
requirement: *id009
|
129
|
+
name: jeweler
|
107
130
|
prerelease: false
|
108
|
-
|
109
|
-
|
131
|
+
type: :development
|
132
|
+
- !ruby/object:Gem::Dependency
|
133
|
+
version_requirements: &id010 !ruby/object:Gem::Requirement
|
110
134
|
requirements:
|
111
135
|
- - ">="
|
112
136
|
- !ruby/object:Gem::Version
|
113
|
-
hash: 3
|
114
137
|
segments:
|
115
138
|
- 0
|
116
139
|
version: "0"
|
140
|
+
requirement: *id010
|
141
|
+
name: rcov
|
142
|
+
prerelease: false
|
117
143
|
type: :development
|
118
|
-
version_requirements: *id007
|
119
144
|
- !ruby/object:Gem::Dependency
|
120
|
-
|
121
|
-
prerelease: false
|
122
|
-
requirement: &id008 !ruby/object:Gem::Requirement
|
123
|
-
none: false
|
145
|
+
version_requirements: &id011 !ruby/object:Gem::Requirement
|
124
146
|
requirements:
|
125
147
|
- - ">="
|
126
148
|
- !ruby/object:Gem::Version
|
127
|
-
hash: 3
|
128
149
|
segments:
|
129
150
|
- 0
|
130
151
|
version: "0"
|
152
|
+
requirement: *id011
|
153
|
+
name: rack-test
|
154
|
+
prerelease: false
|
155
|
+
type: :development
|
156
|
+
- !ruby/object:Gem::Dependency
|
157
|
+
version_requirements: &id012 !ruby/object:Gem::Requirement
|
158
|
+
requirements:
|
159
|
+
- - "="
|
160
|
+
- !ruby/object:Gem::Version
|
161
|
+
segments:
|
162
|
+
- 1
|
163
|
+
- 2
|
164
|
+
- 2
|
165
|
+
version: 1.2.2
|
166
|
+
requirement: *id012
|
167
|
+
name: redgreen
|
168
|
+
prerelease: false
|
131
169
|
type: :development
|
132
|
-
version_requirements: *id008
|
133
170
|
description: It allows you to write rake tasks to do common tasks, such as creating email addresses, adding users etc. Silk provides a HTTP wrapper the the rake tasks, and allows communication via JSON objects, which makes it dead easy for them to be called from a web app.
|
134
171
|
email: myles@madpilot.com.au
|
135
172
|
executables:
|
@@ -141,7 +178,8 @@ extra_rdoc_files:
|
|
141
178
|
- README.rdoc
|
142
179
|
files:
|
143
180
|
- .document
|
144
|
-
-
|
181
|
+
- Gemfile
|
182
|
+
- Gemfile.lock
|
145
183
|
- LICENSE
|
146
184
|
- README.rdoc
|
147
185
|
- Rakefile
|
@@ -150,7 +188,9 @@ files:
|
|
150
188
|
- install.rb
|
151
189
|
- lib/silk.rb
|
152
190
|
- lib/silk/dsl.rake
|
191
|
+
- lib/silk/exceptions/task_not_found.rb
|
153
192
|
- lib/silk/options.rb
|
193
|
+
- lib/silk/runner.rb
|
154
194
|
- lib/silk/server.rb
|
155
195
|
- lib/silk/tasks.rb
|
156
196
|
- silk.gemspec
|
@@ -161,6 +201,7 @@ files:
|
|
161
201
|
- test/test_dsl.rb
|
162
202
|
- test/test_helper.rb
|
163
203
|
- test/test_options.rb
|
204
|
+
- test/test_runner.rb
|
164
205
|
- test/test_server.rb
|
165
206
|
- test/test_silk.rb
|
166
207
|
- test/test_tasks.rb
|
@@ -169,40 +210,30 @@ homepage: http://github.com/madpilot/silk
|
|
169
210
|
licenses: []
|
170
211
|
|
171
212
|
post_install_message:
|
172
|
-
rdoc_options:
|
173
|
-
|
213
|
+
rdoc_options: []
|
214
|
+
|
174
215
|
require_paths:
|
175
216
|
- lib
|
176
217
|
required_ruby_version: !ruby/object:Gem::Requirement
|
177
|
-
none: false
|
178
218
|
requirements:
|
179
219
|
- - ">="
|
180
220
|
- !ruby/object:Gem::Version
|
181
|
-
hash: 3
|
182
221
|
segments:
|
183
222
|
- 0
|
184
223
|
version: "0"
|
185
224
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
186
|
-
none: false
|
187
225
|
requirements:
|
188
226
|
- - ">="
|
189
227
|
- !ruby/object:Gem::Version
|
190
|
-
hash: 3
|
191
228
|
segments:
|
192
229
|
- 0
|
193
230
|
version: "0"
|
194
231
|
requirements: []
|
195
232
|
|
196
233
|
rubyforge_project:
|
197
|
-
rubygems_version: 1.3.
|
234
|
+
rubygems_version: 1.3.6
|
198
235
|
signing_key:
|
199
236
|
specification_version: 3
|
200
237
|
summary: A framework for creating a hosting console
|
201
|
-
test_files:
|
202
|
-
|
203
|
-
- test/test_dsl.rb
|
204
|
-
- test/test_helper.rb
|
205
|
-
- test/test_options.rb
|
206
|
-
- test/test_server.rb
|
207
|
-
- test/test_silk.rb
|
208
|
-
- test/test_tasks.rb
|
238
|
+
test_files: []
|
239
|
+
|