Skip to content

Commit

Permalink
Add instructions about how to setup test database (#282)
Browse files Browse the repository at this point in the history
* Add instructions about how to setup test database

* Be more explicit about the need to check .env.test file

Previous version may lead the reader to conclude that there's
something missing in environment variables for test environment where
in fact he just have to check that the existing info are matching its
database setup / credentials.
  • Loading branch information
Bounga authored and jodosha committed Feb 28, 2017
1 parent d2fbf26 commit dd76337
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
6 changes: 6 additions & 0 deletions source/guides/command-line/database.md
Expand Up @@ -25,6 +25,12 @@ With `db create` we can create the database for the current environment.
% bundle exec hanami db create
```

To be able to run tests, test database has to be explicitly created

```shell
% HANAMI_ENV=test bundle exec hanami db create
```

In order to preserve production data, this command can't be run in the production environment.

### Drop
Expand Down
14 changes: 13 additions & 1 deletion source/guides/getting-started.md
Expand Up @@ -70,7 +70,7 @@ Then we can use the new `hanami` executable to generate a new project:

<p class="notice">
By default, the project will be setup to use a SQLite database. For real-world projects, you can specify your engine:
<code> 
<code>
% hanami new bookshelf --database=postgres
 </code>
</p>
Expand Down Expand Up @@ -159,6 +159,18 @@ Note that, although Hanami is ready for a Behavior Driven Development workflow o
We'll go with [Minitest](https://github.com/seattlerb/minitest) here (which is the default), but we can use [RSpec](http://rspec.info) by creating the project with `--test=rspec` option.
Hanami will then generate helpers and stub files for it.

<p class="notice">
Please check .env.test in case you need to tweak the database URL.
</p>

We have to migrate our schema in the test database by running:

```shell
% HANAMI_ENV=test bundle exec db prepare
```

As you can see, we have set `HANAMI_ENV` environment variable to instruct our command about the environment to use.

### Following a Request

Now we have a test, we can see it fail:
Expand Down

0 comments on commit dd76337

Please sign in to comment.