Showing posts with label ruby. Show all posts
Showing posts with label ruby. Show all posts

Friday, 30 August 2013

Calabash IOS ruby installation (rvm) error and solution

echo progress-bar >> ~/.curlrc
execute command to install rvm with latest ruby:
\curl -L https://get.rvm.io | bash -s stable --ruby

Add below line into ~/.bash_profile
#RVM
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"  # This loads RVM into a shell session.

Check calabash installation
 calabash-ios console
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems.rb:777:in `report_activate_error': Could not find RubyGem json (>= 0) (Gem::LoadError)
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems.rb:211:in `activate'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems.rb:246:in `activate'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems.rb:245:in `each'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems.rb:245:in `activate'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems.rb:1056:in `gem'
from /usr/bin/calabash-ios:18

install this command and you may see below error
sudo gem install json

unable to convert "\xCF" from ASCII-8BIT to UTF-8 for lib/json/ext/generator.bundle,

sudo gem update --system
sudo gem install rdoc



Thursday, 9 May 2013

Reading Excel file using ruby


 This is an example to read excel file in ruby (this can be used for reading excel workbook as well) using RubyXL gem

Step 1) Create an excel workbook like below



 Step 2) Create a ruby file including gems
require 'rubygems'
require 'rubyXL'

Copy path to excel file and replace it in place of work book
    workbook = RubyXL::Parser.parse("/Users/username/Downloads/simple_spreadsheet.xlsm")



This first sheet of excel workbook can be read into hash table using below command
    hash_arr=workbook[0].get_table(["Login", "email", "password"])

Multiple tables can be present in same file and they will read based on the format given in the above command (this helps in organizing many data tables in single sheet of excel file)



 Step 3: If needed it can be used in cucumber file as below


Source code :


require 'rubygems'
require 'rubyXL'
workbook = RubyXL::Parser.parse("simple_spreadsheet.xlsm")
hash_arr=workbook[0].get_table(["Login", "email", "password"])
all_tables=hash_arr[:table]
puts all_tables


For more details refer to - https://github.com/gilt/rubyXL project

Output looks like below