Tag Archives: ruby

Installing Rbenv

RBENV is a Ruby Version manager like RVM. Despite that I’ve been working long time with RVM and it is great, I am giving an opportunity to RBENV. Some reasons:

  • Lighter and more comprehensive to install
  • Simpler, if you use Bundler (I do) you would avoid gemset management

First is install requirements. I’ve got it from RVM, but finally I’ve found that I’ve needed when ruby versions are compiling:

sudo apt-get -y install build-essential openssl libreadline6 libreadline6-dev zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison libcurl3 libcurl3-gnutls libcurl4-openssl-dev

Install RBENV:

git clone git://github.com/sstephenson/rbenv.git .rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc

RUBY-BUILD provides an ‘rbenv install’ command to compile and install different versions of Ruby on UNIX-like systems.

git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc

REHASH avoids use this command every time a gem is installed or uninstalled.

git clone https://github.com/sstephenson/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehash

BINSTUBS avoid the use of ‘bundle exec’ in some commands which should be executed in command line:

git clone https://github.com/ianheggie/rbenv-binstubs.git ~/.rbenv/plugins/rbenv-binstubs

The only disadvantage of BINSTUBS is that you have to remember to run the following command

bundle install --binstubs .bundle/bin

in all your actual projects, so that the appropriate bundle version will be accessed. Binstubs will be created at .bundle/bin and won’t interfere with ./bin folder.

Now, you can use it. List all available versions:

rbenv install -l

Install a Ruby version:

rbenv install 2.1.2

Choose default ruby version on your system

rbenv global 2.1.2

Choose default ruby version on your project (this will create a .ruby-version file scanned every time you access the folder)

rbenv local 2.1.2

Smoke production tests for critical features

Use case:

  • A client wants to be sure that some critical functionality is running in their production environments. Example: their products are showing in their web shop.

Plan:

  • Create some Smoke tests against production server
  • Create a Jenkins job which executes them every hour, sending a mail if this fails

In this post we will see how to create these Smoke tests with Rspec/Capybara/Mechanize. On server you can have deployed whatever web technology (Java, PHP, Node …). Required gems:

  • Rspec: testing Ruby environment
  • Capybara: simple DSL for simulating user interaction with a web application
  • Capibara-mechanize: Capybara driver which uses mechanize to create remote server requests

So that in your Gemfile (asuming you use Bundler to manage your dependencies):

  gem 'capybara'
  gem 'capybara-mechanize'

The specification:

require 'spec_helper'
 
WEBSITE_URL = "http://www.swordshop.com"
 
feature "Critical features on: #{WEBSITE_URL}" , smoke: true do
  background do
    Capybara.run_server = false
    Capybara.app_host = WEBSITE_URL
    require 'capybara/mechanize'
    Capybara.default_driver = :mechanize
 
    visit root_path
  end
 
  scenario "root is up" do
    page.should have_content("Best Swords in the world")
  end
 
  scenario "products url is showing products" do
    within("nav") { click_on "Products" }
    page.should have_css(".product")
  end
end

Just a little great detail: include smoke tag in your excluding filters, so that this will not be mixed with your unit and functional tests:

  config.filter_run_excluding :smoke

And you can allways call these tests with the command:

rspec --tag smoke