rundoc 1.1.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/check_changelog.yml +16 -7
- data/.github/workflows/ci.yml +48 -0
- data/.standard.yml +6 -0
- data/CHANGELOG.md +12 -0
- data/Gemfile +1 -1
- data/README.md +98 -5
- data/Rakefile +9 -10
- data/lib/rundoc/cli.rb +15 -17
- data/lib/rundoc/code_command/background/log/clear.rb +1 -1
- data/lib/rundoc/code_command/background/log/read.rb +1 -1
- data/lib/rundoc/code_command/background/process_spawn.rb +8 -9
- data/lib/rundoc/code_command/background/start.rb +7 -7
- data/lib/rundoc/code_command/background/stop.rb +1 -1
- data/lib/rundoc/code_command/background/wait.rb +2 -2
- data/lib/rundoc/code_command/background.rb +6 -6
- data/lib/rundoc/code_command/bash/cd.rb +6 -7
- data/lib/rundoc/code_command/bash.rb +12 -13
- data/lib/rundoc/code_command/file_command/append.rb +12 -16
- data/lib/rundoc/code_command/file_command/remove.rb +6 -9
- data/lib/rundoc/code_command/no_such_command.rb +0 -1
- data/lib/rundoc/code_command/pipe.rb +2 -5
- data/lib/rundoc/code_command/print/erb.rb +48 -0
- data/lib/rundoc/code_command/print/text.rb +33 -0
- data/lib/rundoc/code_command/raw.rb +1 -1
- data/lib/rundoc/code_command/rundoc/depend_on.rb +0 -1
- data/lib/rundoc/code_command/rundoc/require.rb +2 -3
- data/lib/rundoc/code_command/rundoc_command.rb +3 -4
- data/lib/rundoc/code_command/website/driver.rb +17 -17
- data/lib/rundoc/code_command/website/navigate.rb +2 -2
- data/lib/rundoc/code_command/website/screenshot.rb +1 -1
- data/lib/rundoc/code_command/website/visit.rb +4 -5
- data/lib/rundoc/code_command/website.rb +4 -4
- data/lib/rundoc/code_command/write.rb +10 -11
- data/lib/rundoc/code_command.rb +28 -17
- data/lib/rundoc/code_section.rb +42 -25
- data/lib/rundoc/parser.rb +17 -19
- data/lib/rundoc/peg_parser.rb +57 -59
- data/lib/rundoc/version.rb +1 -1
- data/lib/rundoc.rb +10 -14
- data/rundoc.gemspec +19 -21
- data/test/fixtures/rails_4/rundoc.md +100 -33
- data/test/fixtures/rails_5/rundoc.md +77 -14
- data/test/fixtures/rails_6/rundoc.md +231 -167
- data/test/fixtures/rails_7/rundoc.md +477 -0
- data/test/integration/print_test.rb +194 -0
- data/test/rundoc/code_commands/append_file_test.rb +5 -8
- data/test/rundoc/code_commands/background_test.rb +3 -6
- data/test/rundoc/code_commands/bash_test.rb +12 -7
- data/test/rundoc/code_commands/pipe_test.rb +9 -9
- data/test/rundoc/code_commands/print_test.rb +94 -0
- data/test/rundoc/code_commands/remove_contents_test.rb +4 -5
- data/test/rundoc/code_section_test.rb +50 -56
- data/test/rundoc/parser_test.rb +28 -61
- data/test/rundoc/peg_parser_test.rb +49 -53
- data/test/rundoc/regex_test.rb +120 -127
- data/test/rundoc/test_parse_java.rb +1 -3
- data/test/test_helper.rb +4 -6
- metadata +39 -42
- data/.travis.yml +0 -8
- data/lib/rundoc/code_command/repl.rb +0 -37
@@ -0,0 +1,477 @@
|
|
1
|
+
```
|
2
|
+
:::-- rundoc
|
3
|
+
email = ENV['HEROKU_EMAIL'] || `heroku auth:whoami`
|
4
|
+
|
5
|
+
Rundoc.configure do |config|
|
6
|
+
config.project_root = "myapp"
|
7
|
+
config.filter_sensitive(email => "developer@example.com")
|
8
|
+
config.filter_sensitive(Dir.pwd => ".")
|
9
|
+
end
|
10
|
+
```
|
11
|
+
|
12
|
+
<!--
|
13
|
+
rundoc src:
|
14
|
+
https://github.com/schneems/rundoc/blob/main/test/fixtures/rails_7/rundoc.md
|
15
|
+
|
16
|
+
Command:
|
17
|
+
$ bin/rundoc build --path test/fixtures/rails_7/rundoc.md
|
18
|
+
-->
|
19
|
+
|
20
|
+
Ruby on Rails is a popular web framework written in [Ruby](http://www.ruby-lang.org/). This guide covers using Rails 7 on Heroku. For information on running previous versions of Rails on Heroku, see the tutorial for [Rails 6.x](getting-started-with-rails6) or [Rails 5.x](getting-started-with-rails5).
|
21
|
+
|
22
|
+
```
|
23
|
+
:::-- $ ruby -e "exit 1 unless RUBY_VERSION == '3.2.4'"
|
24
|
+
```
|
25
|
+
|
26
|
+
The tutorial assumes that you have:
|
27
|
+
|
28
|
+
- Basic familiarity with Ruby, Ruby on Rails, and Git
|
29
|
+
- A locally installed version of Ruby 3.0.0+, Rubygems, Bundler, and Rails 7+
|
30
|
+
- A locally installed version of the [Heroku CLI](heroku-cli#install-the-heroku-cli)
|
31
|
+
- A [verified Heroku Account](https://devcenter.heroku.com/articles/account-verification)
|
32
|
+
- A subscription to the [Eco dynos plan](eco-dyno-hours) (recommended)
|
33
|
+
|
34
|
+
>note
|
35
|
+
>Using dynos and databases to complete this tutorial counts towards your usage. We recommend using our [low-cost plans](https://blog.heroku.com/new-low-cost-plans) to complete this tutorial. Eligible students can apply for platform credits through our new [Heroku for GitHub Students program](https://blog.heroku.com/github-student-developer-program).
|
36
|
+
|
37
|
+
## Local Setup
|
38
|
+
|
39
|
+
After installing the [Heroku CLI](heroku-cli#install-the-heroku-cli), log in through your terminal:
|
40
|
+
|
41
|
+
```term
|
42
|
+
$ heroku login
|
43
|
+
heroku: Press any key to open up the browser to login or q to exit
|
44
|
+
› Warning: If browser does not open, visit
|
45
|
+
› https://cli-auth.heroku.com/auth/browser/***
|
46
|
+
heroku: Waiting for login...
|
47
|
+
Logging in... done
|
48
|
+
Logged in as developer@example.com
|
49
|
+
```
|
50
|
+
|
51
|
+
This command opens your web browser to the Heroku login page. If your browser is already logged in to Heroku, click the **`Log in`** button on the page.
|
52
|
+
|
53
|
+
This authentication is required for the `heroku` and `git` commands to work correctly.
|
54
|
+
|
55
|
+
>note
|
56
|
+
> If you're behind a firewall that uses a proxy to connect with external HTTP/HTTPS services, [set the `HTTP_PROXY` or `HTTPS_PROXY` environment variables](articles/using-the-cli#using-an-http-proxy) in your local development environment before running the `heroku` command.
|
57
|
+
|
58
|
+
## Create a New or Upgrade an Existing Rails App
|
59
|
+
|
60
|
+
Ensure you have Rails 7 installed by running `rails -v` before creating an app. If necessary, install Rails 7 with `gem install`:
|
61
|
+
|
62
|
+
```term
|
63
|
+
:::>> $ gem install rails --no-document
|
64
|
+
```
|
65
|
+
|
66
|
+
Create a Rails app:
|
67
|
+
|
68
|
+
```term
|
69
|
+
:::>- $ rails new myapp --database=postgresql
|
70
|
+
```
|
71
|
+
|
72
|
+
Move into the application directory and add the `x86_64-linux` and `ruby` platforms to `Gemfile.lock`.
|
73
|
+
|
74
|
+
```term
|
75
|
+
:::>- $ cd myapp
|
76
|
+
:::>> $ bundle lock --add-platform x86_64-linux --add-platform ruby
|
77
|
+
:::-- $ bundle install
|
78
|
+
```
|
79
|
+
|
80
|
+
<!-- The `bundle install` after `bundle lock` can be removed after https://github.com/rails/rails/issues/48278 is closed -->
|
81
|
+
|
82
|
+
Create a local database:
|
83
|
+
|
84
|
+
```term
|
85
|
+
:::>> $ bin/rails db:create
|
86
|
+
```
|
87
|
+
|
88
|
+
## Add the pg Gem
|
89
|
+
|
90
|
+
For new or existing apps where `--database=postgresql` isn’t defined, confirm the `sqlite3` gem doesn’t exist in the `Gemfile`. Add the `pg` gem in its place.
|
91
|
+
|
92
|
+
Within the `Gemfile` remove:
|
93
|
+
|
94
|
+
```ruby
|
95
|
+
gem 'sqlite3'
|
96
|
+
```
|
97
|
+
|
98
|
+
Replace it with:
|
99
|
+
|
100
|
+
```ruby
|
101
|
+
gem 'pg'
|
102
|
+
```
|
103
|
+
|
104
|
+
> callout
|
105
|
+
>Heroku highly recommends using PostgreSQL locally during development. Maintaining [parity between development](http://www.12factor.net/dev-prod-parity) and deployment environments prevents introducing subtle bugs due to the differences in environments.
|
106
|
+
>
|
107
|
+
> [Install Postgres locally](heroku-postgresql#local-setup). For more information on why Postgres is recommended instead of Sqlite3, see [why Sqlite3 is not compatible with Heroku](sqlite3).
|
108
|
+
|
109
|
+
With the `Gemfile` updated, reinstall the dependencies:
|
110
|
+
|
111
|
+
```ruby
|
112
|
+
$ bundle install
|
113
|
+
```
|
114
|
+
|
115
|
+
The installation also updates `Gemfile.lock` with the changes.
|
116
|
+
|
117
|
+
In addition to the `pg` gem, ensure that `config/database.yml` defines the `postgresql` adapter. The development section of `config/database.yml` file looks something like this:
|
118
|
+
|
119
|
+
```term
|
120
|
+
:::>> $ cat config/database.yml
|
121
|
+
```
|
122
|
+
|
123
|
+
Be careful here. If the value of `adapter` is `postgres` and not `postgresql`, the application won’t work.
|
124
|
+
|
125
|
+
## Create a Welcome Page
|
126
|
+
|
127
|
+
Rails 7 no longer has a static index page in production by default. Apps upgraded to Rails 7 keep their existing page configurations, but new Rails 7 apps don't automatically generate a welcome page. Create a `welcome` controller to hold the homepage:
|
128
|
+
|
129
|
+
```term
|
130
|
+
:::>- $ rails generate controller welcome
|
131
|
+
```
|
132
|
+
|
133
|
+
Create `app/views/welcome/index.html.erb` and add the following code:
|
134
|
+
|
135
|
+
```html
|
136
|
+
:::-> file.write app/views/welcome/index.html.erb
|
137
|
+
<h2>Hello World</h2>
|
138
|
+
<p>
|
139
|
+
The time is now: <%= Time.now %>
|
140
|
+
</p>
|
141
|
+
```
|
142
|
+
|
143
|
+
With a welcome page created, create a route to map to this action.
|
144
|
+
|
145
|
+
```ruby
|
146
|
+
:::>> file.append config/routes.rb#2
|
147
|
+
root 'welcome#index'
|
148
|
+
```
|
149
|
+
|
150
|
+
Verify the page is present by starting the Rails web server:
|
151
|
+
|
152
|
+
```term
|
153
|
+
:::>> background.start("rails server", name: "server")
|
154
|
+
:::-- background.stop(name: "server")
|
155
|
+
```
|
156
|
+
|
157
|
+
Visit [http://localhost:3000](http://localhost:3000) in a browser. If the page doesn’t display, [reference the logs](#view-application-logs) to debug the error. Rails outputs logs in the same terminal where `rails server` was started.
|
158
|
+
|
159
|
+
## Specify the Ruby Version
|
160
|
+
|
161
|
+
Rails 7 requires Ruby 2.7.0 or above. Heroku installs a recent version of Ruby by default. Specify an exact version with the `ruby` DSL in `Gemfile`. For example:
|
162
|
+
|
163
|
+
```ruby
|
164
|
+
:::-- $ sed -i'' -e '/^ruby/d' ./Gemfile
|
165
|
+
:::-> file.append Gemfile#4
|
166
|
+
ruby "3.2.4"
|
167
|
+
```
|
168
|
+
|
169
|
+
Always use the same version of Ruby locally. Confirm the local version of ruby with `ruby -v`. Refer to the [Ruby Versions](ruby-versions) article for more details on defining a specific ruby version.
|
170
|
+
|
171
|
+
## Create a Procfile
|
172
|
+
|
173
|
+
Use a [Procfile](procfile), a text file in the root directory of your application, to explicitly declare what command to execute to start your app.
|
174
|
+
|
175
|
+
This Procfile declares a single process type, `web`, and the command needed to run it. The name `web` is important here. It declares that this process type is attached to Heroku's [HTTP routing](http-routing) stack and receives web traffic when deployed.
|
176
|
+
|
177
|
+
By default, a Rails app’s web process runs `rails server`, which uses Puma in Rails 7. When you deploy a Rails 7 application without a `Procfile`, this command executes. However, we recommend explicitly declaring how to boot your server process via a `Procfile`. For example:
|
178
|
+
|
179
|
+
```
|
180
|
+
:::-> file.write Procfile
|
181
|
+
web: bundle exec puma -C config/puma.rb
|
182
|
+
```
|
183
|
+
|
184
|
+
>note
|
185
|
+
>The `Procfile` filename is case sensitive. There is no file extension.
|
186
|
+
|
187
|
+
If `config/puma.rb` doesn’t exist, create one using [Heroku’s Puma documentation](https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server) for maximum performance.
|
188
|
+
|
189
|
+
A Procfile can contain additional process types. For example, you can declare a [background worker process](background-jobs-queueing#process-model) that processes items off a queue.
|
190
|
+
|
191
|
+
## Store The App in Git
|
192
|
+
|
193
|
+
Heroku relies on [Git](http://git-scm.com/), a distributed source control management tool, for deploying applications. If the application is not already in Git, first verify that `git` is on the system with `git --help`:
|
194
|
+
|
195
|
+
```term
|
196
|
+
:::>- $ git --help
|
197
|
+
:::>> | $ head -n 5
|
198
|
+
```
|
199
|
+
|
200
|
+
If the command produces no output or `command not found`, [install Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git).
|
201
|
+
|
202
|
+
Navigate to the root directory of the Rails app. Use the `ls` command to see its contents:
|
203
|
+
|
204
|
+
```term
|
205
|
+
:::>> $ ls
|
206
|
+
```
|
207
|
+
|
208
|
+
Within the Rails app directly, initialize a local empty Git repository and commit the app’s code:
|
209
|
+
|
210
|
+
```term
|
211
|
+
:::>- $ git init
|
212
|
+
:::>- $ git add .
|
213
|
+
:::>- $ git commit -m "init"
|
214
|
+
```
|
215
|
+
|
216
|
+
Verify everything committed correctly with `git status`:
|
217
|
+
|
218
|
+
```term
|
219
|
+
:::>> $ git status
|
220
|
+
```
|
221
|
+
|
222
|
+
With the application committed to Git, it's ready to deploy to Heroku.
|
223
|
+
|
224
|
+
## Create a Heroku App
|
225
|
+
|
226
|
+
>warning
|
227
|
+
>Using a dyno and a database to complete this tutorial counts towards your usage. [Delete your app](https://devcenter.heroku.com/articles/heroku-cli-commands#heroku-apps-destroy), and [database](https://devcenter.heroku.com/articles/heroku-postgresql#removing-the-add-on) as soon as you're done to control costs.
|
228
|
+
|
229
|
+
To create an app on Heroku, use the Heroku CLI Inside the Rails app’s root directory:
|
230
|
+
|
231
|
+
```term
|
232
|
+
:::>> $ heroku apps:create
|
233
|
+
```
|
234
|
+
|
235
|
+
When you create an app, a git remote called `heroku` is also created and associated with your local git repository. Git remotes are versions of your repository that live on other servers. You deploy your app by pushing its code to that special Heroku-hosted remote associated with your app. Verify the remote is set with `git config`:
|
236
|
+
|
237
|
+
```term
|
238
|
+
:::>> $ git config --list --local | grep heroku
|
239
|
+
```
|
240
|
+
|
241
|
+
If the current directory is incorrect or Git isn't [initialized](#store-the-app-in-git), Git returns `fatal: not in a git directory`. If Git returns a list of remotes, it's ready to deploy.
|
242
|
+
|
243
|
+
>note
|
244
|
+
>Following changes in the industry, Heroku [updated the default branch name](https://devcenter.heroku.com/changelog-items/1829) to `main`. If the project uses `master` as its default branch name, use `git push heroku master`.
|
245
|
+
|
246
|
+
## Provision a Database
|
247
|
+
|
248
|
+
Provision a [Heroku Postgres](https://devcenter.heroku.com/articles/heroku-postgresql) database, one of the add-ons available through the [Elements Marketplace](https://www.heroku.com/elements/addons). Add-ons are cloud services that provide out-of-the-box additional services for your application, such as logging, monitoring, databases, and more.
|
249
|
+
|
250
|
+
>note
|
251
|
+
>A `mini` Postgres size costs [$5 a month, prorated to the minute](https://elements.heroku.com/addons/heroku-postgresql). At the end of this tutorial, we prompt you to [delete your database](https://devcenter.heroku.com/articles/heroku-postgresql#removing-the-add-on) to minimize costs.
|
252
|
+
|
253
|
+
```term
|
254
|
+
:::>> $ heroku addons:create heroku-postgresql:mini
|
255
|
+
```
|
256
|
+
|
257
|
+
Your Heroku app can now access this Postgres database. The `DATABASE_URL` environment variable stores your credentials, which Rails connects to by convention.
|
258
|
+
|
259
|
+
## Deploy the App to Heroku
|
260
|
+
|
261
|
+
>warning
|
262
|
+
>Using a dyno to complete this tutorial counts towards your usage. [Delete your app](https://devcenter.heroku.com/articles/heroku-cli-commands#heroku-apps-destroy) as soon as you're done to control costs.
|
263
|
+
|
264
|
+
Deploy your code. This command pushes the `main` branch of the sample repo to your `heroku` remote, which then deploys to Heroku:
|
265
|
+
|
266
|
+
```term
|
267
|
+
:::>> $ git push heroku main
|
268
|
+
```
|
269
|
+
|
270
|
+
If the output displays warnings or error messages, check the output and make adjustments.
|
271
|
+
|
272
|
+
After a successful deployment, complete these tasks as necessary:
|
273
|
+
|
274
|
+
* Database migrations
|
275
|
+
* Scale your dynos
|
276
|
+
* Check the app’s logs if issues arise
|
277
|
+
|
278
|
+
## Migrate The Database
|
279
|
+
|
280
|
+
If you're using a database in your application, trigger a migration by using the Heroku CLI to start a one-off [dyno](dynos). You can run commands, typically scripts and applications that are part of your app, in one-off dynos using the `heroku run` command. You can trigger a database migration with this command:
|
281
|
+
|
282
|
+
```term
|
283
|
+
$ heroku run rake db:migrate
|
284
|
+
```
|
285
|
+
|
286
|
+
To use an interactive shell session instead, you can execute `heroku run bash`.
|
287
|
+
|
288
|
+
## Scale and Access the Application
|
289
|
+
|
290
|
+
Heroku runs application code using defined processes and [process types](procfile). New applications don't a process type active by default. The following command scales your app up to one dyno, running the `web` process:
|
291
|
+
|
292
|
+
```term
|
293
|
+
:::>- $ heroku ps:scale web=1
|
294
|
+
```
|
295
|
+
|
296
|
+
Use the Heroku CLI’s `ps` command to display the state of all app dynos in the terminal:
|
297
|
+
|
298
|
+
```term
|
299
|
+
:::>> $ heroku ps
|
300
|
+
```
|
301
|
+
|
302
|
+
In this example, a single `web` process is running.
|
303
|
+
|
304
|
+
By default, apps use Eco dynos if you're subscribed to [Eco](eco-dyno-hours). Otherwise, it defaults to Basic dynos. The Eco dynos plan is shared across all Eco dynos in your account and is recommended if you plan on deploying many small apps to Heroku. Eco dynos sleep if they don't receive any traffic for half an hour. This sleep behavior causes a few seconds delay for the first request upon waking. Eco dynos consume from a monthly, account-level quota of [eco dyno hours](eco-dyno-hours). As long as you haven't exhausted the quota, your apps can continue to run.
|
305
|
+
|
306
|
+
To avoid dyno sleeping, upgrade to a Basic or higher dyno type as described in the [Dyno Types](dyno-types) article. Upgrading to at least Standard dynos also allows you to scale up to multiple dynos per process type.
|
307
|
+
|
308
|
+
To launch the app in the browser, run `heroku open`:
|
309
|
+
|
310
|
+
```term
|
311
|
+
:::>> $ heroku open
|
312
|
+
```
|
313
|
+
|
314
|
+
The browser displays the “Hello World” text. If it doesn't, or there's an error, [review and confirm the welcome page contents](#create-a-welcome-page).
|
315
|
+
|
316
|
+
Heroku provides a [default web URL](app-names-and-subdomains) for every application during development. When the application is ready for production, add a [custom domain](https://devcenter.heroku.com/articles/custom-domains).
|
317
|
+
|
318
|
+
## View Application Logs
|
319
|
+
|
320
|
+
The app logs are a valuable tool if the app is not performing correctly or generating errors.
|
321
|
+
|
322
|
+
View information about a running app using the Heroku CLI [logging command](logging), `heroku logs`. Here's example output:
|
323
|
+
|
324
|
+
```term
|
325
|
+
:::>> $ heroku logs
|
326
|
+
```
|
327
|
+
|
328
|
+
Append `-t`/`--tail` to the command to see a full, live stream of the app’s logs:
|
329
|
+
|
330
|
+
```term
|
331
|
+
$ heroku logs --tail
|
332
|
+
```
|
333
|
+
|
334
|
+
By default, Heroku stores 1500 lines of logs from your application, but the full log stream is available as a service. Several [add-on providers](https://elements.heroku.com/addons/#logging) have logging services that provide things such as log persistence, search, and email and SMS alerts.
|
335
|
+
|
336
|
+
## Optional Steps
|
337
|
+
|
338
|
+
### Use The Rails Console
|
339
|
+
|
340
|
+
Use the Heroku CLI `run` command to trigger [one-off dynos](one-off-dynos) to run scripts and applications only when necessary. Use the command to launch a Rails console process attached to the local terminal for experimenting in the app's environment:
|
341
|
+
|
342
|
+
```term
|
343
|
+
$ heroku run rails console
|
344
|
+
irb(main):001:0> puts 1+1
|
345
|
+
2
|
346
|
+
```
|
347
|
+
|
348
|
+
The `run bash` Heroku CLI command is also helpful for debugging. The command starts a new one-off dyno with an interactive bash session.
|
349
|
+
|
350
|
+
### Run Rake Commands
|
351
|
+
|
352
|
+
Run `rake` commands, such as `db:migrate`, using the `run` command exactly like the Rails console:
|
353
|
+
|
354
|
+
```term
|
355
|
+
$ heroku run rake db:migrate
|
356
|
+
```
|
357
|
+
|
358
|
+
### Use a Procfile locally
|
359
|
+
|
360
|
+
To use the `Procfile` locally, use the `heroku local` CLI command.
|
361
|
+
|
362
|
+
In addition to running commands in the `Procfile`, the `heroku local` command can also manage environment variables locally through a `.env` file. Set `RACK_ENV` to `development` for the local environment and the `PORT` for Puma.
|
363
|
+
|
364
|
+
```term
|
365
|
+
:::>> $ echo "RACK_ENV=development" >>.env
|
366
|
+
:::>> $ echo "PORT=3000" >> .env
|
367
|
+
```
|
368
|
+
|
369
|
+
>note
|
370
|
+
> Another alternative to using environment variables locally with a `.env` file is the [dotenv](https://github.com/bkeepers/dotenv) gem.
|
371
|
+
|
372
|
+
Add `.env` to `.gitignore` as these variables are for local environment setup only.
|
373
|
+
|
374
|
+
```term
|
375
|
+
:::>- $ echo ".env" >> .gitignore
|
376
|
+
:::>- $ git add .gitignore
|
377
|
+
:::>- $ git commit -m "add .env to .gitignore"
|
378
|
+
```
|
379
|
+
|
380
|
+
Test the Procfile locally using [Foreman](heroku-local#run-your-app-locally-using-foreman). Start the web server with `local`:
|
381
|
+
|
382
|
+
```term
|
383
|
+
:::>> background.start("heroku local", name: "local", wait: "Ctrl-C to stop", timeout: 15)
|
384
|
+
:::-- background.stop(name: "local")
|
385
|
+
```
|
386
|
+
|
387
|
+
Press `Ctrl+C` or `Cmd+C` to exit.
|
388
|
+
|
389
|
+
### Rails asset pipeline
|
390
|
+
|
391
|
+
When deploying to Heroku, there are several options for invoking the [Rails asset pipeline](http://guides.rubyonrails.org/asset_pipeline.html). See the [Rails 3.1+ Asset Pipeline on Heroku](rails-asset-pipeline) article for general information on the asset pipeline.
|
392
|
+
|
393
|
+
Rails 7 removed the `config.assets.initialize_on_precompile` option because it's no longer needed. Additionally, any failure in asset compilation now causes the push to fail. For Rails 7 asset pipeline support, see the [Ruby Support](ruby-support#rails-7-x-applications) page.
|
394
|
+
|
395
|
+
## Troubleshooting
|
396
|
+
|
397
|
+
If an app deployed to Heroku crashes, for example, `heroku ps` shows the state `crashed`, review the app’s logs. The following section covers common causes of app crashes.
|
398
|
+
|
399
|
+
### Runtime Dependencies on Development or Test Gems
|
400
|
+
|
401
|
+
If a gem is missing during deployment, check the Bundler groups. Heroku builds apps without the `development` or `test` groups, and if the app depends on a gem from one of these groups to run, move it out of the group.
|
402
|
+
|
403
|
+
A common example is using the RSpec tasks in the `Rakefile`. The error often looks like this:
|
404
|
+
|
405
|
+
```term
|
406
|
+
$ heroku run rake -T
|
407
|
+
Running `bundle exec rake -T` attached to terminal... up, ps.3
|
408
|
+
rake aborted!
|
409
|
+
no such file to load -- rspec/core/rake_task
|
410
|
+
```
|
411
|
+
First, duplicate the problem locally by running `bundle install` without the development or test gem groups:
|
412
|
+
|
413
|
+
```term
|
414
|
+
$ bundle install --without development:test
|
415
|
+
…
|
416
|
+
$ bundle exec rake -T
|
417
|
+
rake aborted!
|
418
|
+
no such file to load -- rspec/core/rake_task
|
419
|
+
```
|
420
|
+
|
421
|
+
>note
|
422
|
+
>The `--without` option on `bundler` is persistent. To remove this option, run `bundle config --delete without`.
|
423
|
+
|
424
|
+
Fix the error by making these Rake tasks conditional during gem load. For example:
|
425
|
+
|
426
|
+
```ruby
|
427
|
+
begin
|
428
|
+
require "rspec/core/rake_task"
|
429
|
+
|
430
|
+
desc "Run all examples"
|
431
|
+
|
432
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
433
|
+
t.rspec_opts = %w[--color]
|
434
|
+
t.pattern = 'spec/**/*_spec.rb'
|
435
|
+
end
|
436
|
+
rescue LoadError
|
437
|
+
end
|
438
|
+
```
|
439
|
+
|
440
|
+
Confirm it works locally, then push it to Heroku.
|
441
|
+
|
442
|
+
## Next Steps
|
443
|
+
|
444
|
+
Congratulations on deploying a Rails 7 application! To continue exploring, review the following articles next:
|
445
|
+
|
446
|
+
* Visit the [Ruby support category](/categories/ruby-support) to learn more about using Ruby and Rails on Heroku.
|
447
|
+
* The [Deployment category](/categories/deployment) provides a variety of powerful integrations and features to help streamline and simplify your deployments.
|
448
|
+
|
449
|
+
>note
|
450
|
+
>Remember to [delete your example app](https://devcenter.heroku.com/articles/heroku-cli-commands#heroku-apps-destroy), and [database](https://devcenter.heroku.com/articles/heroku-postgresql#removing-the-add-on) as soon as you're done with the tutorial, to control costs.
|
451
|
+
|
452
|
+
## Delete Your App and Add-on
|
453
|
+
|
454
|
+
Remove the app and database from your account. You're only charged for the resources you used.
|
455
|
+
|
456
|
+
>warning
|
457
|
+
>This action removes your add-on and any data saved in the database.
|
458
|
+
|
459
|
+
```term
|
460
|
+
$ heroku addons:destroy heroku-postgresql
|
461
|
+
```
|
462
|
+
|
463
|
+
>warning
|
464
|
+
>This action permanently deletes your application
|
465
|
+
|
466
|
+
```term
|
467
|
+
$ heroku apps:destroy
|
468
|
+
```
|
469
|
+
|
470
|
+
You can confirm that your add-on and app are gone with these commands:
|
471
|
+
|
472
|
+
```term
|
473
|
+
$ heroku addons --all
|
474
|
+
$ heroku apps --all
|
475
|
+
```
|
476
|
+
|
477
|
+
You're now ready to <a href= "https://devcenter.heroku.com/articles/preparing-a-codebase-for-heroku-deployment" target= "_blank">deploy your app</a>.
|
@@ -0,0 +1,194 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class ParserTest < Minitest::Test
|
4
|
+
def test_erb_shared_binding_persists_values
|
5
|
+
key = SecureRandom.hex
|
6
|
+
contents = <<~RUBY
|
7
|
+
```
|
8
|
+
:::-> print.erb
|
9
|
+
one <% @variable = "#{key}" %>
|
10
|
+
:::-> print.erb
|
11
|
+
<%= @variable %>
|
12
|
+
```
|
13
|
+
RUBY
|
14
|
+
|
15
|
+
Dir.mktmpdir do |dir|
|
16
|
+
Dir.chdir(dir) do
|
17
|
+
env = {}
|
18
|
+
env[:before] = []
|
19
|
+
expected = <<~EOF
|
20
|
+
one
|
21
|
+
#{key}
|
22
|
+
EOF
|
23
|
+
parsed = Rundoc::Parser.new(contents)
|
24
|
+
actual = parsed.to_md.gsub(Rundoc::CodeSection::AUTOGEN_WARNING, "")
|
25
|
+
assert_equal expected, actual
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
key = SecureRandom.hex
|
30
|
+
contents = <<~RUBY
|
31
|
+
```
|
32
|
+
:::-> print.erb(binding: "one")
|
33
|
+
one <% @variable = "#{key}" %>
|
34
|
+
:::-> print.erb(binding: "different")
|
35
|
+
<%= @variable %>
|
36
|
+
```
|
37
|
+
RUBY
|
38
|
+
|
39
|
+
Dir.mktmpdir do |dir|
|
40
|
+
Dir.chdir(dir) do
|
41
|
+
env = {}
|
42
|
+
env[:before] = []
|
43
|
+
expected = <<~EOF
|
44
|
+
one
|
45
|
+
EOF
|
46
|
+
parsed = Rundoc::Parser.new(contents)
|
47
|
+
actual = parsed.to_md.gsub(Rundoc::CodeSection::AUTOGEN_WARNING, "")
|
48
|
+
assert_equal expected, actual
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_erb_in_block
|
54
|
+
contents = <<~RUBY
|
55
|
+
```
|
56
|
+
:::>> print.erb
|
57
|
+
Hello
|
58
|
+
there
|
59
|
+
```
|
60
|
+
RUBY
|
61
|
+
|
62
|
+
Dir.mktmpdir do |dir|
|
63
|
+
Dir.chdir(dir) do
|
64
|
+
env = {}
|
65
|
+
env[:before] = []
|
66
|
+
expected = <<~EOF
|
67
|
+
```
|
68
|
+
Hello
|
69
|
+
there
|
70
|
+
```
|
71
|
+
EOF
|
72
|
+
parsed = Rundoc::Parser.new(contents)
|
73
|
+
actual = parsed.to_md.gsub(Rundoc::CodeSection::AUTOGEN_WARNING, "")
|
74
|
+
assert_equal expected, actual
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_erb_with_default_binding
|
80
|
+
contents = <<~RUBY
|
81
|
+
```
|
82
|
+
:::-> print.erb
|
83
|
+
Hello
|
84
|
+
there
|
85
|
+
```
|
86
|
+
RUBY
|
87
|
+
|
88
|
+
Dir.mktmpdir do |dir|
|
89
|
+
Dir.chdir(dir) do
|
90
|
+
env = {}
|
91
|
+
env[:before] = []
|
92
|
+
expected = <<~EOF
|
93
|
+
Hello
|
94
|
+
there
|
95
|
+
EOF
|
96
|
+
parsed = Rundoc::Parser.new(contents)
|
97
|
+
actual = parsed.to_md.gsub(Rundoc::CodeSection::AUTOGEN_WARNING, "")
|
98
|
+
assert_equal expected, actual
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_erb_with_explicit_binding
|
104
|
+
contents = <<~RUBY
|
105
|
+
```
|
106
|
+
:::-> print.erb(binding: "yolo")
|
107
|
+
Hello
|
108
|
+
there
|
109
|
+
```
|
110
|
+
RUBY
|
111
|
+
|
112
|
+
Dir.mktmpdir do |dir|
|
113
|
+
Dir.chdir(dir) do
|
114
|
+
env = {}
|
115
|
+
env[:before] = []
|
116
|
+
expected = <<~EOF
|
117
|
+
Hello
|
118
|
+
there
|
119
|
+
EOF
|
120
|
+
parsed = Rundoc::Parser.new(contents)
|
121
|
+
actual = parsed.to_md.gsub(Rundoc::CodeSection::AUTOGEN_WARNING, "")
|
122
|
+
assert_equal expected, actual
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_print_text_stdin_contents
|
128
|
+
contents = <<~RUBY
|
129
|
+
```
|
130
|
+
:::-> print.text
|
131
|
+
Hello
|
132
|
+
there
|
133
|
+
```
|
134
|
+
RUBY
|
135
|
+
|
136
|
+
Dir.mktmpdir do |dir|
|
137
|
+
Dir.chdir(dir) do
|
138
|
+
env = {}
|
139
|
+
env[:before] = []
|
140
|
+
expected = <<~EOF
|
141
|
+
Hello
|
142
|
+
there
|
143
|
+
EOF
|
144
|
+
parsed = Rundoc::Parser.new(contents)
|
145
|
+
actual = parsed.to_md.gsub(Rundoc::CodeSection::AUTOGEN_WARNING, "")
|
146
|
+
assert_equal expected, actual
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
def test_print_before
|
152
|
+
contents = <<~RUBY
|
153
|
+
```
|
154
|
+
:::-> print.text Hello there
|
155
|
+
```
|
156
|
+
RUBY
|
157
|
+
|
158
|
+
Dir.mktmpdir do |dir|
|
159
|
+
Dir.chdir(dir) do
|
160
|
+
env = {}
|
161
|
+
env[:before] = []
|
162
|
+
expected = <<~EOF
|
163
|
+
Hello there
|
164
|
+
EOF
|
165
|
+
parsed = Rundoc::Parser.new(contents)
|
166
|
+
actual = parsed.to_md.gsub(Rundoc::CodeSection::AUTOGEN_WARNING, "")
|
167
|
+
assert_equal expected, actual
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
def test_print_in_block
|
173
|
+
contents = <<~RUBY
|
174
|
+
```
|
175
|
+
:::>> print.text Hello there
|
176
|
+
```
|
177
|
+
RUBY
|
178
|
+
|
179
|
+
Dir.mktmpdir do |dir|
|
180
|
+
Dir.chdir(dir) do
|
181
|
+
env = {}
|
182
|
+
env[:before] = []
|
183
|
+
expected = <<~EOF
|
184
|
+
```
|
185
|
+
Hello there
|
186
|
+
```
|
187
|
+
EOF
|
188
|
+
parsed = Rundoc::Parser.new(contents)
|
189
|
+
actual = parsed.to_md.gsub(Rundoc::CodeSection::AUTOGEN_WARNING, "")
|
190
|
+
assert_equal expected, actual
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
@@ -1,11 +1,9 @@
|
|
1
|
-
require
|
1
|
+
require "test_helper"
|
2
2
|
|
3
3
|
class AppendFileTest < Minitest::Test
|
4
|
-
|
5
4
|
def test_appends_to_a_file
|
6
5
|
Dir.mktmpdir do |dir|
|
7
6
|
Dir.chdir(dir) do
|
8
|
-
|
9
7
|
file = "foo.rb"
|
10
8
|
`echo 'foo' >> #{file}`
|
11
9
|
|
@@ -22,7 +20,7 @@ class AppendFileTest < Minitest::Test
|
|
22
20
|
cc << "baz"
|
23
21
|
cc.call
|
24
22
|
|
25
|
-
actual
|
23
|
+
actual = File.read(file)
|
26
24
|
expected = "foo\nbar\nbaz\n"
|
27
25
|
assert_equal expected, actual
|
28
26
|
end
|
@@ -32,10 +30,9 @@ class AppendFileTest < Minitest::Test
|
|
32
30
|
def test_appends_to_a_file_at_line_number
|
33
31
|
Dir.mktmpdir do |dir|
|
34
32
|
Dir.chdir(dir) do
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
gem 'rails', '4.0.0'
|
33
|
+
contents = <<~CONTENTS
|
34
|
+
source 'https://rubygems.org'
|
35
|
+
gem 'rails', '4.0.0'
|
39
36
|
CONTENTS
|
40
37
|
|
41
38
|
file = "foo.rb"
|