rundoc 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +7 -0
  3. data/CHANGELOG.md +10 -0
  4. data/README.md +219 -96
  5. data/bin/rundoc +4 -68
  6. data/lib/rundoc.rb +1 -0
  7. data/lib/rundoc/cli.rb +84 -0
  8. data/lib/rundoc/code_command.rb +3 -2
  9. data/lib/rundoc/code_command/background/process_spawn.rb +28 -2
  10. data/lib/rundoc/code_command/background/start.rb +1 -0
  11. data/lib/rundoc/code_command/bash/cd.rb +20 -2
  12. data/lib/rundoc/code_command/no_such_command.rb +4 -0
  13. data/lib/rundoc/code_command/rundoc/depend_on.rb +37 -0
  14. data/lib/rundoc/code_command/rundoc/require.rb +41 -0
  15. data/lib/rundoc/code_command/rundoc_command.rb +4 -1
  16. data/lib/rundoc/code_command/website.rb +7 -0
  17. data/lib/rundoc/code_command/website/driver.rb +111 -0
  18. data/lib/rundoc/code_command/website/navigate.rb +29 -0
  19. data/lib/rundoc/code_command/website/screenshot.rb +28 -0
  20. data/lib/rundoc/code_command/website/visit.rb +47 -0
  21. data/lib/rundoc/code_section.rb +13 -4
  22. data/lib/rundoc/parser.rb +4 -3
  23. data/lib/rundoc/peg_parser.rb +1 -1
  24. data/lib/rundoc/version.rb +1 -1
  25. data/rundoc.gemspec +6 -2
  26. data/test/fixtures/build_logs/rundoc.md +56 -0
  27. data/test/fixtures/depend_on/dependency/rundoc.md +5 -0
  28. data/test/fixtures/depend_on/main/rundoc.md +10 -0
  29. data/test/fixtures/java/rundoc.md +9 -0
  30. data/test/fixtures/rails_4/rundoc.md +1 -1
  31. data/test/fixtures/rails_5/rundoc.md +3 -3
  32. data/test/fixtures/{rails_5_beta → rails_6}/rundoc.md +79 -86
  33. data/test/fixtures/require/dependency/rundoc.md +5 -0
  34. data/test/fixtures/require/main/rundoc.md +10 -0
  35. data/test/fixtures/screenshot/rundoc.md +10 -0
  36. data/test/rundoc/peg_parser_test.rb +33 -0
  37. metadata +71 -8
@@ -0,0 +1,29 @@
1
+ class Rundoc::CodeCommand::Website
2
+ class Navigate < Rundoc::CodeCommand
3
+ def initialize(name: )
4
+ @name = name
5
+ @driver = Rundoc::CodeCommand::Website::Driver.find(name)
6
+ end
7
+
8
+ def to_md(env = {})
9
+ ""
10
+ end
11
+
12
+ def call(env = {})
13
+ puts "website.navigate [#{@name}]: #{contents}"
14
+ @driver.safe_eval(contents)
15
+ ""
16
+ end
17
+
18
+ def hidden?
19
+ true
20
+ end
21
+
22
+ def not_hidden?
23
+ !hidden?
24
+ end
25
+ end
26
+ end
27
+
28
+ Rundoc.register_code_command(:"website.nav", Rundoc::CodeCommand::Website::Navigate)
29
+ Rundoc.register_code_command(:"website.navigate", Rundoc::CodeCommand::Website::Navigate)
@@ -0,0 +1,28 @@
1
+ class Rundoc::CodeCommand::Website
2
+ class Screenshot < Rundoc::CodeCommand
3
+ def initialize(name: , upload: false)
4
+ @driver = Rundoc::CodeCommand::Website::Driver.find(name)
5
+ @upload = upload
6
+ end
7
+
8
+ def to_md(env = {})
9
+ ""
10
+ end
11
+
12
+ def call(env = {})
13
+ puts "Taking screenshot: #{@driver.current_url}"
14
+ filename = @driver.screenshot(upload: @upload)
15
+ env[:replace] = "![Screenshot of #{@driver.current_url}](#{filename})"
16
+ ""
17
+ end
18
+
19
+ # def hidden?
20
+ # true
21
+ # end
22
+
23
+ # def not_hidden?
24
+ # !hidden?
25
+ # end
26
+ end
27
+ end
28
+ Rundoc.register_code_command(:"website.screenshot", Rundoc::CodeCommand::Website::Screenshot)
@@ -0,0 +1,47 @@
1
+ class Rundoc::CodeCommand::Website
2
+ class Visit < Rundoc::CodeCommand
3
+ def initialize(name: , url: nil, scroll: nil, height: 720, width: 1024, visible: false)
4
+ @name = name
5
+ @url = url
6
+ @scroll = scroll
7
+ @driver = Driver.new(
8
+ name: name,
9
+ url: url,
10
+ height: height,
11
+ width: width,
12
+ visible: visible
13
+ )
14
+ Driver.add(@name, @driver)
15
+ end
16
+
17
+ def to_md(env = {})
18
+ ""
19
+ end
20
+
21
+ def call(env = {})
22
+ message = String.new("Visting: #{@url}")
23
+ message << "and executing:\n#{contents}" unless contents.nil? || contents.empty?
24
+
25
+ puts message
26
+
27
+ @driver.visit(@url) if @url
28
+ @driver.scroll(@scroll) if @scroll
29
+
30
+
31
+ return "" if contents.nil? || contents.empty?
32
+ @driver.safe_eval(contents)
33
+
34
+ return ""
35
+ end
36
+
37
+ def hidden?
38
+ true
39
+ end
40
+
41
+ def not_hidden?
42
+ !hidden?
43
+ end
44
+ end
45
+ end
46
+
47
+ Rundoc.register_code_command(:"website.visit", Rundoc::CodeCommand::Website::Visit)
@@ -32,6 +32,7 @@ module Rundoc
32
32
  @commands = []
33
33
  @stack = []
34
34
  @keyword = options[:keyword] or raise "keyword is required"
35
+ @document_path = options[:document_path]
35
36
  @fence = match[:fence]
36
37
  @lang = match[:lang]
37
38
  @code = match[:contents]
@@ -42,8 +43,9 @@ module Rundoc
42
43
  result = []
43
44
  env = {}
44
45
  env[:commands] = []
45
- env[:before] = "#{fence}#{lang}"
46
- env[:after] = "#{fence}"
46
+ env[:before] = String.new("#{fence}#{lang}")
47
+ env[:after] = String.new(fence)
48
+ env[:document_path] = @document_path
47
49
 
48
50
  @stack.each do |s|
49
51
  unless s.respond_to?(:call)
@@ -55,7 +57,7 @@ module Rundoc
55
57
  code_output = code_command.call(env) || ""
56
58
  code_line = code_command.to_md(env) || ""
57
59
 
58
- env[:commands] << { object: code_command, output: code_output, command: code_line}
60
+ env[:commands] << { object: code_command, output: code_output, command: code_line }
59
61
 
60
62
  tmp_result = []
61
63
  tmp_result << code_line if code_command.render_command?
@@ -65,10 +67,17 @@ module Rundoc
65
67
  result
66
68
  end
67
69
 
70
+ return env[:replace] if env[:replace]
71
+
68
72
  return "" if hidden?
69
73
 
70
74
  array = [env[:before], result, env[:after]]
71
- return array.flatten.compact.map(&:rstrip).reject(&:empty?).join("\n") << "\n"
75
+ array.flatten!
76
+ array.compact!
77
+ array.map!(&:rstrip)
78
+ array.reject!(&:empty?)
79
+
80
+ return array.join("\n") << "\n"
72
81
  end
73
82
 
74
83
  # all of the commands are hidden
@@ -10,10 +10,11 @@ module Rundoc
10
10
 
11
11
  attr_reader :contents, :keyword, :stack
12
12
 
13
- def initialize(contents, options = {})
13
+ def initialize(contents, keyword: DEFAULT_KEYWORD, document_path: nil)
14
+ @document_path = document_path
14
15
  @contents = contents
15
16
  @original = contents.dup
16
- @keyword = options[:keyword] || DEFAULT_KEYWORD
17
+ @keyword = keyword
17
18
  @stack = []
18
19
  partition
19
20
  end
@@ -42,7 +43,7 @@ module Rundoc
42
43
  @stack << head unless head.empty?
43
44
  unless code.empty?
44
45
  match = code.match(CODEBLOCK_REGEX)
45
- @stack << CodeSection.new(match, keyword: keyword)
46
+ @stack << CodeSection.new(match, keyword: keyword, document_path: @document_path)
46
47
  end
47
48
  @contents = tail
48
49
  end
@@ -119,7 +119,7 @@ module Rundoc
119
119
  (
120
120
  start_command >>
121
121
  visability.as(:cmd_visability) >> spaces? >>
122
- method_call.as(:cmd_method_call) >> newline #>> match(/\z/)
122
+ method_call.as(:cmd_method_call) >> newline.maybe #>> match(/\z/)
123
123
  ).as(:command)
124
124
  }
125
125
 
@@ -1,3 +1,3 @@
1
1
  module Rundoc
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -8,8 +8,8 @@ Gem::Specification.new do |gem|
8
8
  gem.version = Rundoc::VERSION
9
9
  gem.authors = ["Richard Schneeman"]
10
10
  gem.email = ["richard.schneeman+rubygems@gmail.com"]
11
- gem.description = %q{runDOC turns docs to runable code}
12
- gem.summary = %q{runDOC generates runable code from docs}
11
+ gem.description = %q{RunDOC turns docs to runable code}
12
+ gem.summary = %q{RunDOC generates runable code from docs}
13
13
  gem.homepage = "https://github.com/schneems/rundoc"
14
14
  gem.license = "MIT"
15
15
 
@@ -21,6 +21,10 @@ Gem::Specification.new do |gem|
21
21
  gem.add_dependency "thor"
22
22
  gem.add_dependency "repl_runner"
23
23
  gem.add_dependency 'parslet', '~> 1'
24
+ gem.add_dependency 'capybara', '~> 3'
25
+ gem.add_dependency 'selenium-webdriver', '~> 3'
26
+
27
+ gem.add_dependency 'aws-sdk-s3', '~> 1'
24
28
 
25
29
  gem.add_development_dependency "rake"
26
30
  gem.add_development_dependency "mocha"
@@ -0,0 +1,56 @@
1
+ Logs produced while building your application (deploying) are separated from your [runtime logs](https://devcenter.heroku.com/articles/logging#log-retrieval). The build logs for failed and successful deploys are available via the dashboard of the application.
2
+
3
+ ```
4
+ :::-- $ touch Gemfile
5
+ :::-- $ bundle _1.15.2_ install
6
+ :::-- $ git init && git add . && git commit -m first
7
+ :::-- $ heroku create
8
+ :::-- $ git push heroku master
9
+ ```
10
+
11
+ To view your build logs, first visit the dashboard for the application (`https://dashboard.heroku.com/apps/<app-name>`):
12
+
13
+ ```
14
+ :::>> website.visit(name: "dashboard", url: "https://dashboard.heroku.com", visible: true)
15
+
16
+ while current_url != "https://dashboard.heroku.com/apps"
17
+ puts "waiting for successful login: #{current_url}"
18
+ sleep 1
19
+ end
20
+
21
+ git_url = `git config --get remote.heroku.url`.chomp
22
+ app_name = git_url.split("/").last.gsub(".git", "")
23
+ session.visit "https://dashboard.heroku.com/apps/#{app_name}"
24
+ sleep 2
25
+
26
+ email = ENV['HEROKU_EMAIL'] || `heroku auth:whoami`
27
+ session.execute_script %Q{$("span:contains(#{email}").html('developer@example.com')}
28
+
29
+ :::>> website.screenshot(name: "dashboard", upload: "s3")
30
+ ```
31
+
32
+ Next click on the "Activity" tab:
33
+
34
+ ```
35
+ :::>> website.nav(name: "dashboard")
36
+ session.first(:link, "Activity").click
37
+ sleep 2
38
+
39
+ email = ENV['HEROKU_EMAIL'] || `heroku auth:whoami`
40
+ session.execute_script %Q{$("span:contains(#{email}").html('developer@example.com')}
41
+
42
+ :::>> website.screenshot(name: "dashboard", upload: "s3")
43
+ ```
44
+
45
+ From here you can click on "View build log" to see your most recent build:
46
+
47
+ ```
48
+ :::>> website.nav(name: "dashboard")
49
+ session.first(:link, "View build log").click
50
+ sleep 2
51
+
52
+ email = ENV['HEROKU_EMAIL'] || `heroku auth:whoami`
53
+ session.execute_script %Q{$("span:contains(#{email}").html('developer@example.com')}
54
+
55
+ :::>> website.screenshot(name: "dashboard", upload: "s3")
56
+ ```
@@ -0,0 +1,5 @@
1
+ ```
2
+ :::>> $ mkdir foo
3
+ :::>> $ cd foo
4
+ :::>> $ echo "hello" >> hello.txt
5
+ ```
@@ -0,0 +1,10 @@
1
+ # Hello
2
+
3
+ ```
4
+ :::-- rundoc.depend_on "../dependency/rundoc.md"
5
+ ```
6
+
7
+ ```
8
+ :::>> $ ruby -e "raise 'nope' unless File.read('hello.txt').chomp == 'hello'"
9
+ ```
10
+
@@ -0,0 +1,9 @@
1
+
2
+ Hello
3
+
4
+ ```
5
+ :::>- $ git clone https://github.com/heroku/java-getting-started
6
+ :::>- $ cd java-getting-started
7
+ ```
8
+
9
+ world
@@ -56,7 +56,7 @@ Press enter at the prompt to upload your existing `ssh` key or create a new one,
56
56
  You may be starting from an existing app, if so [upgrade to Rails 4](http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#upgrading-from-rails-3-2-to-rails-4-0) before continuing. If not, a vanilla Rails 4 app will serve as a suitable sample app. To build a new app make sure that you're using the Rails 4.x using `$ rails -v`. You can get the new version of rails by running,
57
57
 
58
58
  ```term
59
- :::>> $ gem install rails -v 4.2.9 --no-ri --no-rdoc
59
+ :::>> $ gem install rails -v 4.2.9 --no-document
60
60
  ```
61
61
 
62
62
  Note: There may be a [more recent version of Rails](https://rubygems.org/gems/rails/versions) available, we recommend always running the latest. You may want to [run Rails 5 on Heroku](https://devcenter.heroku.com/articles/getting-started-with-rails5).
@@ -18,7 +18,7 @@ end
18
18
  Ruby on Rails is a popular web framework written in [Ruby](http://www.ruby-lang.org/). This guide covers using Rails 5 on Heroku. For information on running previous versions of Rails on Heroku, see the tutorial for [Rails 4.x](getting-started-with-rails4) or [Rails 3.x](getting-started-with-rails3).
19
19
 
20
20
  ```
21
- :::-- $ ruby -e "exit 1 unless RUBY_VERSION == '2.5.3'"
21
+ :::-- $ ruby -e "exit 1 unless RUBY_VERSION == '2.6.0'"
22
22
  ```
23
23
 
24
24
  For this guide you will need:
@@ -53,7 +53,7 @@ If you are starting with an existing app that uses a previous version of Rails,
53
53
  To create a new app, first make sure that you're using Rails 5.x by running `rails -v`. If necessary, you can get the new version of rails by running the following:
54
54
 
55
55
  ```term
56
- :::>> $ gem install rails --no-ri --no-rdoc
56
+ :::>> $ gem install rails --no-document
57
57
  ```
58
58
 
59
59
  Then create a new app and move into its root directory:
@@ -158,7 +158,7 @@ Rails 5 requires Ruby 2.2.0 or above. Heroku has a recent version of Ruby instal
158
158
  ```ruby
159
159
  :::-- $ sed -i'' -e '/^ruby/d' ./Gemfile
160
160
  :::-> file.append Gemfile#4
161
- ruby "2.5.3"
161
+ ruby "2.6.0"
162
162
  ```
163
163
 
164
164
  You should also be running the same version of Ruby locally. You can check this by running `$ ruby -v`. You can get more information on [specifying your Ruby version on Heroku here](https://devcenter.heroku.com/articles/ruby-versions).
@@ -1,5 +1,5 @@
1
1
  ```
2
- :::- rundoc
2
+ :::-- rundoc
3
3
  email = ENV['HEROKU_EMAIL'] || `heroku auth:whoami`
4
4
 
5
5
  Rundoc.configure do |config|
@@ -7,32 +7,36 @@ Rundoc.configure do |config|
7
7
  config.filter_sensitive(email => "developer@example.com")
8
8
  end
9
9
  ```
10
+
10
11
  <!--
11
12
  rundoc src:
12
- https://github.com/schneems/rundoc/blob/master/test/fixtures/rails_5/rundoc.md
13
+ https://github.com/schneems/rundoc/blob/master/test/fixtures/rails_6/rundoc.md
14
+
15
+ Command:
16
+ $ bin/rundoc build --path test/fixtures/rails_6/rundoc.md
13
17
  -->
14
18
 
15
- Ruby on Rails is a popular web framework written in [Ruby](http://www.ruby-lang.org/). This guide covers using Rails 5 on Heroku. For information about running previous versions of Rails on Heroku, see [Getting Started with Rails 4.x on Heroku](getting-started-with-rails4) or [Getting Started with Rails 3.x on Heroku](getting-started-with-rails3).
19
+ Ruby on Rails is a popular web framework written in [Ruby](http://www.ruby-lang.org/). This guide covers using Rails 6 on Heroku. For information on running previous versions of Rails on Heroku, see the tutorial for [Rails 5.x](getting-started-with-rails5) or [Rails 4.x](getting-started-with-rails4).
20
+
21
+ ```
22
+ :::-- $ ruby -e "exit 1 unless RUBY_VERSION == '2.6.3'"
23
+ ```
16
24
 
17
25
  For this guide you will need:
18
26
 
19
- - Basic Ruby/Rails knowledge.
20
- - A locally installed version of Ruby 2.2.0+, Rubygems, Bundler, and Rails 5+.
21
- - Basic Git knowledge.
27
+ - Basic familiarity with Ruby/Rails and Git
28
+ - A locally installed version of Ruby 2.2.0+, Rubygems, Bundler, and Rails 6+
22
29
  - A Heroku user account: [Signup is free and instant](https://signup.heroku.com/devcenter).
23
30
 
24
- ## Local workstation setup
31
+ ## Local setup
25
32
 
26
- Install the [Heroku Toolbelt](https://toolbelt.heroku.com/) on your local workstation. This ensures that you have access to the [Heroku command-line client](/categories/command-line), Heroku Local, and the Git revision control system. You will also need [Ruby and Rails installed](http://guides.railsgirls.com/install).
33
+ Install the [Heroku CLI](heroku-cli#download-and-install) on your development machine.
27
34
 
28
- Once installed, you'll have access to the `$ heroku` command from your command shell. Log in using the email address and password you used when creating your Heroku account:
29
-
30
-
31
- > callout Note that `$` symbol before commands indicates they should be run on the command line, prompt, or terminal with appropriate permissions. Do not copy the `$` symbol.
35
+ Once installed, the `heroku` command is available from your terminal. Log in using your Heroku account's email address and password:
32
36
 
33
37
  ```term
34
38
  $ heroku login
35
- Enter your Heroku credentials.
39
+ heroku: Enter your Heroku credentials
36
40
  Email: schneems@example.com
37
41
  Password:
38
42
  Could not find an existing public key.
@@ -41,41 +45,31 @@ Generating new SSH public key.
41
45
  Uploading ssh public key /Users/adam/.ssh/id_rsa.pub
42
46
  ```
43
47
 
44
- Press enter at the prompt to upload your existing `ssh` key or create a new one, used for pushing code later on.
45
-
46
- ## Write your app
47
-
48
- > callout To run on Heroku, your app must be configured to use the Postgres database, have all dependencies declared in your `Gemfile`.
48
+ Press Enter at the prompt to upload your existing `ssh` key or create a new one, used for pushing code later on.
49
49
 
50
+ ## Create a new Rails app (or upgrade an existing one)
50
51
 
51
- If you are starting from an existing app, [upgrade to Rails 5](http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#upgrading-from-rails-4-2-to-rails-5-0) before continuing. If not, a vanilla Rails 5 app will serve as a suitable sample app. To build a new app make sure that you're using the Rails 5.x using `$ rails -v`. You can get the new version of rails by running,
52
-
53
- ```
54
- :::- $ git clone https://github.com/rails/rails.git
55
- ```
52
+ To create a new app, first make sure that you're using Rails 6.x by running `rails -v`. If necessary, you can get the new version of rails by running the following:
56
53
 
57
54
  ```term
58
- $ gem install rails --no-ri --no-rdoc
55
+ :::>> $ gem install rails --pre --no-document
59
56
  ```
60
57
 
61
- Then create a new app:
58
+ Then create a new app and move into its root directory:
62
59
 
63
60
  ```term
64
- $ rails new myapp --database=postgresql
65
- :::-> $ ruby rails/railties/exe/rails new myapp --edge --database=postgresql
61
+ :::>- $ rails new myapp --database=postgresql
66
62
  ```
67
63
 
68
64
  Then move into your application directory.
69
65
 
70
66
  ```term
71
- :::> $ cd myapp
67
+ :::>- $ cd myapp
72
68
  ```
73
69
 
74
- > callout If you experience problems or get stuck with this tutorial, your questions may be answered in a later part of this document. If you experience a problem, try reading through the entire document and then go back to your issue. It can also be useful to review your previous steps to ensure they all executed correctly.
75
-
76
- ## Database
70
+ ## Add the pg gem
77
71
 
78
- If you already have an app that was created without specifying `--database=postgresql` you will need to add the `pg` gem to your Rails project. Edit your `Gemfile` and change this line:
72
+ If you're using an existing app that was created without specifying `--database=postgresql`, you need to add the `pg` gem to your Rails project. Edit your `Gemfile` and change this line:
79
73
 
80
74
  ```ruby
81
75
  gem 'sqlite3'
@@ -87,7 +81,7 @@ To this:
87
81
  gem 'pg'
88
82
  ```
89
83
 
90
- > callout We highly recommend using PostgreSQL during development. Maintaining [parity between your development](http://www.12factor.net/dev-prod-parity) and deployment environments prevents subtle bugs from being introduced because of differences between your environments. [Install Postgres locally](https://devcenter.heroku.com/articles/heroku-postgresql#local-setup) now if it is not already on your system.
84
+ > callout We highly recommend using PostgreSQL during development. Maintaining [parity between your development](http://www.12factor.net/dev-prod-parity) and deployment environments prevents subtle bugs from being introduced because of differences between your environments. [Install Postgres locally](heroku-postgresql#local-setup) now if it is not already on your system.
91
85
 
92
86
  Now re-install your dependencies (to generate a new `Gemfile.lock`):
93
87
 
@@ -95,27 +89,25 @@ Now re-install your dependencies (to generate a new `Gemfile.lock`):
95
89
  $ bundle install
96
90
  ```
97
91
 
98
- To get more information on why this change is needed and how to configure your app to run Postgres locally, see [why you cannot use Sqlite3 on Heroku](https://devcenter.heroku.com/articles/sqlite3).
92
+ For more information on why Postgres is recommended instead of Sqlite3, see [why you cannot use Sqlite3 on Heroku](sqlite3).
99
93
 
100
- In addition to using the `pg` gem, you'll also need to ensure the `config/database.yml` is using the `postgresql` adapter.
101
-
102
- The development section of your `config/database.yml` file should look something like this:
94
+ In addition to using the `pg` gem, ensure that your `config/database.yml` file is using the `postgresql` adapter. The development section of your `config/database.yml` file should look something like this:
103
95
 
104
96
  ```term
105
- :::>> $ cat config/database.yml
97
+ :::>> $ cat config/database.yml
106
98
  ```
107
99
 
108
100
  Be careful here. If you omit the `sql` at the end of `postgresql` in the `adapter` section, your application will not work.
109
101
 
110
- ## Welcome page
102
+ ## Create a welcome page
111
103
 
112
- Rails 5 no longer has a static index page in production. When you're using a new app, there will not be a root page in production, so we need to create one. We will first create a controller called `welcome` for our home page to live:
104
+ Rails 6 no longer has a static index page in production by default. When you're using a new app, there will not be a root page in production, so we need to create one. We will first create a controller called `welcome` for our home page to live:
113
105
 
114
106
  ```term
115
- :::> $ rails generate controller welcome
107
+ :::>- $ rails generate controller welcome
116
108
  ```
117
109
 
118
- Next we'll add an index page.
110
+ Next we'll add an index page:
119
111
 
120
112
  ```html
121
113
  :::>> file.write app/views/welcome/index.html.erb
@@ -128,21 +120,23 @@ Next we'll add an index page.
128
120
  Now we need to make Rails route to this action. We'll edit `config/routes.rb` to set the index page to our new method:
129
121
 
130
122
  ```ruby
131
- :::>> file.append config/routes.rb#4
123
+ :::>> file.append config/routes.rb#2
132
124
  root 'welcome#index'
133
125
  ```
134
126
 
135
127
  You can verify that the page is there by running your server:
136
128
 
137
129
  ```term
138
- $ rails server
130
+ :::>> background.start("rails server", name: "server")
131
+ :::-- background.stop(name: "server")
139
132
  ```
140
133
 
141
134
  And visiting [http://localhost:3000](http://localhost:3000) in your browser. If you do not see the page, [use the logs](#view-the-logs) that are output to your server to debug.
142
135
 
143
136
  ## Heroku gems
144
137
 
145
- Previous versions of Rails required you to add a gem to your project [rails_12factor](https://github.com/heroku/rails_12factor) to enable static asset serving and logging on Heroku. If you are deploying a new application this gem is not needed. If you are upgrading an existing application you can remove this gem provided you have the apprpriate configuration in your `config/environments/production.rb` file:
138
+ Previous versions of Rails required you to add a gem to your project [rails_12factor](https://github.com/heroku/rails_12factor) to enable static asset serving and logging on Heroku. If you are deploying a new application, this gem is not needed. If you are upgrading an existing application, you can remove this gem provided you have the apprpriate configuration in your `config/environments/production.rb` file:
139
+
146
140
 
147
141
  ```ruby
148
142
  # config/environments/production.rb
@@ -155,13 +149,15 @@ if ENV["RAILS_LOG_TO_STDOUT"].present?
155
149
  end
156
150
  ```
157
151
 
158
- ## Specify Ruby version in app
152
+ ## Specify your Ruby version
153
+
154
+ Rails 6 requires Ruby 2.2.0 or above. Heroku has a recent version of Ruby installed by default, however you can specify an exact version by using the `ruby` DSL in your `Gemfile`. Depending on your version of Ruby that you are currently running it might look like this:
159
155
 
160
- Rails 5 requires Ruby 2.2.0 or above. Heroku has a recent version of Ruby installed by default, however you can specify an exact version by using the `ruby` DSL in your `Gemfile`.
161
156
 
162
157
  ```ruby
163
- :::>> file.append Gemfile
164
- ruby "2.4.1"
158
+ :::-- $ sed -i'' -e '/^ruby/d' ./Gemfile
159
+ :::-> file.append Gemfile#4
160
+ ruby "2.6.3"
165
161
  ```
166
162
 
167
163
  You should also be running the same version of Ruby locally. You can check this by running `$ ruby -v`. You can get more information on [specifying your Ruby version on Heroku here](https://devcenter.heroku.com/articles/ruby-versions).
@@ -171,11 +167,11 @@ You should also be running the same version of Ruby locally. You can check this
171
167
  Heroku relies on [Git](http://git-scm.com/), a distributed source control management tool, for deploying your project. If your project is not already in Git, first verify that `git` is on your system:
172
168
 
173
169
  ```term
174
- :::> $ git --help
170
+ :::>- $ git --help
175
171
  :::>> | $ head -n 5
176
172
  ```
177
173
 
178
- If you don't see any output or get `command not found` you will need to install it on your system. Verify that the [Heroku toolbelt](https://toolbelt.heroku.com/) is installed.
174
+ If you don't see any output or get `command not found` you need to install Git on your system.
179
175
 
180
176
  Once you've verified that Git works, first make sure you are in your Rails app directory by running `$ ls`:
181
177
 
@@ -188,9 +184,9 @@ The output should look like this:
188
184
  Now run these commands in your Rails app directory to initialize and commit your code to Git:
189
185
 
190
186
  ```term
191
- :::> $ git init
192
- :::> $ git add .
193
- :::> $ git commit -m "init"
187
+ :::>- $ git init
188
+ :::>- $ git add .
189
+ :::>- $ git commit -m "init"
194
190
  ```
195
191
 
196
192
  You can verify everything was committed correctly by running:
@@ -215,7 +211,7 @@ You can verify that the remote was added to your project by running:
215
211
  :::>> $ git config --list | grep heroku
216
212
  ```
217
213
 
218
- If you see `fatal: not in a git directory` then you are likely not in the correct directory. Otherwise you may deploy your code. After you deploy your code, you will need to migrate your database, make sure it is properly scaled, and use logs to debug any issues that come up.
214
+ If you see `fatal: not in a git directory` then you are likely not in the correct directory. Otherwise you can deploy your code. After you deploy your code, you need to migrate your database, make sure it is properly scaled, and use logs to debug any issues that come up.
219
215
 
220
216
  Deploy your code:
221
217
 
@@ -227,13 +223,13 @@ It is always a good idea to check to see if there are any warnings or errors in
227
223
 
228
224
  ## Migrate your database
229
225
 
230
- If you are using the database in your application you need to manually migrate the database by running:
226
+ If you are using the database in your application, you need to manually migrate the database by running:
231
227
 
232
228
  ```term
233
229
  $ heroku run rake db:migrate
234
230
  ```
235
231
 
236
- Any commands after the `heroku run` will be executed on a Heroku [dyno](dynos). You can obtain an interactive shell session by running `$ heroku run bash`.
232
+ Any commands after the `heroku run` are executed on a Heroku [dyno](dynos). You can obtain an interactive shell session by running `$ heroku run bash`.
237
233
 
238
234
  ## Visit your application
239
235
 
@@ -242,7 +238,7 @@ You've deployed your code to Heroku. You can now instruct Heroku to execute a pr
242
238
  Let's ensure we have one dyno running the `web` process type:
243
239
 
244
240
  ```term
245
- :::> $ heroku ps:scale web=1
241
+ :::>- $ heroku ps:scale web=1
246
242
  ```
247
243
 
248
244
  You can check the state of the app's dynos. The `heroku ps` command lists the running dynos of your application:
@@ -263,7 +259,7 @@ You should now see the "Hello World" text we inserted above.
263
259
 
264
260
  Heroku gives you a default web URL for simplicity while you are developing. When you are ready to scale up and use Heroku for production you can add your own [custom domain](https://devcenter.heroku.com/articles/custom-domains).
265
261
 
266
- ## View the logs
262
+ ## View logs
267
263
 
268
264
  If you run into any problems getting your app to perform properly, you will need to check the logs.
269
265
 
@@ -281,11 +277,11 @@ $ heroku logs --tail
281
277
 
282
278
  ## Dyno sleeping and scaling
283
279
 
284
- By default, new applications are deployed to a free dyno. Free apps will "sleep" to conserve resources. You can find more information about this behavior by reading about [free dyno behavior](https://devcenter.heroku.com/articles/free-dyno-hours).
280
+ By default, new applications are deployed to a free dyno. Free apps will "sleep" to conserve resources. You can find more information about this behavior by reading about [free dyno behavior](free-dyno-hours).
285
281
 
286
282
  To avoid dyno sleeping, you can upgrade to a hobby or professional dyno type as described in the [Dyno Types](dyno-types) article. For example, if you migrate your app to a professional dyno, you can easily scale it by running a command telling Heroku to execute a specific number of dynos, each running your web process type.
287
283
 
288
- ## Rails console
284
+ ## Run the Rails console
289
285
 
290
286
  Heroku allows you to run commands in a [one-off dyno](one-off-dynos) - scripts and applications that only need to be executed when needed - using the `heroku run` command. Use this to launch a Rails console process attached to your local terminal for experimenting in your app's environment:
291
287
 
@@ -297,7 +293,7 @@ irb(main):001:0> puts 1+1
297
293
 
298
294
  Another useful command for debugging is `$ heroku run bash` which will spin up a new dyno and give you access to a bash session.
299
295
 
300
- ## Rake
296
+ ## Run Rake commands
301
297
 
302
298
  Rake can be run as an attached process exactly like the console:
303
299
 
@@ -305,9 +301,9 @@ Rake can be run as an attached process exactly like the console:
305
301
  $ heroku run rake db:migrate
306
302
  ```
307
303
 
308
- ## Webserver
304
+ ## Configure your webserver
309
305
 
310
- By default, your app's web process runs `rails server`, which uses Puma in Rails 5. If you are upgrading an app you'll need to add `puma` to your application `Gemfile`:
306
+ By default, your app's web process runs `rails server`, which uses Puma in Rails 6. If you are upgrading an app you'll need to add `puma` to your application `Gemfile`:
311
307
 
312
308
  ```ruby
313
309
  gem 'puma'
@@ -316,14 +312,14 @@ gem 'puma'
316
312
  Then run
317
313
 
318
314
  ```term
319
- :::> $ bundle install
315
+ :::>- $ bundle install
320
316
  ```
321
317
 
322
- Now you are ready to configure your app to use Puma. For this tutorial we will use the default `config/puma.rb` of that ships with Rails 5, but we recommend reading more about configuring your application for maximum performance by [reading the Puma documentation](https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server).
318
+ Now you are ready to configure your app to use Puma. For this tutorial we will use the default `config/puma.rb` of that ships with Rails 6, but we recommend reading more about configuring your application for maximum performance by [reading the Puma documentation](https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server).
323
319
 
324
320
  Finally you will need to tell Heroku how to run your Rails app by creating a `Procfile` in the root of your application directory.
325
321
 
326
- ### Procfile
322
+ ### Create a Procfile
327
323
 
328
324
  Change the command used to launch your web process by creating a file called [Procfile](procfile) and entering this:
329
325
 
@@ -332,11 +328,11 @@ Change the command used to launch your web process by creating a file called [Pr
332
328
  web: bundle exec puma -t 5:5 -p ${PORT:-3000} -e ${RACK_ENV:-development}
333
329
  ```
334
330
 
335
- > Note: The case of `Procfile` matters, the first letter must be uppercase.
331
+ > Note: This file must be named `Procfile` exactly.
336
332
 
337
333
  We recommend generating a Puma config file based on [our Puma documentation](https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server) for maximum performance.
338
334
 
339
- To use the Procfile locally you can use `heroku local`.
335
+ To use the Procfile locally, you can use `heroku local`.
340
336
 
341
337
  In addition to running commands in your `Procfile` `heroku local` can also help you manage environment variables locally through a `.env` file. Set the local `RACK_ENV` to development in your environment and a `PORT` to connect to. Before pushing to Heroku you'll want to test with the `RACK_ENV` set to production since this is the environment your Heroku app will run in.
342
338
 
@@ -350,30 +346,24 @@ In addition to running commands in your `Procfile` `heroku local` can also help
350
346
  You'll also want to add `.env` to your `.gitignore` since this is for local environment setup.
351
347
 
352
348
  ```term
353
- :::> $ echo ".env" >> .gitignore
354
- :::> $ git add .gitignore
355
- :::> $ git commit -m "add .env to .gitignore"
349
+ :::>- $ echo ".env" >> .gitignore
350
+ :::>- $ git add .gitignore
351
+ :::>- $ git commit -m "add .env to .gitignore"
356
352
  ```
357
353
 
358
354
  Test your Procfile locally using Foreman. You can now start your web server by running:
359
355
 
360
356
  ```term
361
- $ heroku local
362
- [OKAY] Loaded ENV .env File as KEY=VALUE Format
363
- 11:06:35 AM web.1 | [18878] Puma starting in cluster mode...
364
- 11:06:35 AM web.1 | [18878] * Version 3.8.2 (ruby 2.4.1-p111), codename: Sassy Salamander
365
- 11:06:35 AM web.1 | [18878] * Min threads: 5, max threads: 5
366
- 11:06:35 AM web.1 | [18878] * Environment: development
367
- 11:06:35 AM web.1 | [18878] * Process workers: 2
368
- 11:06:35 AM web.1 | [18878] * Preloading application
357
+ :::>> background.start("heroku local", name: "local", wait: "Ctrl-C to stop", timeout: 15)
358
+ :::-- background.stop(name: "local")
369
359
  ```
370
360
 
371
361
  Looks good, so press `Ctrl+C` to exit and you can deploy your changes to Heroku:
372
362
 
373
363
  ```term
374
- :::> $ git add .
375
- :::> $ git commit -m "use puma via procfile"
376
- :::> $ git push heroku master
364
+ :::>- $ git add .
365
+ :::>- $ git commit -m "use puma via procfile"
366
+ :::>- $ git push heroku master
377
367
  ```
378
368
 
379
369
  Check `ps`. You'll see that the web process uses your new command specifying Puma as the web server.
@@ -392,7 +382,7 @@ $ heroku logs
392
382
 
393
383
  There are several options for invoking the [Rails asset pipeline](http://guides.rubyonrails.org/asset_pipeline.html) when deploying to Heroku. For general information on the asset pipeline please see the [Rails 3.1+ Asset Pipeline on Heroku Cedar](rails-asset-pipeline) article.
394
384
 
395
- The `config.assets.initialize_on_precompile` option has been removed is and not needed for Rails 5. Also, any failure in asset compilation will now cause the push to fail. For Rails 5 asset pipeline support see the [Ruby Support](https://devcenter.heroku.com/articles/ruby-support#rails-5-x-applications) page.
385
+ The `config.assets.initialize_on_precompile` option has been removed is and not needed for Rails 6. Also, any failure in asset compilation will now cause the push to fail. For Rails 6 asset pipeline support see the [Ruby Support](ruby-support#rails-5-x-applications) page.
396
386
 
397
387
  ## Troubleshooting
398
388
 
@@ -440,6 +430,9 @@ end
440
430
 
441
431
  Confirm it works locally, then push to Heroku.
442
432
 
443
- ## Done
433
+ ## Next steps
434
+
435
+ Congratulations! You have deployed your first Rails 6 application to Heroku. Here's some recommended reading:
444
436
 
445
- You have deployed your first application to Heroku. The next step is to deploy your own application. You can read more about Ruby on Heroku at the [Dev Center](https://devcenter.heroku.com/categories/ruby).
437
+ * Visit the [Ruby support category](/categories/ruby-support) to learn more about using Ruby and Rails on Heroku.
438
+ * The [Deployment category](/categories/deployment) provides a variety of powerful integrations and features to help streamline and simplify your deployments.