Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Instant RubyMine Assimilation

You're reading from  Instant RubyMine Assimilation

Product type Book
Published in Nov 2013
Publisher Packt
ISBN-13 9781849698764
Pages 66 pages
Edition 1st Edition
Languages
Author (1):
David L. Jones David L. Jones
Profile icon David L. Jones

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.

arrow left Previous Chapter
You have been reading a chapter from
Instant RubyMine Assimilation
Published in: Nov 2013 Publisher: Packt ISBN-13: 9781849698764
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}