RSpec lets you define the arguments with which you expect a method to be invoked: subject.should_receive(:say).with('hello...

Calling #gsub on a string that was previously marked as #html_safe will lead to unexpected behavior. E. g. backreferences...

github.com

Looks simpler than inaction_mailer: gem install mailcatcher mailcatcher Setup Rails to send mails to 127.0.0.1:1025. Usually you want...

Defining a custom to_json method for your classes can be useful. Do it properly or you will "randomly" get...

When you require the Ruby debugger to be available from your Rails console (e.g. you want to inspect a method...

When adding a new field to your model's database table, don't set any defaults in the database.

Oniguruma is an advanced regular expression engine for Ruby. Install Oniguruma with binary dependencies like this: sudo apt-get install...

makandra dev

Never use raise_error without specifying the Error you expect. expect { do_a_lot_of_complicated_stuff }.to raise_error...

The technique described in this card has an important caveat: The result of GROUP_CONCAT is truncated to the maximum...

You can use heredoc to avoid endlessly long lines of code that nobody can read. Heredoc strings preserve linebreaks and...

If Rails or Rake are complaining about a missing gem that is listed in your Gemfile.lock and the listed version...

Sometimes you want to use a vanilla Ruby method like a block. You can use Object#method to obtain a...

regular-expressions.info

This article explains why some regular expressions take years to match against certain strings. A common culprit are nested repetition...

stackoverflow.com

Most likely you run rake and your code is causing an exception which is not the one shown in your...

Consider you have a website vhost listening to www.example.com, redirecting all incoming requests that do not talk about the configured...

github.com

ExecJS lets you run JavaScript code from Ruby. It automatically picks the best runtime available to evaluate your JavaScript program...

makandra dev

We forked craken today and fixed one of the issues we had with new (>0.8.7) rake versions. The craken:install...

The state_machine gem comes with a rake task that lets you generate PNG graphs from any model using state...

blog.rubybestpractices.com

class Errormaster CoffeeIsOut = Class.new(StandardError) # is prettier than class CoffeeIsOut < StandardError; end end Reference such an error class with Errormaster...

You can create a Regexp object from existing Regexp objects by using the interpolation syntax you know from strings:

Observed on Rails 2.3 and machinist 1.0.6 Like the title says, when you define the method empty? like in the...

stackoverflow.com

These methods are available to you: page.driver.browser.switch_to.alert.accept page.driver.browser.switch_to.alert.dismiss page.driver.browser.switch_to.alert.text # the confirmation text Spreewald gives you steps like these:

github.com

Grit gives you object oriented read/write access to Git repositories via Ruby.

Ever wondered how Rails talks to itself in a Cucumber feature? In Rails 3 you can do it like this...