sinatra_bootstrap 0.0.1 → 0.1.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/README.md ADDED
@@ -0,0 +1,36 @@
1
+ Sinatra Bootstrap
2
+ =================
3
+
4
+ Get a skeleton [sinatra](http://www.sinatrarb.com/) app up and running before you finish wishing you
5
+ had an idea
6
+
7
+ Install
8
+ -------
9
+
10
+ gem install sinatra_bootstrap
11
+
12
+ Usage
13
+ -----
14
+
15
+ ### Sinatra-only application
16
+
17
+ take_the_stage sinatra
18
+
19
+ Wow, that was easy. `take_the_stage sinatra` will generate a `Gemfile`
20
+ specifying only `gem 'sinatra', '~> 1.3'` as well as a `main.rb` file to
21
+ hold your application.
22
+
23
+ ### Rack application
24
+
25
+ take_the_stage sinatra --rackup
26
+
27
+ The `rackup` variant will also generate a `config.ru` file suitable for
28
+ deploying your application on a Rack-based server.
29
+
30
+ ### Heroku
31
+
32
+ take_the_stage heroku
33
+
34
+ When passed `heroku` sinatra bootstrap will generate a more complete
35
+ `Gemfile` containing [thin](http://code.macournoyer.com/thin/),
36
+ [heroku](https://github.com/heroku/heroku), and [foreman](https://github.com/ddollar/foreman). It also outputs a simple `config.ru` and `Procfile`
@@ -9,20 +9,26 @@ module SinatraBootstrap
9
9
  end
10
10
 
11
11
  desc 'sinatra', 'Installs Gemfile and main.rb'
12
+ method_option :rackup, :type => :boolean, :desc => 'Create a config.ru file', :default => false
12
13
  def sinatra
13
14
  copy_file 'Gemfile-bare', 'Gemfile'
15
+ copy_file 'config.ru' if options[:rackup]
14
16
  copy_file 'main.rb'
15
17
  say 'Simple startup:'
16
18
  say ' bundle install'
17
19
  say ' ruby ./main.rb'
18
20
  end
19
21
 
20
- # desc 'rackup', 'Install sinatra files plus config.ru'
21
- # method_options
22
- # def rackup
23
- # invoke :sinatra
24
- # end
25
-
22
+ desc 'heroku', 'Install base files for running Sinatra on Heroku'
23
+ def heroku
24
+ copy_file 'Gemfile-heroku', 'Gemfile'
25
+ copy_file 'config.ru'
26
+ copy_file 'Procfile'
27
+ copy_file 'main.rb'
28
+ say 'Simple development startup:'
29
+ say ' bundle install'
30
+ say ' foreman start'
31
+ end
26
32
  end
27
33
 
28
34
  end
@@ -0,0 +1,9 @@
1
+ source :rubygems
2
+
3
+ gem 'sinatra', '~> 1.3'
4
+ gem 'thin'
5
+
6
+ group :development do
7
+ gem 'heroku'
8
+ gem 'foreman'
9
+ end
@@ -0,0 +1 @@
1
+ web: bundle exec thin -p $PORT -e $RACK_ENV start
@@ -0,0 +1,2 @@
1
+ require './main'
2
+ run Sinatra::Application
data/spec/spec_helper.rb CHANGED
@@ -4,8 +4,42 @@
4
4
  # loaded once.
5
5
  #
6
6
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+
8
+ require 'simplecov'
9
+ SimpleCov.start do
10
+ add_group 'Libraries', 'lib'
11
+ add_group 'Specs', 'spec'
12
+ end
13
+
14
+ $:.unshift(File.join(File.dirname(__FILE__), '..' 'lib'))
15
+ require 'sinatra_bootstrap'
16
+
17
+ $0 = 'take_the_stage'
18
+ ARGV.clear
19
+
20
+
7
21
  RSpec.configure do |config|
8
22
  config.treat_symbols_as_metadata_keys_with_true_values = true
9
23
  config.run_all_when_everything_filtered = true
10
24
  config.filter_run :focus
25
+
26
+ def capture(stream)
27
+ begin
28
+ stream = stream.to_s
29
+ eval "$#{stream} = StringIO.new"
30
+ yield
31
+ result = eval("$#{stream}").string
32
+ ensure
33
+ eval "$#{stream} = #{stream.upcase}"
34
+ end
35
+
36
+ result
37
+ end
38
+
39
+ def in_tmpdir
40
+ Dir.mktmpdir do |tmp|
41
+ Dir.chdir(tmp) { yield }
42
+ end
43
+ end
44
+
11
45
  end
@@ -0,0 +1,121 @@
1
+ require 'spec_helper'
2
+
3
+ describe SinatraBootstrap::Stage do
4
+
5
+ describe "#sinatra" do
6
+ let(:sinatra) { described_class.start ['sinatra'] }
7
+
8
+ it "outputs the instructions for starting sinatra" do
9
+ Thor::Actions::CreateFile.stub(:new).and_return stub :invoke! => true
10
+ stdout = capture(:stdout) { sinatra }
11
+ stdout.should =~ /Simple startup:/
12
+ stdout.should =~ / bundle install/
13
+ stdout.should =~ / ruby \.\/main.rb/
14
+ end
15
+
16
+ it "creates a Gemfile" do
17
+ in_tmpdir do
18
+ capture(:stdout) { sinatra }
19
+ File.exists?('Gemfile').should be_true
20
+ end
21
+ end
22
+
23
+ it "Gemfile has only sinatra in it" do
24
+ in_tmpdir do
25
+ capture(:stdout) { sinatra }
26
+ gemfile = File.read 'Gemfile'
27
+ gemfile.should =~ /^gem 'sinatra', '~> 1.3'$/
28
+ gemfile.lines.map do |line|
29
+ line if line =~ /^gem/
30
+ end.compact.length.should == 1
31
+ end
32
+ end
33
+
34
+ it "copies main.rb" do
35
+ in_tmpdir do
36
+ capture(:stdout) { sinatra }
37
+ File.exists?('main.rb').should be_true
38
+ end
39
+ end
40
+
41
+ it "does not copy config.ru" do
42
+ in_tmpdir do
43
+ capture(:stdout) { sinatra }
44
+ File.exists?('config.ru').should be_false
45
+ end
46
+ end
47
+
48
+ context "with --rackup" do
49
+ let(:sinatra) { described_class.start ['sinatra', '--rackup'] }
50
+
51
+ it "copies config.ru" do
52
+ in_tmpdir do
53
+ capture(:stdout) { sinatra }
54
+ File.exists?('config.ru').should be_true
55
+ end
56
+ end
57
+ end
58
+
59
+ context "with --no-rackup" do
60
+ let(:sinatra) { described_class.start ['sinatra', '--no-rackup'] }
61
+
62
+ it "does not copy config.ru" do
63
+ in_tmpdir do
64
+ capture(:stdout) { sinatra }
65
+ File.exists?('config.ru').should be_false
66
+ end
67
+ end
68
+ end
69
+ end
70
+
71
+ describe "#heroku" do
72
+ let(:sinatra) { described_class.start ['heroku'] }
73
+
74
+ it "outputs the instructions for starting foreman" do
75
+ Thor::Actions::CreateFile.stub(:new).and_return stub :invoke! => true
76
+ stdout = capture(:stdout) { sinatra }
77
+ stdout.should =~ /Simple development startup:/
78
+ stdout.should =~ / bundle install/
79
+ stdout.should =~ / foreman start/
80
+ end
81
+
82
+ it "creates a Gemfile" do
83
+ in_tmpdir do
84
+ capture(:stdout) { sinatra }
85
+ File.exists?('Gemfile').should be_true
86
+ end
87
+ end
88
+
89
+ it "Gemfile has sinatra, thin, heroku, and foreman in it" do
90
+ in_tmpdir do
91
+ capture(:stdout) { sinatra }
92
+ gemfile = File.read 'Gemfile'
93
+ gemfile.should =~ /^gem 'sinatra', '~> 1.3'$/
94
+ gemfile.should =~ /^gem 'thin'$/
95
+ gemfile.should =~ /^ gem 'heroku'$/
96
+ gemfile.should =~ /^ gem 'foreman'$/
97
+ end
98
+ end
99
+
100
+ it "copies main.rb" do
101
+ in_tmpdir do
102
+ capture(:stdout) { sinatra }
103
+ File.exists?('main.rb').should be_true
104
+ end
105
+ end
106
+
107
+ it "copies config.ru" do
108
+ in_tmpdir do
109
+ capture(:stdout) { sinatra }
110
+ File.exists?('config.ru').should be_true
111
+ end
112
+ end
113
+
114
+ it "copies Procfile" do
115
+ in_tmpdir do
116
+ capture(:stdout) { sinatra }
117
+ File.exists?('Procfile').should be_true
118
+ end
119
+ end
120
+ end
121
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra_bootstrap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-21 00:00:00.000000000 Z
12
+ date: 2012-03-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
16
- requirement: &70309235764020 !ruby/object:Gem::Requirement
16
+ requirement: &70305607699660 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0.14'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70309235764020
24
+ version_requirements: *70305607699660
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &70309235763520 !ruby/object:Gem::Requirement
27
+ requirement: &70305607698320 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0.9'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70309235763520
35
+ version_requirements: *70305607698320
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &70309235763060 !ruby/object:Gem::Requirement
38
+ requirement: &70305607697240 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,21 @@ dependencies:
43
43
  version: '2.9'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70309235763060
46
+ version_requirements: *70305607697240
47
+ - !ruby/object:Gem::Dependency
48
+ name: simplecov
49
+ requirement: &70305607696720 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '0.6'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70305607696720
47
58
  - !ruby/object:Gem::Dependency
48
59
  name: bundler
49
- requirement: &70309235762600 !ruby/object:Gem::Requirement
60
+ requirement: &70305607696160 !ruby/object:Gem::Requirement
50
61
  none: false
51
62
  requirements:
52
63
  - - ~>
@@ -54,7 +65,7 @@ dependencies:
54
65
  version: '1.0'
55
66
  type: :development
56
67
  prerelease: false
57
- version_requirements: *70309235762600
68
+ version_requirements: *70305607696160
58
69
  description: Quick Sinatra app setup
59
70
  email: ryan@coshx.com
60
71
  executables:
@@ -65,8 +76,13 @@ files:
65
76
  - lib/sinatra_bootstrap.rb
66
77
  - lib/sinatra_bootstrap/stage.rb
67
78
  - lib/sinatra_bootstrap/templates/Gemfile-bare
79
+ - lib/sinatra_bootstrap/templates/Gemfile-heroku
80
+ - lib/sinatra_bootstrap/templates/Procfile
81
+ - lib/sinatra_bootstrap/templates/config.ru
68
82
  - lib/sinatra_bootstrap/templates/main.rb
83
+ - README.md
69
84
  - spec/spec_helper.rb
85
+ - spec/stage_spec.rb
70
86
  - bin/take_the_stage
71
87
  homepage: http://github.com/rahearn/sinatra_bootstrap
72
88
  licenses:
@@ -95,3 +111,4 @@ specification_version: 3
95
111
  summary: sinatra_bootstrap
96
112
  test_files:
97
113
  - spec/spec_helper.rb
114
+ - spec/stage_spec.rb