Book Image

Instant RubyMine Assimilation

By : David L. Jones
Book Image

Instant RubyMine Assimilation

By: David L. Jones

Overview of this book

Ruby and Ruby on Rails applications can become very complex very quickly, with hundreds of different files to contend with during a typical day of development. With RubyMine, you can become much more productive and let the IDE take care of the menial tasks while you concentrate on the details and structure of your applications. Instant RubyMine Assimilation shows you how to integrate the RubyMine development environment into your everyday development process. With step-by-step instructions and practical examples, you will learn how to customize the environment precisely to suit your needs, debug and test your code, and get the most out of many other features of RubyMine. Starting with the installation of RubyMine on your preferred platform, this guide will walk you through creating your first program. You will be taken through everything from the development and testing process all the way to deploying your website for the world to enjoy. You will learn how to manage your project in RubyMine including integrating version control, testing, and debugging your projects. Furthermore, you will learn how to navigate complex projects, view database tables, and utilize the built-in console and deployment tools of RubyMine, all of which will help you become an expert developer This book will also teach you how to install and use Gems, change Ruby environments, and use code coverage and reports to enhance your testing. By the end of this book, you will be able to confidently deploy your Rails application to a server, all within the inviting environment that is RubyMine.
Table of Contents (7 chapters)

Strengthening your tech against intrusion (Become an expert)


In this recipe, we will begin using the code coverage Gem with the built-in RubyMine tools to enhance your testing regimen and make your code even more robust.

Getting ready

Open your Progeny Rails project that we created earlier in RubyMine.

How to do it...

We first need to add the Gem simplecov to our Gemfile using the following steps:

  1. Open this Gemfile and add the following line:

    gem 'simplecov', :require => false, :group => :test
  2. Navigate to Tools | Bunder | Install.

Now, all we have to do is to run our comprehensive set of tests that we created earlier using the coverage option:

  1. Select the rake test configuration and then hit the button that looks like "Run 'test' with Coverage".

If you followed the other recipes, then you probably got seven errors in your tests. Oops! Remember that the Borg are only seeking perfection, we have not yet arrived! We need to add some text fixtures that we removed earlier using the following steps:

  1. Open the test/fixtures/species.yml file and add back the following fixtures:

    one:
      name: MyString
      identification: 1
      assimilated: false
    
    two:
      name: MyString
      identification: 1
      assimilated: false
  2. Rerun the test with the coverage option and all of our tests should pass. A new panel will open on the right that has the results of our coverage, as shown in the following screenshot:

This shows that we don't have many of our lines of code actually tested. Let's generate a report, so we can see more detail:

  1. Click on the Generate Coverage Report icon which looks like a square with a green arrow point up.

    The next window will ask you where you want to save the file and gives the option of opening the resulting report in your browser.

  2. Select this option and hit Save.

    Your browser should now open with a report in which you can click on each line and get actual details of which lines of code have not been tested or executed:

  3. Click on the file app/controllers/species_controller.rb.

    You will then get a screen like the following, which shows much more detail about exactly which lines were not tested.

  4. The lines in green are tested and they show a little number on the right in a black circle that tells how many times that line of code was executed during the tests. The light red lines show which code has not been executed at all and are ripe for a new test to be written, so we can aspire to 100 percent code coverage:

  5. Now you, the new RubyMine drone, can begin to write the missing tests and continue until you are a perfect 100 percent code coverage expert.

There's more…

If you would like to read more information on SimpleCov, you can find it at https://github.com/colszowka/simplecov.