mattheworiordan/capybara-screenshot

Using this gem, whenever a Capybara test in Cucumber, Rspec or Minitest fails, the HTML for the failed page and a screenshot (when using capybara-webkit, Selenium or poltergeist) is saved into $APPLICATION_ROOT/tmp/capybara.

Link via Binärgewitter Podcast (German).

BrowserStack has browser plugins for local testing

Local testing allows you to test your private and internal servers using the BrowserStack cloud, which has support for firewalls, proxies and Active Directory.

Stubbing out external services with an embedded Sinatra application

One of many useful techniques when your test suite needs to talk to a remote API.

mattheworiordan/capybara-screenshot

Takes a screenshot when you call it, or when a test fails.

responsive.is

Online tool to test how a site behaves in popular desktop, tablet and phone resolutions.

colszowka/simplecov - GitHub

Code coverage for Ruby 1.9 with a powerful configuration library and automatic merging of coverage across test suites.

Note that rcov won't ever have support for Ruby 1.9, you're supposed to use rcov for 1.8 and simplecov for 1.9.

Cucumber.yml was found, but could not be parsed.

If you encounter the error message above when running cucumber, just execute...
rm rerun.txt
...in the Rails directory.

Or run...
tests
...from the geordi gem. This will do the work for you automatically.

ActiveSupport::StringInquirer

Wrapping a string in this class gives you a prettier way to test for equality.

plus2/whereuat - GitHub

Adds a slide out panel to your Rails application that directs clients to test stories that have been marked as 'delivered' in Pivotal Tracker.

Run a rake task in all environments

Use like this:

power-rake db:migrate VERSION=20100913132321

By default the environments development, test, cucumber and performance are considered. The script will not run rake on a production or staging environment.


This script is part of our geordi gem on github.

defunkt's fakefs at master - GitHub

A fake filesystem. Use it in your tests.

Railscheck project home page

This project is (or will be) a best effort semi-static verifier for your Ruby on Rails projects. Delivered as a Ruby gem it provides a shell command task "railscheck" that you can run against your Rails projects to test for a number of typical bugs, potential problems and inconsistencies.

Integrity | The easy and fun automated continuous integration server

Integrity is the angel watching over your shoulder while you code. As soon as you push your commits, it builds, runs your tests, and makes sure everything works fine.

mdub's sham_rack at master - GitHub

Or, you can test your Rack application (or Sinatra, or Rails, or Merb) using arbitrary HTTP client libraries, to check interoperability.

citrusbyte's contest at master - GitHub

Write declarative tests using nested contexts without performance penalties. Contest is less than 100 lines of code and gets the job done.

thumblemonks's riot at master - GitHub

Riot differs primarily in that it does not rerun setup for each test in a context.

Unit Testing Achievements

  • Unlock achievements for running your test suite!

Localized external services - GIANT ROBOTS SMASHING INTO OTHER GIANT ROBOTS

ShamRack mounts a Rack app locally, just for your tests. It goes one further: it “mounts” it using Net::HTTP such that requests to the Rack app never hit any network.

mynyml's holygrail at master - GitHub

The Holy Grail of testing for front-end development; execute browser-less, console-based, javascript + DOM code right from within your Rails test suite.

Waiting for page loads and AJAX requests to finish with Capybara

If you're using the Capybara webdriver, steps sometimes fail because the browser hasn't finished loading the next page yet, or it still has a pending AJAX request. You'll often see workarounds like

When I wait for the page to load
Then ...

Workarounds like this do not work reliably, will result in flickering tests and should be avoided. There is no known reliable way to detect if the browser has finished loading the page.

Solution

Instead you should wait until you can observe the result of a page load. E.g. if y...

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

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

actual_array.should =~ expected_array

If either side is an ActiveRecord scope rather than an array, you should call to_a on it first, since =~ does not play nice with scopes:

actual_scope.to_a.should =~ expected_scope.to_a

If you use RSpec >= 2.11 we recommend using the match_array or contain_exactly matchers instead of =~.
Use the eq matcher only if the order of records matters.

RSpec: Expect one of multiple matchers to match

RSpec let's you chain a matcher with .or. The expectation will then pass if at least one matcher matches:

expect(color).to eq("red").or eq("green")

Real-world example

A real-world use case would be to test if the current page has a button with the label "Foo". There are many ways to render a button with CSS:

<input type="button" value="Foo">
<input type="submit" value="Foo">
<button>Foo</button>

We cannot express it with a single have_css() matcher, since we need the { text: 'Foo' } optio...

Don't use migrations to seed default data

Don't insert table rows in a Rails database migration. This will break tests that expect that database to be empty and cause you all sorts of pain.

If you need a place for default application data, use db/seed.rb or put a script into lib/scripts. It won't run automatically, so add a chore story to Pivotal Tracker as a reminder.

Sync confidential files between unixes using cloud storage and encfs

Note: You might also want to check out BoxCryptor which does pretty much the same, and is supported across many more platforms. I just didn't want to use Dropbox...

I use Ubuntu One to automatically sync confidential files between my machines. The encryption is done via encfs, which is a file-based encryption that simply puts encrypted versions of files from one folder into another. This is well-suited for cloud storage, since it allows syncing single files, not whole crypt containers.

Recipe

I'll ass...