This is a skeleton app for developing Heroku-deployable modular Sinatra apps with DataMapper, Slim, RSpec & Capybara.
Skip this step if Heroku toolbelt is already installed. Not sure? Try heroku --version
- Download and install Heroku toolbelt from toolbelt.heroku.com.
In order to sync your repository with GitHub & deploy your app to Heroku, you will need a git repository. This can be done from the terminal, but is probably easier done in the GitHub client.
- Start the GitHub client
- In the
File
menu, selectAdd Local Repository
- Select app's root folder and click
add
- When asked if you want to "create a new git repository here?", click
Create and Add
Gemfile contains a listing of all required gems.
-
Go to the app's root folder
-
run
bundle install
This will
- Download and install all gems listed in Gemfile
- Create (or update)
Gemfile.lock
, which contains a listing of which versions of the gems specified in Gemfile that have been installed.
Heroku uses
Gemfile.lock
to install the same versions of the gems, making sure that the app will work the same way on Heroku as it does on your own machine.
If you add a gem to Gemfile you must rerun bundle install
to generate a new Gemfile.lock
.
In order to not have to manually restart the server when we are developing, we use rerun. Rerun will watch the app's folder, and automatically restart the server when it detects a change in a file.
-
rerun --ignore "*.{slim,js,css,coffee}" "rackup --host 0.0.0.0"
This will launch rerun, which will, in turn, start the server using
rackup
. The--ignore
argument tells rerun not to restart the app if it detects changes in .slim, .js, .css or .coffee files (changes in these types of files do not require a relaunch of the server)rackup
will look in config.ru for instructions on how to start the server. -
Look for the line telling which port the server is running on (normally 9292)
- DEVELOPMENT ENV *
Thin web server (v1.6.4 codename Gob Bluth) Maximum connections set to 1024 Listening on 0.0.0.0:9292, CTRL+C to stop 12:32:00 [rerun] Watching . for **/*.{rb,js,coffee,css,scss,sass,erb,html,haml,ru,yml,slim,md,feature} (ignoring *.{slim,js,css,coffee})
-
Launch your browser and point it to
localhost:9292
You should see Hello, Sinatra!
There are three different types of tests, testing different aspects of the application.
The tests are run using rake tasks, specified in rakefile.
Route tests test the routes (get and/or post) specified in app.rb.
Route tests are located in test/routes/
Look in test/routes/base_test.rb for examples of what you can test using route tests.
- To run route tests:
rake test:routes
- To create new route tests: create files named
*_test.rb
intest/routes/
Model tests test the models specified in models/
Model tests are located in test/models
Look in test/models/sample_test.rb for examples of what you can test using model tests
- To run model tests:
rake test:models
- To create new model tests: create files named
name_of_model_test.rb
intest/models
Acceptance tests test the entire application; routes, models, database, and frontend.
If the tests do not rely upon javascript, the tests are in a headless browser using Capybara.
If the tests require javascript, the tests must be run in a programatically controlled browser using Selenium.
Look in test/acceptance/sample_spec.rb for examples of what you can test using acceptance tests.
- To run acceptance tests:
rake test:acceptance
- To create new acceptance tests: create files named
name_of_feature_spec.rb
intest/acceptance
Since Heroku uses the git repository for deployment, you must always commit the latest changes to the repository before deploying the app.
-
In the apps root folder, run
heroku create
This creates an empty app on Heroku, ready to accept your application, and tells git how to push the application to Heroku.
-
Install the Heroku Postgresql addon:
heroku addons:add heroku-postgresql:dev
-
In the apps root folder, run
git push heroku master
This pushes the application to Github. Gitub then:
- Determines what kind of app it is (in our case Ruby).
- Downloads and installs the gems specified in
Gemfile.lock
(but only the ones specified in theproduction
group).
Heroku caches the gems so it does not have to install them every time you push changes to the app.
- Starts the applications server running the command specified in Procfile
To view the application, either run
heroku open
, which points your web browser to the app's url, or tell the browser to go there manually.
Since we have a new database, none of the data has been transferred.
- Run
heroku run rake db:seed
to seed the database from db/seed.rb
Sometimes the app won't start, or maybe it will crash. To view the logs, run
heroku logs
in the apps root folder.
Sometimes you might feel the need to do some "cowboy coding".
- To access the app's console:
heroku run racksh