Running cucumber features in different locale

We use Selenium + Capybara + Firefox to run all our cucumber features. Recently, we decided to extend the tests to run in different locales and this post is a summary of the problems and the plausible solutions.

We had the following objectives in mind:

  • Since, we run the tests in firefox, the test process should be capable of creating an appropriate profile with required locale settings
  • The tests should be generic enough so that they don’t have to be written and maintained separately for every locale

Setup

The first step involves creating a new browser profile and switching the locale (italian in this case) and passing it on to the Capybara driver.

env.rb
1
2
3
4
5
6
7
8
9
10
11
Capybara.default_driver = :selenium

it_profile = Selenium::WebDriver::Firefox::Profile.new
it_profile['intl.accept_languages'] = 'it' # Italian Locale

Capybara.register_driver :selenium do |app|
  Capybara::Selenium::Driver.new(app, :browser => :firefox,
                                      :profile => it_profile)
end

Capybara.current_session.driver.browser.capabilities.firefox_profile = it_profile

The advantage of creating a profile on-the-fly is that the tests do not require every machine to have a pre-configured firefox profile that has the necessary settings.

Read on →

What’s the deal with Ruby GC and Copy-on-write

This post aims at answering the following questions:

  • What is Unix Copy-on-write (COW)
  • Why is current version of ruby (1.x.x) not COW friendly
  • How does the GC packaged with Ruby 2.0 fix that

Holy COW

The fork functionality in Unix systems uses an optimization strategy where memory is shared between the parent and the child processes. The shared memory is maintained till either the parent or one of the children modify their copy of the resource. At that point, a true private copy is created to prevent the changes from being visible to other processes. The primary advantage is that if any of the processes do not make any modifications, no private copy needs to be ever created. This is called Copy-on-write (COW) technique.

1
2
3
4
5
6
7
8
9
shared_array = [1,2,3,4,5]

if fork
  #will be executed by parent process
  parent_array = [6,7,8]
else
  #will be executed by child process
  child_array = [9,10,11]
end
Read on →

3 ways to keep a Linux process alive

Assume that you have a ruby script data_cruncher.rb that will run for a long time. You would like to log into a VM, run the script and keep it running in the background when you log out. Now, I end up writing long running scripts like these all the time and I found the following ways to make them run uninterrupted:

1. Job Control

Job control allows you to interact with background jobs, suspend foreground jobs and manage multiple jobs in a single session. Also, when you later realize that the currently running command must be pushed to the background, job control makes it easy to do that.

  • Start running the process using the command ruby data_cruncher.rb
  • Press ctrl+z to suspend the process
  • type bg to resume it in the background

That’s it. The job will run in the background. Note that using bg command later is the same as running the parent process with & at the end like this: ruby data_cruncher.rb &.

Read on →