I know there’s a million of these articles out there and even though it’s quite a straightforward process, I still find myself having to research how to do it. So I thought I’d write a quick post about my process and how I do it.
Firstly, lets go ahead and open up the terminal and install rails.
$ gem install rails
I’ve decided to use RSpec and Postgres, so the next command intialises a new app where I specify the database and the fact that I’d like to turn off Rails’ built-in test suit.
$ rails new YourApp -d postgresql -T
If you’d rather use Rails’ default testing suite and database, you can also initialise an app like so:
$ rails new YourApp
This will do a whole bunch of stuff and setup your project with a load of files. Once this is all done, navigate to the project’s root directory and launch the server.
$ cd YourAppsRootDirectory
$ bin/rails s
This will launch the server on the default port (http://localhost:3000), when navigating to this page you should see a message welcoming you to Rails and confirming your server is up and running! If that didn’t work and you’re having trouble, depending on your computers configuration, you may need to create your databases and run a rake task.
$ bin/rake db:create
As I mentioned earlier, I’ve gone with RSpec, with Capybara, as my preferred testing suite, however choose whichever your most comfortable with. First things first, in our Gemfile we should add the required gems. At this point we should also specify what ruby version we’ll be using.
ruby '2.3.0'group :test do
Once doing this, we should bundle to install those gems and use the RSpec install command to create a testing structure for us.
$ bin/rails generate rspec:install
Lastly, if you’re using Capybara, you’ll need to reuqire it in your rails_helper.rb file.
Now you’re all ready to write your first test and start creating your application!