Instead of running all missing migrations on your test database with rake db:migrate RAILS_ENV=test you can also use a handful of rake tasks to prepare the database...
...structure directly. They can produce different results, though. In a nutshell, to ensure your test database gains the correct structure: Don't use rake db:test:prepare carelessly
...it has not yet recorded. Some signs an error is caused by randomness The test is green on a single run but red when run in parallel
...always green on recording but red when the cassette is used The test is green on one day and red the following day Finding the randomness Taking a close look...
To run a single test file: rake test:units TEST=test/unit/post_test.rb rake test:functionals TEST=test/functional/posts_controller_test.rb rake test:integration TEST=test/integration/admin_news_posts_test.rb You may even run a single test method:
...I test test/unit/post_test.rb -n "name of the test" ruby -I test test/functional/posts_controller_test.rb -n test_name_of_the_test # underscored, prefixed with 'test_' Or all tests matching a regular expression:
...when two focus-sensitive Selenium scenarios run at the same time (probably with parallel_tests). This can help you to detect and fix flickering integration tests. The attached feature works...
...you'll see). Default is 5 minutes. It should be longer than your flickering tests take to run. Make sure that your root_path contains a form element (select, input...
...a habit of using this regularly, as it has high potential to make your tests hard to read and understand. You're often better of by using factories, generally different...
...implementation patterns, or just duplicating some of your tests' code. In some situations this has benefits, like making complex setups simpler if you want to modify only one aspect.
...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...
...afterwards again. CSSnext Input: body { font-variant: small-caps; background-image: image-set(url(test_1.svg) 1x, url(test_2.svg) 2x); } Output: body { -webkit-font-feature-settings: "c2sc"; font-feature-settings: "c2sc...
...font-variant: small-caps; background-image: -webkit-image-set(url(test_1.svg) 1x, url((test_2.svg) 2x); background-image: image-set(url(test_1.svg) 1x, url(test_2.svg); } Autoprefixer Input: body { ::placeholder { color: gray...
...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...
...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...
The Basic Authentication header encodes username and password. Effectively, it's just Base64 plus a "Basic" prefix.
Possible Reason 1: parallel_tests - running more processes than features If you run old versions of parallel_tests with more processes than you have Cucumber features, you will get errors...
...The bug is fixed in versions 0.6.18+. Possible Reason 2: You are running parallel tests but you are using an (probably old) database.yml which is not setup for parallel tests...
...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...
We are using Spring in our tests for sequential test execution but not for parallel test execution. And Rails requires you to set the config.cache_classes = false if you are...
...using Spring in tests. With our setup, this would raise the following error in cucumber-rails for parallel test executions due to some legacy database cleaner issue. WARNING: You have...
...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...
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...
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...
Large projects usually have large test suites that can run for a long time. This can be annoying as running tests blocks you from picking up the next story -- but...
...simply push that branch and check it out on your 2nd copy to run tests there. You can pick up a new story and work on that on your "main...
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...
You know that Devise offers RSpec test helpers for controller specs. However, in request specs, they will not work. Here is a solution for request specs, adapted from the Devise...
...wiki. We will simply use Warden's test helpers -- you probably already load them for your Cucumber tests. First, we define sign_in and sign_out methods. These will behave...
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 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...
...start playing video or audio. E.g. if you attempt to call video.play() in a test, the call will reject with a message like this: NotAllowedError: play() failed because the user...
...with the document first. https://goo.gl/xX8pDD Workaround To pretend document interaction in a test you can create an element, click on it, and remove the element again. This unblocks...
Capybara drivers will usually delete all cookies after each scenario. If you need to lose cookie data in the middle...