Unfortunately, Capybara does not offer a switch to disable cookies in your test browser. However, you can work around that by using a tiny Rack middleware -- it works for both...

...Selenium and non-Selenium tests. Wouldn't it be nice to say something like this? Given cookies are disabled When I try to sign in Then I should see "Can...

...Here is a snippet that shows the current settings and lets you send a test mail directly from the console: mailer = ActionMailer::Base.new # check settings: mailer.delivery_method # -> :smtp mailer.smtp_settings...

...authentication: nil, enable_starttls_auto: true } # send mail: mailer.mail(from: 'sender@example.com', to: 'recipient@example.com', subject: 'test', body: "Hello, you've got mail!").deliver You could use this to test the spam...

Geordi uses parallel_tests if available for running the test suite. To debug an application it is very unhandy to have multiple processes as your terminal I/O will not work...

...as expected once a breakpoint is hit. Even parallel_tests support an option to enable a single process run, it is not possible to pass this option through geordi. But...

To test concurrent code, you will need to run multiple threads. Unfortunately, when you use blocking system calls (e.g. locks on the database), Ruby 1.8 threads won't work because...

@writer.puts "Started: #{i}" sleep 0.01 @writer.puts "Finished: #{i}" end @writer.close end end @writer.close # test whether we always get alternating "Started" / "Finished" lines lines = @reader.lines.to_a lines.should be_present # it...

...wait until one of the two requests is finished. Concurrent requests in development and tests Normally having multiple threads for development is fine. Puma can handle blocking threads e.g. when...

...count = Integer(ENV['RAILS_MAX_THREADS'] || 5) Note: Having multiple workers in development and tests might cause unexpected issues (database transactions and other shared states), you should not enable it...

RSpec 1, RSpec 2 To test whether two arrays have the same elements regardless of order, RSpec 1 and 2 give you the =~ matcher: actual_array.should =~ expected_array Rspec 3

...array takes an argument, but contain_exactly takes a list of elements as varargs. Test::Unit If you install shoulda-matchers you can say: assert_same_elements([:a, :b, :c...

This is an awful way to test whether a number is shown on the screen: Then I should see "5" It is awful because the step above is green for...

...see the number 5 The step also works if you you'd like to test that the number is followed by a unit: Then I should see the amount...

sudo gem install parallel script/plugin install git://github.com/grosser/parallel_tests.git Adapt config/database.yml test: database: xxx_test<%= ENV['TEST_ENV_NUMBER'] %> Create test databases script/dbconsole -p CREATE DATABASE `xxx...

... Generate RSpec files script/generate rspec (you'll probably only let it overwrite files in script/) Prepare test databases Now and after each migration: rake parallel:prepare Run tests

...you are writing to the cookie more than once, but when doing so, integration tests (Cucumber) may break for you with this error: You have a nil object when you...

You want to test your 1GE or 10GE internet uplink? We needed to ensure we have full 10GE to the backbone for a customer project. Using netcat To test whether...

...pending Cucumber step (or feature) that also uses an existing VCR cassette, your pending test may fail at the very end with an error like this: There are unused HTTP...

...your VCR is configured to complain about cassettes that contain extra requests which your test did not use. This is often a good configuration. If you do not want to...

We are maintaining some vintage projects with tests written in Test::Unit instead of RSpec. Mocks and stubs are not features of Test::Unit, but you can use the Mocha...

Aruba is an extension to Cucumber that helps integration-testing command line tools. When your tests involve a Rails test application, your tool's Bundler environment will shadow that of...

...the test application. To fix this, just call unset_bundler_env_vars in a Cucumber Before block. Previously suggested solution Put the snippet below into your tool's features/support/env.rb -- now...

...by "regular" browsers, search engine crawlers, or other web client software. Cucumber In Rack::Test, you can set your user agent like this on Capybara: Given /^my user agent is...

...User-Agent', agent) # Or, for older Capybaras: # page.driver.header('User-Agent', agent) end For Selenium tests with Firefox, it seems you can set the general.useragent.override profile setting to your preferred value...

...write the password hash to a file: echo firstname.lastname:$2y$05$4JXxd2GM/J2...9c3KJmFS > htpass_test Check, if it is correct: htpasswd -v htpass_test firstname.lastname You probably should not use...

You can set the resolution and user agent used in selenium tests with chrome with the method described in this card, but you can also set the accept-language and...

Use the following command to test if a server (in this example: makandra.com on port 443) uses Perfect Forward Secrecy (PFS): openssl s_client -connect makandra.com:443 -cipher ECDHE-RSA-RC4...

end Note that you need to tag the scenario with @allow-rescue to test that an error is shown like this @allow-rescue Scenario: Accessing the admin area requires...

...don't provide canditional validations (validations with if: option). Here is how to write tests for the condition: Class: class Employee < ActiveRecored::Base validates :office, presence: true, if: manager?

... end end Test: describe Employee do describe '#office' do context 'is a manager' do before { allow(subject).to receive(:manager?).and_return(true) } it { is_expected.to validate_presence_of(:office...

TLDR: In tests you need to clean out the database before each example. Use :transaction where possible. Use :deletion for Selenium features or when you have a lot of MyISAM...

Understanding database cleaning You want to clean out your test database after each test, so the next test can start from a blank database. To do so you have...

...option is available, not that it is selected. There is a separate step to test that an option is selected. Capybara (0.4.1 or higher) Then /^"([^"]*)" should( not)? be an option...

...a machine by sending an e-mail you can run the following: mail -s Test someone@example.com < /dev/null This will send an empty e-mail with "Test" as its subject to...

...someone@example.com. If you want it to contain a message body, call mail -s Test someone@example.com only; the mail application will then read your input from stdin. Finish your message by...

...when it was called during browser interaction in development but doesn't make the test fail. The reason Development autoloading isn't smart enough to find the referenced class

...other environments (test, staging, production) autoloading is disabled, that all classes are already loaded when browser interaction takes place what makes rails able to find the class even without the...

...work the way you how you would like it to. To create a nice test coverage report, copy the attached file to lib/tasks/rcov.rake. After that rake rcov:all will run...

...app/controllers/shared and app/models/shared (which may or may not be entirely correct for your case). Tested that it works with Selenium features Doesn't add rake tasks outside development environment