decoct 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +43 -0
- data/Rakefile +32 -0
- data/VERSION +1 -0
- data/bin/decoct +7 -0
- data/lib/decoct/dconstants.rb +9 -0
- data/lib/decoct/dmeta.rb +35 -0
- data/lib/decoct/dscript.rb +54 -0
- data/lib/decoct.rb +5 -0
- data/lib/templates/.autotest +2 -0
- data/lib/templates/generic_app.rb +7 -0
- data/lib/templates/spec/app_spec.rb +9 -0
- data/lib/templates/spec/rcov.opts +1 -0
- data/lib/templates/spec/spec.opts +4 -0
- data/lib/templates/spec/spec_helper.rb +12 -0
- data/test/decoct/ts_script.rb +76 -0
- data/test/test_helper.rb +2 -0
- metadata +110 -0
data/README.markdown
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
Decoct: Quick start Sinatra with Rspec
|
2
|
+
=====================================
|
3
|
+
|
4
|
+
Decoct is a simple gem that creates a sinatra app directory structure and hooks it up with Rspec.
|
5
|
+
|
6
|
+
Installing
|
7
|
+
---------
|
8
|
+
|
9
|
+
Install the gem: sudo gem install andhapp-decoct -s http://gems.github.com (on Mac)
|
10
|
+
|
11
|
+
Dependencies
|
12
|
+
-----------
|
13
|
+
|
14
|
+
The gem depends on the following libraries:
|
15
|
+
|
16
|
+
* rspec
|
17
|
+
* ZenTest
|
18
|
+
* redgreen
|
19
|
+
* rcov
|
20
|
+
|
21
|
+
growl is the Mac OS X messaging system and there are a plethora of articles detailing its installation. Google 'growl Mac OS X' and you would definitely encounter some useful results.
|
22
|
+
|
23
|
+
Usage
|
24
|
+
----
|
25
|
+
|
26
|
+
Assuming that you have installed the gem. Use the command line and go to the directory where you would like to create
|
27
|
+
the new project and run the following command:
|
28
|
+
|
29
|
+
decoct {project-name}
|
30
|
+
|
31
|
+
This would create a sinatra project with all the rspec dependencies. If a directory with the same name exists it will
|
32
|
+
overwrite it. Just go into the directory on your command line and run the following command:
|
33
|
+
|
34
|
+
RSPEC=true autotest
|
35
|
+
|
36
|
+
Tests
|
37
|
+
---
|
38
|
+
|
39
|
+
In order to run the test, please do ruby -rubygems test/decoct/ts_script.rb which makes the test independent of rubygems.
|
40
|
+
|
41
|
+
Roadmap
|
42
|
+
---
|
43
|
+
To move the gem to gemcutter
|
data/Rakefile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# sinatra-rspec
|
2
|
+
|
3
|
+
%W{rake rake/testtask rake/rdoctask rcov/rcovtask}.each{|x| require x}
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'jeweler'
|
7
|
+
Jeweler::Tasks.new do |gem|
|
8
|
+
gem.name = "decoct"
|
9
|
+
gem.summary = "Its a simple gem which creates a project structure for sinatra to work with rspec, ZenTest, RedGreen, Rcov"
|
10
|
+
gem.email = "anuj@andhapp.com"
|
11
|
+
gem.homepage = "http://github.com/andhapp/decoct"
|
12
|
+
gem.description = "Sinatra Rspec project generator"
|
13
|
+
gem.authors = ["Anuj Dutta"]
|
14
|
+
gem.add_dependency 'rspec'
|
15
|
+
gem.add_dependency 'ZenTest'
|
16
|
+
gem.add_dependency 'redgreen'
|
17
|
+
gem.add_dependency 'rcov'
|
18
|
+
end
|
19
|
+
Jeweler::GemcutterTasks.new
|
20
|
+
rescue LoadError
|
21
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
22
|
+
end
|
23
|
+
|
24
|
+
desc "rake task to run all the tests"
|
25
|
+
Rake::TestTask.new do |t|
|
26
|
+
t.libs << "lib"
|
27
|
+
t.test_files = FileList['test/**/ts_*.rb']
|
28
|
+
t.verbose = true
|
29
|
+
t.ruby_opts = ['-rubygems']
|
30
|
+
end
|
31
|
+
|
32
|
+
task :default => [:test]
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/bin/decoct
ADDED
data/lib/decoct/dmeta.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'ftools'
|
2
|
+
|
3
|
+
module Decoct
|
4
|
+
module Dmeta
|
5
|
+
|
6
|
+
include Decoct::Dconstants
|
7
|
+
|
8
|
+
def copy_file(from, to)
|
9
|
+
if from.is_a?(Array) && to.is_a?(Array)
|
10
|
+
from.each_index {|i| copy_file(from[i], to[i])}
|
11
|
+
else
|
12
|
+
File.copy(Dconstants::TEMPLATES + from, to)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module ClassMethods
|
17
|
+
def create_dir(name)
|
18
|
+
if name.is_a?(Array)
|
19
|
+
name.map {|x| create_dir(x)}
|
20
|
+
else
|
21
|
+
define_method("create_#{name}") do
|
22
|
+
path = "#{@app_name}#{File::SEPARATOR}#{name}"
|
23
|
+
Dir.mkdir(path) if !test(?d, path)
|
24
|
+
puts "Created #{path}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.included(host_class)
|
31
|
+
host_class.extend(ClassMethods)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Decoct
|
2
|
+
|
3
|
+
class Dscript
|
4
|
+
|
5
|
+
include Decoct::Dmeta
|
6
|
+
|
7
|
+
attr_accessor :app_name
|
8
|
+
|
9
|
+
create_dir [:lib, :spec, :views, :public, :icons]
|
10
|
+
|
11
|
+
def initialize(app_name)
|
12
|
+
fail "app name cannot be nil or empty!!!" if app_name.eql?(nil) || app_name.empty?
|
13
|
+
@app_name = app_name
|
14
|
+
end
|
15
|
+
|
16
|
+
def run
|
17
|
+
create_app_dir
|
18
|
+
create_lib
|
19
|
+
create_spec
|
20
|
+
create_views
|
21
|
+
create_public
|
22
|
+
copy_autotest_file
|
23
|
+
copy_rspec_files
|
24
|
+
copy_app_file
|
25
|
+
end
|
26
|
+
|
27
|
+
def create_app_dir
|
28
|
+
Dir.mkdir("#{app_name}") if !test(?d, "#{app_name}")
|
29
|
+
puts "\nCreated application directory - #{app_name}"
|
30
|
+
end
|
31
|
+
|
32
|
+
def copy_autotest_file
|
33
|
+
copy_file(".autotest", "#{app_name}#{File::SEPARATOR}.autotest")
|
34
|
+
puts "\nCopied autotest files"
|
35
|
+
end
|
36
|
+
|
37
|
+
def copy_rspec_files
|
38
|
+
from = ["spec#{File::SEPARATOR}spec.opts", "spec#{File::SEPARATOR}rcov.opts", "spec#{File::SEPARATOR}spec_helper.rb", "spec#{File::SEPARATOR}app_spec.rb"]
|
39
|
+
to = ["#{app_name}#{File::SEPARATOR}spec#{File::SEPARATOR}spec.opts", "#{app_name}#{File::SEPARATOR}spec#{File::SEPARATOR}rcov.opts", "#{app_name}#{File::SEPARATOR}spec#{File::SEPARATOR}spec_helper.rb", "#{app_name}#{File::SEPARATOR}spec#{File::SEPARATOR}#{app_name}_spec.rb"]
|
40
|
+
copy_file(from, to)
|
41
|
+
|
42
|
+
file_string = File.open("#{app_name}#{File::SEPARATOR}spec#{File::SEPARATOR}spec_helper.rb") {|f| f.readlines.unshift("require '#{app_name}'\n").join }
|
43
|
+
File.open("#{app_name}#{File::SEPARATOR}spec#{File::SEPARATOR}spec_helper.rb", "w") {|f| f << file_string}
|
44
|
+
puts "\nCopied rspec files"
|
45
|
+
end
|
46
|
+
|
47
|
+
def copy_app_file
|
48
|
+
copy_file("generic_app.rb", "#{app_name}#{File::SEPARATOR}#{app_name}.rb")
|
49
|
+
puts "\nCopied application file"
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
data/lib/decoct.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--exclude "spec/*,gems/*"
|
@@ -0,0 +1,12 @@
|
|
1
|
+
%w{spec spec/autorun spec/interop/test rack/test}.each {|x| require x}
|
2
|
+
|
3
|
+
set :environment, :test
|
4
|
+
|
5
|
+
module AppHelper
|
6
|
+
include Rack::Test::Methods
|
7
|
+
def app; Sinatra::Application; end
|
8
|
+
end
|
9
|
+
|
10
|
+
Spec::Runner.configure do |config|
|
11
|
+
config.include AppeHelper
|
12
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '../test_helper.rb')
|
2
|
+
|
3
|
+
class TestScript < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def dir_in_app_folder
|
6
|
+
Dir.entries("epoxys").each {|x| [] << x if !File.directory?(x)}
|
7
|
+
end
|
8
|
+
|
9
|
+
context "Creation - sinatra-rspec app" do
|
10
|
+
setup do
|
11
|
+
@script = Decoct::Dscript.new('epoxys')
|
12
|
+
@app_name = @script.app_name
|
13
|
+
@script.create_app_dir
|
14
|
+
end
|
15
|
+
|
16
|
+
should 'create the app directory' do
|
17
|
+
assert File.exists?(@app_name)
|
18
|
+
end
|
19
|
+
|
20
|
+
should 'create a directory called lib' do
|
21
|
+
@script.create_lib
|
22
|
+
assert_not_nil dir_in_app_folder.index("lib")
|
23
|
+
end
|
24
|
+
|
25
|
+
should 'create a directory called spec and copy the rspec files' do
|
26
|
+
@script.create_spec
|
27
|
+
@script.copy_rspec_files
|
28
|
+
|
29
|
+
assert File.exists?("#{@app_name}#{File::SEPARATOR}spec#{File::SEPARATOR}spec.opts")
|
30
|
+
assert File.exists?("#{@app_name}#{File::SEPARATOR}spec#{File::SEPARATOR}rcov.opts")
|
31
|
+
assert File.exists?("#{@app_name}#{File::SEPARATOR}spec#{File::SEPARATOR}spec_helper.rb")
|
32
|
+
assert File.exists?("#{@app_name}#{File::SEPARATOR}spec#{File::SEPARATOR}#{@app_name}_spec.rb")
|
33
|
+
|
34
|
+
assert File.open("#{@app_name}#{File::SEPARATOR}spec#{File::SEPARATOR}spec_helper.rb").readline == "require '#{@script.app_name}'\n"
|
35
|
+
assert_not_nil dir_in_app_folder.index("spec")
|
36
|
+
end
|
37
|
+
|
38
|
+
should 'create a directory called views' do
|
39
|
+
@script.create_views
|
40
|
+
assert_not_nil dir_in_app_folder.index("views")
|
41
|
+
end
|
42
|
+
|
43
|
+
should 'create a directory called public' do
|
44
|
+
@script.create_public
|
45
|
+
assert_not_nil dir_in_app_folder.index("public")
|
46
|
+
end
|
47
|
+
|
48
|
+
should 'copy the .autotest file to app folder' do
|
49
|
+
@script.copy_autotest_file
|
50
|
+
assert File.exists?("#{@app_name}#{File::SEPARATOR}.autotest")
|
51
|
+
end
|
52
|
+
|
53
|
+
should 'copy the app file' do
|
54
|
+
@script.copy_app_file
|
55
|
+
assert File.exists?("#{@app_name}#{File::SEPARATOR}#{@app_name}.rb")
|
56
|
+
end
|
57
|
+
|
58
|
+
teardown do
|
59
|
+
FileUtils.rmtree @app_name
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
context "Exceptions" do
|
65
|
+
|
66
|
+
should 'raise an error if there is app_name is empty' do
|
67
|
+
assert_raises(RuntimeError) {Decoct::Dscript.new('')}
|
68
|
+
end
|
69
|
+
|
70
|
+
should 'raise an error if there is app_name is nil' do
|
71
|
+
assert_raises(RuntimeError) {Decoct::Dscript.new(nil)}
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: decoct
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Anuj Dutta
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-11-22 00:00:00 +05:30
|
13
|
+
default_executable: decoct
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rspec
|
17
|
+
type: :runtime
|
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: ZenTest
|
27
|
+
type: :runtime
|
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: redgreen
|
37
|
+
type: :runtime
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "0"
|
44
|
+
version:
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: rcov
|
47
|
+
type: :runtime
|
48
|
+
version_requirement:
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
version:
|
55
|
+
description: Sinatra Rspec project generator
|
56
|
+
email: anuj@andhapp.com
|
57
|
+
executables:
|
58
|
+
- decoct
|
59
|
+
extensions: []
|
60
|
+
|
61
|
+
extra_rdoc_files:
|
62
|
+
- README.markdown
|
63
|
+
files:
|
64
|
+
- README.markdown
|
65
|
+
- Rakefile
|
66
|
+
- VERSION
|
67
|
+
- bin/decoct
|
68
|
+
- lib/decoct.rb
|
69
|
+
- lib/decoct/dconstants.rb
|
70
|
+
- lib/decoct/dmeta.rb
|
71
|
+
- lib/decoct/dscript.rb
|
72
|
+
- lib/templates/.autotest
|
73
|
+
- lib/templates/generic_app.rb
|
74
|
+
- lib/templates/spec/app_spec.rb
|
75
|
+
- lib/templates/spec/rcov.opts
|
76
|
+
- lib/templates/spec/spec.opts
|
77
|
+
- lib/templates/spec/spec_helper.rb
|
78
|
+
- test/decoct/ts_script.rb
|
79
|
+
- test/test_helper.rb
|
80
|
+
has_rdoc: true
|
81
|
+
homepage: http://github.com/andhapp/decoct
|
82
|
+
licenses: []
|
83
|
+
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options:
|
86
|
+
- --charset=UTF-8
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: "0"
|
94
|
+
version:
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: "0"
|
100
|
+
version:
|
101
|
+
requirements: []
|
102
|
+
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 1.3.5
|
105
|
+
signing_key:
|
106
|
+
specification_version: 3
|
107
|
+
summary: Its a simple gem which creates a project structure for sinatra to work with rspec, ZenTest, RedGreen, Rcov
|
108
|
+
test_files:
|
109
|
+
- test/decoct/ts_script.rb
|
110
|
+
- test/test_helper.rb
|