Our rcov:all task for aggregated RSpec/Cucumber coverage was overhauled extensively. Among other things it now works for Rails 2...
...app such as PHP, Perl, Java / JEE, etc. I like using cucumber for functional testing so I put together this project structure to use as a starting point for testing...
jqueryElement.is(':checked')
...this article we’ve listed 7 fresh and simple tools for cross-browser compatibility testing, tools that actually make this stuff pretty easy. Not only that, but every single one...
Celerity is a JRuby wrapper around HtmlUnit – a headless Java browser with JavaScript support. It provides a simple API for...
What do we expect from the custom finder? We expect that it should find assets A, B, C and should...
When testing with Cucumber / Caypbara, iframes are ignored, so you can't interact with them. To interact with your iframe, you have to explicitly tell your driver to use it...
Geordi now supports our solution for running Selenium tests without having Firefox or Chrome windows popping up all over your workspace. This will stop Selenium windows from appearing on your...
...you want to spy on a function that is imported by the code under test. This card explores various methods to achieve this. Example We are going to use the...
// client.js import { hello } from 'lib' function helloTwice() { hello() hello() } export helloTwice In our test we would like to show that helloTwice() calls hello() twice. We find out that it...
Validations should be covered by a model's spec. This card shows how to test an individual validation. This is preferrable to save an entire record and see whether it...
Recipe for testing any validation In general any validation test for an attribute :attribute_being_tested looks like this: Make a model instance (named record below) Run validations...
...ETags can again match. Before I make this change I like to add a test that ensures I did it correctly. For this add the following code to spec/requests/default_etag_spec.rb. You...
...ActionView::Base).to receive(:image_path).and_return('image') # CSRF protection is disabled in tests by default. Activate it for this spec as # randomly masked CSRF tokens are a major...
When filling out forms in Selenium tests, Chrome shows the (usual) bubble, asking to store those credentials. While the bubble does not interfere with tests, it is annoying when debugging...
...tests. Here are two ways to disable it: Option 1: prefs You can set profile preferences to disable the password manager like so: prefs = { 'credentials_enable_service' => false, 'profile.password_manager...
item 2 This card compares various approaches to fabricating DOM elements for testing. Constructing individual elements While you can use standard DOM functions to individually create and append...
A very visual method is to embedded a string of HTML into your test. My specs often have a function htmlFixtures() that parses the HTML and returns a reference...
...or when working on a project without LoDash. Booleans This one is straightforward to test with typeof: x = true typeof x === 'boolean' // => true Strings Strings can exist as literal ("foo...
...we cannot rely on typeof: typeof "foo" // => "string" typeof new String("foo") // => "object" Your test should check both forms: x = 'foo' typeof x === 'string' || x instanceof String // => true Numbers
Try to break your refactoring down in different parts. Try to make tests green for each part of your refactoring as soon as possible and only move to...
...the next big part if your tests are fixed. It's not a good idea to work for weeks or months and wait for all puzzle pieces to come together...
...should extract that behavior into a trait or module. This card describes how to test that extracted behavior without repeating yourself. Note that the examples below use Modularity traits to...
...app/models/page.rb class Page < ApplicationRecord include DoesSanitizeHtml end # app/models/template.rb class Template < ApplicationRecord include DoesSanitizeHtml end Testing test trait usage with a shared example group When two classes share behavior through a...
...Understand the gem Make your changes Bump the version number Update the changelog Run tests and commit Make a pull request, or release the gem Let's look at these...
...version switch, an "if Rails version < 4 do this, else do that". Gemika (see Tests below) can help you with that, but still keep these parts as short as possible...
...return means "exit the lambda" How to define a lambda With the lambda keyword test = lambda do |arg| puts arg end With the lambda literal -> (since Ruby 1.9.1)
...also are next and continue How to define a block With the proc keyword: test = proc do |arg| puts arg end With Proc.new: test = Proc.new do |arg| puts arg
...text-transform: uppercase - especially on form labels - can cause you serious headaches in Selenium tests. Sometimes the web driver will see the uppercase text, sometimes it won't, and umlauts...
...will be a problem as well. Simply disable it in tests, by adding a body class for tests %body{'data-environment' => Rails.env} overriding the transforms [data-environment="test"] * text-transform...
...present. Otherwise, the browser uses its local time. This can lead to issues in tests with mocked time or inconsistent cache behavior. Cookie Expires depends on the Date header or...
...lead to unexpected issues in specific scenarios. Why does this matter? Mocked time in tests Consider a Rails application where you use the remember_me feature of Clearance for authentication...
Sometimes you have a test expectation but actually want a better error message in case of a failure. Here is how to do that. Background Consider this test: expect(User.last...
expect(User.last).to be_present, 'Could not find a user!' Now your test will fail with an actually helpful error message: Could not find a user! (Spec::Expectations...
Prefer request specs over end-to-end tests (Capybara) to joyfully test file downloads! Why? Testing file downloads via Capybara is not easy and results in slow and...
...fragile tests. We tried different approaches and the best one is just okay. Tests for file downloads via Capybara ... ... are slow, ... are fragile (breaks CI, breaks if Selenium driver changes...