Blog

bevkjbvkbdkdxoeoziejdoiehz fiugebfuyegwik

Building nokogiri on OS X

Since I constantly have to build nokogiri for some Gem or another and also always forget how to prevent it from falling over itself, here are my notes. The instructions are for Yosemite and were tested on 10.10.3.

Building older versions

Older versions of Nokogiri need to be told where to find certain system libraries. Use this command as an example (it installs version 1.3.3):

$ gem install nokogiri -v 1.3.3 -- --with-iconv-dir=`xcode-select -p`/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr --with-xml2-include=`xcode-select -p`/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/libxml2

Building versions >= 1.6.4

The newer versions got better and worse at the same time. Under certain circumstances, one will not have a /usr/include on Yosemite, but nokogiri stubbornly checks for that. The fix for this is ugly, simply to this before installation:

$ sudo mkdir /usr/include
$ sudo touch /usr/include/iconv.h

😭

Objective-C code coverage

"If you like it you should have put a test on it." ~ Beyonce Knowles, Software Developer.

source

How do we even coverage?

You have written some tests for new code or maybe are trying to improve the quality of an existing open source component. That's cool, but how do you get a sense of what tests are still missing?

The answer is of course code coverage - if you are unfamiliar with the concept, take a look at Jon Reid's excellent article on the topic. Thankfully, enabling this has pretty much become trivial, thanks to the nice work of Mark Larsen in form of slather:

$ slather setup path/to/project.xcodeproj
$ # Run the testsuite
$ slather coverage -s path/to/project.xcodeproj

This is great for getting an overview and also for integrating code coverage into CI via Coveralls. However, it does not really help us to find the uncovered bits in the codebase.

PuncoverPlugin

The obvious answer is that this should be visible right next to the code. Enter PuncoverPlugin:

Screenshot of the plugin in action

You can install it via Alcatraz and it integrates with slather, so there is nothing to set up if you already use it. Simply run

$ slather coverage -g path/to/project.xcodeproj

to generate a .gutter.json file. The plugin will pick up that file and display the information right where you need it, in Xcode's gutter.

Gutter JSON

This is a simple file format I came up with to store information which should be displayed by PuncoverPlugin:

{ "/some/file": [
      {
        "line": 23,
        "long_text": "Some longer text in a tooltip when hovering over the line.",
        "name": "main",
        "short_text": "gutter text",
        "background_color":"0x35CC4B"
      }
] }

The example tells the plugin to display the given short_text right next to line 23 and color it with that background_color. The long_text value will be displayed on hover. This makes the plugin really flexible, as it allows integration with other tools to display arbitrary information in the Xcode editor gutter. You can find some information about other integrations in the README and maybe come up with some of your own.

Test Jam

Of course you are a nice person and all your projects already have 100% code coverage, but there is still a nice opportunity to use this plugin: the CocoaPods Test Jam, a community event we are doing to improve the test coverage of popular Pods. You should participate for some great fun!