Wednesday, June 17, 2015

Objective-C: Travis-CI and Coveralls.io (2/2)

Until now we've added to our repository just the support for Travis-CI. Now it's time for Coveralls.io which is basically the second part of this Pull Request.

Coveralls is a service that analyses your code and gives a percentage of code that is covered by some tests.

Coveralls.io

If your code is already on Github, you can navigate now to Coveralls.io and activate the support for your repository, otherwise you can do it at the end, but then the next commit will show up on Coveralls.io. As we already had for the Travis-CI;

1) This service will start after Travis-CI so he needed to invoke it when Travis-CI has finished. This can be done by adding it to the .travis.yml
after_success: bundle exec slather
As you may already expect he had to include slather into our Gemfile and execute it
source 'https://rubygems.org'
gem 'cocoapods'
gem 'rake'
gem 'slather'
gem 'xcpretty'
Slather, as Travis-CI needs its own configuration file which is .slather.yml in this case

2) If you'd run now the bundle exec slather command you'll probably end up with an error as Xcode is not generating coverage files if they are not needed. There are basically two flags to set in the xcodeproject file
  • GCC_GENERATE_TEST_COVERAGE_FILES = YES
  • GCC_INSTRUMENT_PROGRAM_FLOW_ARCS = YES
Basically there are the methods to set these flags

  1. Open Xcode, search in Build settings for Instrument Program Flow and Generate Test Coverage Files and set both of them to YES which will generate the needed files on every build
  2. You can do the same executing the command $ slather setup path/to/project.xcodeproj which will automatically set those flags
  3. Add the parameters to the build command in the Rakefile which will generate them only when you execute the rake build.

3) Now as in Travis-CI just add the badge to the readme
[![Coverage Status](https://coveralls.io/repos/hons82/THSegmentedPager/badge.svg)](https://coveralls.io/r/hons82/THSegmentedPager)

Objective-C: Travis-CI and Coveralls.io (1/2)

Just recently one of my projects has been chosen to become featured with test during the CocoaPods Test Jam.

Goal of this event was to add tests (XCTestSpecta / Expecta , Kiwi or Cedar) to the projects (THSegmentedPager in my case) to reach a certain coverage and add the project to the Travis-CI Continuous Integration service as well as to the Coveralls test coverage service.

In this article I'll skip the creation of the tests itself (Those can be seen in the repository and watching the Pull Request that he sent when everything was done) and jump directly to the Travis-CI and Coveralls.io integration.

Travis-CI

If your project is already on Github you could navigate to Travis-CI connect it with your Github account and enable it for Travis-CI. If not you'll need to do it at the end of the process and it will run with the next commit.

1) As the project uses CocoaPods he add a Gemfile with it as dependency which you can execute using bundler (sudo gem install bundler)
$ bundle install
Resolving dependencies...
Using i18n 0.7.0
Using json 1.8.3
Using minitest 5.7.0
Using thread_safe 0.3.5
Using tzinfo 1.2.2
Using activesupport 4.2.1
Using claide 0.8.1
Using fuzzy_match 2.0.4
Using nap 0.8.0
Using cocoapods-core 0.37.2
Using cocoapods-downloader 0.9.0
Using cocoapods-plugins 0.4.2
Using netrc 0.7.8
Using cocoapods-trunk 0.6.1
Using cocoapods-try 0.4.5
Using colored 1.2
Using escape 0.0.4
Using molinillo 0.2.3
Using xcodeproj 0.24.2
Using cocoapods 0.37.2
Using bundler 1.10.3
Bundle complete! 1 Gemfile dependency, 21 gems now installed.
Use `bundle show [gemname]` to see where a bundled gem is installed.

2) Now he add the .travis.yml file which will tell to Travis what is exactly to do.
language: objective-c
before_script:
- bundle exec pod install --project-directory=THSegmentedPagerExample
script:
- set -o pipefail && bundle exec rake test | bundle exec xcpretty --test --color
- bundle exec pod lib lint --quick
To make this commands work we'll need to add the missing commands (rake and xcpretty)to the Gemfile and execute it again
source 'https://rubygems.org'
gem 'cocoapods'
gem 'rake'
gem 'xcpretty'
The script in .travis.yml points to a rake target named "test" which he had to define in the Rakefile
desc 'Run tests'
task :test do
  command = "xcodebuild \
    -workspace THSegmentedPagerExample/THSegmentedPagerExample.xcworkspace \
    -scheme THSegmentedPagerExample \
    -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 6,OS=8.1' \
    test"
  system(command) or exit 1
end
task :default => :test
If you're not sure about how to write the script it is probably the best option to open a console; cd to the project root and run it

3) One more thing which is often forgotten is to share the scheme. This is done in Xcode

4) Now, as you'll probably want to show that you're using a CI service all that is left is to add a badge to the readme
[![Build Status](https://travis-ci.org/hons82/THSegmentedPager.png)](https://travis-ci.org/hons82/THSegmentedPager)

Monday, June 15, 2015

OSX 10.11 - El Capitan

I was so curious about El Capitan that I had to download and install it on my old Mac just after it was present in the developer center.

As expected from the presentation and the reviews the main changes are under the hood, so beside the updated notes app, the improved Spotlight and window management you'll not see a lot. However, more interesting for me is to see when it can be used for development.

In previous OSX versions we hat always problems with some tools that were simply not ready for updates. Despite that on El Capitan most things are working one thing that we use quite often was not working.

Cocoapods

The issue here was something like this
ERROR: While executing gem ... (Errno::EPERM) Operation not permitted
The issue behind is the "rootless" feature that comes with 10.11 as I've found here. For now it needs to be disabled.
sudo nvram boot-args="rootless=0"
Now it seems like it would install correctly, however there will come up an error wit a dependency that cocoapods needs "nokogiri".
This seems not to point to the right libraries, so you'll need to install it first using this command
sudo gem install nokogiri -- --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/libxml2 --use-system-libraries
Now you should be able to use cocoapods again.

To Be Continued ...

Golang setup PATH

Quite recently we startet in the company to use and write some Go programs. I love Go. It's easy to learn, read and modify. One of the m...