Basic tests scaffold

This commit is contained in:
Chris Veleris 2023-11-13 13:34:38 +02:00
parent 998a1c3e7c
commit aa408a85dc
4 changed files with 51 additions and 0 deletions

View file

@ -18,3 +18,7 @@ gem 'byebug'
# Development
gem 'faker'
gem 'rubocop'
# Testing
gem 'rack-test', group: :test
gem 'minitest', group: :test

View file

@ -51,6 +51,8 @@ GEM
rack (2.2.8)
rack-protection (3.1.0)
rack (~> 2.2, >= 2.2.4)
rack-test (2.1.0)
rack (>= 1.3)
rainbow (3.1.1)
rake (13.1.0)
rb-fsevent (0.11.2)
@ -97,7 +99,9 @@ DEPENDENCIES
bcrypt
byebug
faker
minitest
puma
rack-test
rake
rerun
rubocop

View file

@ -57,6 +57,13 @@ To install `tu|du|di`, follow these steps:
openssl req -new -x509 -key server.key -out server.crt -days 365
```
### DB setup
1. Execute the migrations
```bash
rake db:migrate
```
### Create your user
1. Open console
```bash
@ -76,6 +83,14 @@ To start the application, run the following command in your terminal:
puma -C app/config/puma.rb
```
### Testing
To run tests:
```bash
bundle exec ruby -Itest test/test_app.rb
```
Open your browser and navigate to `http://localhost:9292` to access the application and login with the email and the password you created.
## Contributing

28
test/test_app.rb Normal file
View file

@ -0,0 +1,28 @@
require 'minitest/autorun'
require 'rack/test'
require_relative '../app'
class AppTest < Minitest::Test
include Rack::Test::Methods
def app
Sinatra::Application
end
def setup
ActiveRecord::Base.logger.level = Logger::WARN
User.create(email: 'test@example.com', password: 'password')
end
def test_get_home
post '/login', { email: 'test@example.com', password: 'password' }
get '/'
assert last_response.ok?
end
def test_get_inbox
post '/login', { email: 'test@example.com', password: 'password' }
get '/inbox'
assert last_response.ok?
end
end