-
Notifications
You must be signed in to change notification settings - Fork 2
Testing
This section will show you how to run all the system tests, as well as how to add new tests. See the table of contents, for setting up your development environment first.
If you encounter any errors with this wiki, or the project in general, please submit a new issue!
Using the rails console, you can interact directly with the app, even when its not running.
rails console
See this link for some tips and tricks.
Navigate into the project's root folder.
cd share-the-food/
Run the unit tests.
rails test
Run the system, i.e. feature, tests.
rails test:system
Navigate to the project's root folder.
cd share-the-food/
Run Rubocop, the analyzer. Also, require its performance analyzer.
rubocop --require rubocop-performance
Rubocop can automatically fix many of the issues it detects.
rubocop -a
A sonarqube analysis is automatically performed by Travis CI. Visit the dashboard.
Navigate to the project's root folder.
cd share-the-food/
Run the Ruby static code analyzer. The app parameter excludes test, configuration, etc. code.
rubycritic app
The results will open in a web browser.
Navigate to the project's root folder.
cd share-the-food/
Run the brakeman Ruby on Rails static code analyzer.
brakeman
The results will output to the terminal.
Navigate to the project's root folder.
cd share-the-food/
Run the Rails Best Practices static code analyzer.
rails_best_practices -f html .
The results will output in share-the-food/rails_best_practices_output.html
Navigate to the project's root folder.
cd share-the-food/
Run the traceroute tool. It will display any unused or unreachable routes.
rake traceroute
Navigate to the project's root folder.
cd share-the-food/
To see the total memory used by each gem in the Gemfile, run the following command.
bundle exec derailed bundle:mem
To see memory usage over time by the application, run the following command.
bundle exec derailed exec perf:mem_over_time
More information and commands can be found here.
Navigate to the project's root folder.
cd share-the-food/
Run the fasterer tool. It will output any suggests to speed up Ruby code.
In development, the Bullet gem will detect any query that could be sped up and alert the developer, through the console, pop-ups, etc.
Navigate to the project's root folder.
cd share-the-food/
Run the database analyzer, to find if any indexes should be added to any database columns to increase performance.
lol_dba db:find_indexes
Each commit and pull request has all tests and a style check automatically run by Travis CI. The master branch is protected, you cannot commit directly into it. Instead, create another branch, make your changes, then create a pull request into master. Only once all tests have passed (and someone else has reviewed the code) can the pull request be merged.
Tests are located in share-the-food/test.
Test data are stored in fixtures at test/fixtures. Each file is split per model.
Unit tests are located in /test/models/*. Each file is split per model.
Feature tests are located in /test/system/*. Each file is a different page of the website. Multiple features are stored per file.
Tests for controllers, helpers, mailers, and integration tests can also be added (they currently don't have any tests written) in test/controllers/, test/helpers/, test/mailers/, and test/integration/.