OCRA
OCRA (One-Click Ruby Application) builds Windows executables from Ruby source code. The executable is a self-extracting, self-running executable that contains the Ruby interpreter, your source code and any additionally needed ruby libraries or DLL.
ocra [option] script.rb
Will package “script.rb“, the Ruby interpreter and all dependencies (gems and DLLs) into an executable named “script.exe“.
salesking/king_dtaus
DTAUS & DTAZV are formats for German bank transfers and is short for "Datenträgeraustausch". The format itself totally sucks because it was established in the last century, to be used on floppy disks. Still almost all German banks use it (they only seem innovative at robbing), and it is therefore supported in common banking programs too.
This gem saves you all the trouble when generating DTAUS- or DTAZV-text.
Navigating through the browser history in a cucumber feature using selenium
In order to navigate through the browser history. you can manipulate the window.history object via javascript like follows:
When /^I go back in the browser history$/ do
page.evaluate_script('window.history.back()')
end
For further functions of the window and history objects check out this link.
An improved version of this step is now part of our gem spreewald on Github.
Authorize allowed values with assignable_values
All our projects have enum-like requirements like this:
- An attribute value must be included in a given set of values.
- The list of allowed values must be retrievable in order to render
<select>
boxes. - Each value has a humanized label.
- Sometimes there is a default value.
Most of the time, this requirement is also needed:
- The list of assignable values depends on the user who is currently signed in.
In our past projects there are many different solutions for these related requirements, e.g. ChoiceTrait
, methods like `available_...
How to fix Passenger "Unexpected end-of-file detected" error
This is for you if Passenger gives you the following useless error message.
Passenger encountered the following error:\
The application spawner server exited unexpectedly: Unexpected end-of-file detected.
- Exception class:
- PhusionPassenger::Rack::ApplicationSpawner::Error
Most often this happens because you are missing a gem. Usually Passenger would tell you about that but in some cases it can't.
To resolve this issue, run:
bundle install
If this does not do the trick for you, take a look at the Apache log files for de...
Building Gem 'RedCloth' with Bundler and GCC 4.6
If you cannot install the gem 'RedCloth' via bundle install you might want to try the following.
Specifying extra build options for bundler which will only be applied when building RedCloth:
bundle config build.RedCloth --with-cflags=-w
Shell script to deploy changes to production and not shoot yourself in the foot
Geordi, our collection of command line tools, has been extended by another command deploy-to-production
. This script encapsulates the following workflow:
- Pull the production branch.
- Show which commits from the master would make it to production with this deploy.
- Ask if you want to proceed.
- If yes, merge the master into the production branch, push and deploy with
bundle exec cap production deploy:migrations
The script will ask you for the names of your master branch, production branch an...
Fix warning: Cucumber-rails required outside of env.rb
After installing Bundler 1.1 you will get the following warning when running tests:
WARNING: Cucumber-rails required outside of env.rb. The rest of loading is being defered until env.rb is called.\
To avoid this warning, move 'gem cucumber-rails' under only group :test in your Gemfile
The warning is misleading because it has nothing to do with moving cucumber-rails
into a :test
group. Instead you need to change your Gemfile
to say:
gem 'cucumber-rails', :require => false
Connecting the "sequel" gem to MSSQL via ODBC
After you configured your ODBC describe in
- Fix [RubyODBC]Cannot allocate SQLHENV when connecting to MSSQL 2005 with Ruby 1.8.7. on Ubuntu 10.10
- and Connecting to MSSQL with Ruby on Ubuntu - lambie.org
you can connect with sequel
:
require "rubygems"
require "se...
Fix [RubyODBC]Cannot allocate SQLHENV when connecting to MSSQL 2005 with Ruby 1.8.7. on Ubuntu 10.10
I followed this nice guide Connecting to MSSQL with Ruby on Ubuntu - lambie.org until I ran in the following errors:
irb(main):001:0> require "dbi"; dbh = DBI.connect('dbi:ODBC:MyLegacyServer', 'my_name', 'my_password')
DBI::DatabaseError: INTERN (0) [RubyODBC]Cannot allocate SQLHENV
from /usr/lib/ruby/1.8/dbd/odbc/driver.rb:36:in `connect'
from /usr/lib/ruby/1.8/dbi/handles/driver.rb:33:in `connect'
from /usr/lib/ruby...
Make your Rails console (and irb) output better readable
Pour color on your Rails console with awesome_print. Turn confusing long strings into formatted output. Have objects and classes laid out clearly whenever you need it.
Put gem 'awesome_print', :group => :development
into your Gemfile. Now on the Rails console you have the command ap
that will give you a colored, formatted output of whatever you pass it. See the example output of the User
class below.
For customization visit the repository on Github.
 with native extensions
/usr/local/lib/site_ruby/1.8/rubygems/installer.rb:483:in `build_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)
/usr/bin/ruby1.8 extconf.rb
checking for curl/curl.h in /opt/local/include,/opt/local/include/curl,/usr/include/curl,/usr/include,/usr/include/curl,/usr/local/include/curl... no
need libcurl
You can fix it by installing the libcurl3-dev
package:
sudo apt-get install libcurl3-dev
Now you should...
Setup or update Passenger to use Ruby Enterprise
- Your current
ruby
must be Ruby Enterprise. gem install passenger
passenger-install-apache2-module
- Edit your
httpd.conf
according to the instructions provided at the end of the setup script. - Restart Apache:
sudo service apache2 restart
This also works when you previously ran your Passenger using MRI. Just run the setup as described.
Gherkin: Error during installation
When trying to install the gherkin gem, you might encounter an error with the following lines:
ERROR: Error installing gherkin:
ERROR: Failed to build gem native extension.
...
checking for main() in -lc... yes
creating Makefile
...
cc1: all warnings being treated as errors
Makefile:150: recipe for target 'gherkin_lexer_ar.o' failed
make: *** [gherkin_lexer_ar.o] Error 1
...
If upgrading is not an option, configure build options for gherkin
:
bundle config --local build.gherkin --with-cflags=-w
Your .bundle/config
fi...
Compare two XML strings as hashes
Let's say you have two XML strings that are ordered differently but you don't care about the order of attributes inside containers:
a = '<?xml version="1.0" encoding="UTF-8"?><Authenticate><User>batman</User><Password>secret</Password></Authenticate>'
b = '<?xml version="1.0" encoding="UTF-8"?><Authenticate><Password>secret</Password><User>batman</User></Authenticate>'
Working with plain string comparison is not helpful, of course:
a == b
=> false
Instead, you can use the Nori gem ...
WebMock 1.8.0 does not play nice with Curb < 0.7.16
When updating WebMock, be prepared that your specs may send real requests into the depths of the internet unless you update Curb as well.\
WebMock will not complain about those requests not being stubbed.
One of the commits that made it into 1.8.0 actually breaks Curb versions below 0.7.16 while fixing it for that version (and above, hopefully).\
WebMock's hooks for Curl::Easy
are sti...
Sunspot and Solr on Tomcat: Trouble with Umlauts
We experienced problems with Sunspot and Solr on Tomcat: Umlauts (ä, ö, ü) were not correctly handled on Tomcat while everything was okay on the local development machines (your local Sunspot service you start with the sunspot:solr:run
task is based on Jetty).
We use a stemmer that reduces "Sänger" to "sang" and "Sanger" to "sang" as well.
Though, results for "Sänger" where empty on Tomcat.
This is due to a UTF-8 bug in RSolr (see Github for some discussion on that).
The bug is fixed in a ...
Issues with has_select?
The handy method has_select?(field, :selected => text)
does not behave as expected with Cucumber 0.10.2, Capybara 0.4.1.2 and Selenium 0.2.2. It may not recognize a select field if the selected option
with the text
has no value. If you don't have the possibility to upgrade these Gems, probably the best way to go is to distinguish the current Capybara driver:
Then /^"([^"]*)" should be selected for "([^"]*)"(?: within "([^\"]*)")?$/ do |value, field, selector|
with_scope(selector) do
# currently needed due to different behav...
Fix YAML::Syck::DefaultKey:0x1083b59f8
When your gems complain about invalid gemspecs and illformed requirements, it is most probably an error resulting from the transition from Syck
to psych
. To fix this:
- go to your gemspec directory (e.g.
/Library/Ruby/Gems/1.8/specifications/
) - change
#<Syck::DefaultKey:0x00000100e779e8>
to=
(equals sign) in each file that's complaining
Cucumber step to test that a tooltip text exists in the HTML
Tooltips that are delivered through HTML attributes are encoded. Decode entities before checking for their presence.
Capybara:
Then /^there should( not)? be a(n encoded)? tooltip "([^"]*)"$/ do |negate, encoded, tooltip|
tooltip = HTMLEntities.new.encode(tooltip) if encoded
Then "I should#{negate} see \"#{tooltip}\" in the HTML"
end
Note
This step uses the htmlentities gem described in another card.
Ma...
Look up a gem's version history
Sometimes it might be helpful to have a version history for a gem, e.g. when you want to see if there is a newer Rails 2 version of your currently used gem.
At first you should search your gem at RubyGems. Example: will_paginate version history.
The "Tags" tab at GitHub might be helpful as well.
How to create Excel sheets with spreadsheet gem and use number formats for cells like money or date
The following snippet demonstrates how you could create excel files (with spreadsheet gem) and format columns so that they follow a specific number format like currencies or dates do.
require 'rubygems'
require 'spreadsheet'
Spreadsheet.client_encoding = 'UTF-8'
book = Spreadsheet::Workbook.new
sheet1 = book.create_worksheet :name => 'test'
money_format = Spreadsheet::Format.new :number_format => "#,##0.00 [$€-407]"
date_format = Spreadsheet::Format.new :num...
Using Solr with Sunspot
This describes all the steps you'll need to get Solr up and running for your project using the Sunspot gem.
Prepare Sunspot on your development machine
What you want in your Gemfile:
gem 'sunspot_rails'
gem 'sunspot_solr'
gem 'progress_bar' # for sunspot:solr:reindex
Now define what should be indexed within Solr from your ActiveRecord models, e.g.,
class Article << ActiveRecord::Base
searchable do
text :title
...