In the last chapter we installed lots of goodies to make our mac a more productive environment and one more conducive to using calaba.sh on.
In this chapter we will configure our bash_profile so that rvm is available every time we use the terminal window, then we will install calaba.sh and finally at the end of the chapter we will runs test using calaba.sh.
RVM is a version manager for Ruby. It allows us to switch between versions of Ruby. You may have several projects going as once and each project may be built on a different version of Ruby. Instead of hacking your system around and making a pigs ear of things, rvm does all the heavy lifting, allowing us to install and switch ruby versions in one simple command line statement.
Now – if you’ve followed my instructions in Chapter 1, you will have ruby v2 installed.
Now if we want to instal other versions of ruby we can use dvm to manage them, but when I tried running
$ rvm install 1.9.2
to install version 1.9.2, I ran into a problem – basically the installer hung at the gcc part – so I had to do the following:
$ brew update
$ brew tap homebrew/dupes
$ brew install autoconf automake apple-gcc42
$ rvm pkg install openssl
$ rvm reinstall all —force
$ sudo ln -s /usr/local/bin/gcc-4.2 /usr/bin/gcc-4.2
$ rvm install 1.9.2
So now ruby 1.9.2 is installed let’s just take a look at the list of rubies that we have on our system and which one we are using, we do this by typing:
$ rvm list
my response is:
ruby-1.9.2-p320 [ x86_64 ]
=* ruby-2.0.0-p247 [ x86_64 ]
=> – current
=* – current && default
* – default
This shows us that we have ruby 1.9.2 and ruby 2.0.0 installed and that we are using ruby 2.0.0 as our current and default ruby installation.
Please note, each time you use rvm it is a good idea to make sure you have the latest version. You can do this by entering:
$ rvm get stable —autolibs=enable.
Now using rvm, if you want to set 1.9.2 as the default version you can ruby version you can just issue the command:
$ rvm use 1.9.2
RVM is a useful tool. I suggest you take a look at http://rvm.io/rvm/basics to find more info on how to change your default, check paths to you versions etc.
We’re going to need something to test against. If you don’t already have the source code for an app, Calaba.sh has a sample app that we can use. To get the source code we need to get it from Github. To do this we do what is called “clone” the git repository. The git repository is: https://github.com/calabash/calabash-ios-example and to ‘clone’ the github repository (repo) we do the following: cd into the folder where you will keep your apps source code, then issue the command to clone the repo:
$ git clone https://github.com/calabash/calabash-ios-example.git
this will make a calabash-ios-example folder containing the source code for the App.
In terminal, cd to your app folder, in my case, this is:
$ cd ~/App/calabash-ios-example/
then install the calabash-cucumber gem:
$ sudo gem install calabash-cucumber
then run the calabash project set up:
$ calabash-ios setup
Then follow the instructions in your terminal console. This is done by running the -cal target from Xocde.
First we’ll do this, then I’ll explain what we’ve just done.
In Xcode, open the .xcodeprojfile for your app – this is in the folder LPSimpleExample if using the sample app.
Then, go to the scheme toolbar – in my workspace it’s under Product > Scheme. Select the app which is post fixed with -cal, in my case LPSimpleExample-cal
Build the app.
The simulator will start and in the in the application log (which is in the bottom right of your Xcode workspace) you will find a message which say “Started LPHTTP server on port xxxxxx” – this verifies that your project has been built and is running under calabash.
What we have done here is instruct the app to use the calabash framework (hence the postfix -cal)
Finally, we can generate the skeleton folders for our tests:
$ calabash-ios gen
then run our first test:
We should see 1 passed scenario and 4 passed steps.
That’s us set up and ready to rock and roll.
Next chapter – diving deeper – writing our own tests