Simple database lock for MySQL

Posted About 13 years ago by Tobias Kraze.

Note: For PostgreSQL you should use advisory locks. For MySQL we still recommend the solution in this card.

RSpec < 2.11: ActiveRecord scopes must be loaded before using the "=~" matcher

Posted About 13 years ago by Henning Koch.

To test whether two arrays have the same elements regardless of order, you can use the =~ matcher in RSpec < 2.11...

Test that a select field contains an option with Cucumber

Posted About 13 years ago by Henning Koch.

This note describes a Cucumber step definition that lets you say: Then "Mow lawn" should be an option for "Activity...

Fix errors when rendering PDF output

Posted About 13 years ago by Arne Hartherz.

If you run specs or your application and get an error like: ActionController::MissingFile in 'ProductsController#show, should render PDF...

babushka: test-driven sysadmin

Posted About 13 years ago by Lexy.
babushka.me

The idea is this: you take a job that you'd rather not do manually, and describe it to babushka...

Testing if two date ranges overlap in Ruby or Rails

Posted About 13 years ago by Henning Koch.

A check if two date or time ranges A and B overlap needs to cover a lot of cases:

Rails: When defining scopes with class methods, don't use `self`

Posted Over 13 years ago by Henning Koch.

Sometimes it is useful to define a named scope by implementing a static method with the scope's name on...

Split an array into groups

Posted Over 13 years ago by Henning Koch.

Given group size If you would like to split a Ruby array into pairs of two, you can use the...

Test the status code of a response in Cucumber

Posted Over 13 years ago by Henning Koch.

Then /^I should get a response with status (\d+)$/ do |status| response.status.should include(status) end Capybara Then /^I should...

Perform HTTP basic authentication in Cucumber (with or without Selenium)

Posted Over 13 years ago by Henning Koch.

This card describes a Cucumber step that lets you say: When I perform basic authentication as "username/password" and I visit...

How to define constants with traits

Posted Over 13 years ago by Arne Hartherz.

When defining a trait using the Modularity gem, you must take extra steps to define constants to avoid caveats (like...

Setting up Tomcat to use an existing OpenSSL certificate

Posted Over 13 years ago by Arne Hartherz.

This is for those who already own an SSL certificate (e.g. using it in the Apache HTTP Server) and need...

Speed up RSpec by deferring garbage collection

Posted Over 13 years ago by Henning Koch.

Update: This trick probably isn't very useful anymore in Ruby 2.x. The Ruby GC has improved a lot...

Silencing Deprecation Warnings in Rspec

Posted Over 13 years ago by Lexy.
justinfrench.com

If you’re testing the behavior of deprecated code in your Ruby project, the warning messages littered throughout your spec...

How to: Use git bisect to find bugs and regressions

Posted Over 13 years ago by Arne Hartherz.
kernel.org

Git allows you to do a binary search across commits to hunt down the commit that introduced a bug.

Test a download's filename with Cucumber

Posted Over 13 years ago by Henning Koch.

These steps are now part of Spreewald. The step definitions below allow you to test the filename suggested by the...

Test the content-type of a response in Cucumber

Posted Over 13 years ago by Henning Koch.

The step definitions below allow you to write this in both Webrat and Capybara: When I follow "Download as PDF...

Cucumber steps to test input fields for equality (with wildcard support)

Posted Over 13 years ago by Henning Koch.

Our collection of the most useful Cucumber steps, Spreewald, now supports exact matching of form fields and lets you use...

Apache: Redirect all requests from one host to another

Posted Over 13 years ago by Henning Koch.

In order to redirect all requests from redirecting-host.com to desired-host.com while keeping path and query params unchanged, change your Apache...

Parametrized shared example groups in RSpec

Posted Over 13 years ago by Henning Koch.

In RSpec 2 shared_examples_for can have parameters. You can simply hand over arguments from it_should...

Inspect the page content in a Cucumber session

Posted Over 13 years ago by Arne Hartherz.

When you need to see the content of a page (i.e. not all the HTML but the relevant text body...

RSpec matcher to check if two numbers are the same

Posted Over 13 years ago by Henning Koch.

You can usually just use the eq matched to compare two numbers: expect(deal.total).to eq(120)

Test that an exception or error page is raised in Capybara

Posted Over 13 years ago by Henning Koch.

You can use these step definitions: Then /^I should not see an error$/ do (200 .. 399).should include(page.status_code...

Preloaded associations are filtered by conditions on the same table

Posted Over 13 years ago by Arne Hartherz.

When you eagerly load an association list using the .include option, and at the same time have a .where on...