...external URL (like http://somehost.com/some/path) you will find that this is hard to test with Cucumber and Capybara: A non-Javascript Rack::Test scenario will just ignore the host...

...and try to open /some/path in your local application A Selenium test will actually follow the redirect, which you probably don't want either There are two workarounds for this...

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...

...a script that helps you create an unchanging version of Firefox for your Selenium tests. In particular, this new copy of Firefox will have the following properties:

Once the setup process has completed, you have two Firefoxes: One for Selenium tests, one for regular browsing. You can now update your regular Firefox without fear of Selenium...

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...

jetmore.org

swaks is a very nice tool to test SMTP. For the most linux distributions you can easily install it with your package management system. This example send an email from...

...Date: Mon, 04 Nov 2013 15:56:19 +0100 ~> To: to@example.com ~> From: from@example.com ~> Subject: test Mon, 04 Nov 2013 15:56:19 +0100 ~> X-Mailer: swaks v20111230.0 jetmore.org/john/code/swaks/ ~>

makandra dev

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...

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...

makandra dev

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...

Summary: Don't add chromedriver-helper to the Gemfile the executables might break your tests in projects where chromedriver-helper is not in the Gemfile developers with different chrome versions...

...the chromedriver-helper gem, but don't have it in you Gemfile, your selenium tests might fail with: Selenium::WebDriver::Error::WebDriverError: unable to connect to chromedriver 127.0.0.1:9515

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...

You might not know that Rails disables CSRF protection in tests. This means that if you accidentally forget to send the CSRF token for non-GET requests, your tests will...

To test that an object was constructed by a given constructor function, use jasmine.any(Klass): describe('plus()', function() { it ('returns a number', function() { let result = plus(1, 2) expect(result...

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...

...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...

...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