When your Cucumber feature seems to forget cookies / sessions when you run it with Selenium or capybara-webkit, check if the test travels in time like here:
Given the date is 1981-10-20 When I sign in Then I should see "Welcome!"
What happens here is that the Rails application serving pages runs in 1984, but the process running your Firefox or Webkit still lives today. This gap of 27+ years will expire most Cookies immediately.
If all you need is to freeze the time to a date, a workaround is to travel to the future instead.
When you print (or print preview) and elements are cut off (e.g. after 1st page, or "randomly") you should check your CSS rules for these:
Is there an element with "
display: inline-block" that surrounds your content? Make sure it has "
display: block" for printing.
This primarily affects Firefox and Internet Explorer. Chrome seems to be able to handle
inline-block elements in most cases.
Does the element itself, or a container, define "
overflow: hidden"? Use "
overflow: auto" (or maybe "
overflow: visible") instead.
Cookies without an expiration timestamp are called "session cookies".  They should only be kept until the end of the browsing session.
However, when Chrome or Firefox are configured to reopen tabs from last time upon start, they will keep session cookies when closing the browser. This even applies to tabs that were closed before shutting down the browser.
This is by design in Chrome and [Firefox](https://bugzilla.mozilla.org/buglist.cgi?bug_id=337551,345830,358042,362212,36…
By default, browsers will not wrap text at syllable boundaries. Text is wrapped at word boundaries only.
This card explains some options to make browsers wrap inside a long word like
Unicode has a soft hyphen character you can use to mark optional word division opportunities. The soft hyphen is an invisible character with zero width. Only when the browser decides to wrap at a soft hyphen, it is turned in…
reloadUsers() that fetches a HTML snippet from the server using AJAX and replaces the current
.users container in the DOM:
window.reloadUsers = -> $.get('/users').then (html) -> $('.users').html(html)
Testing this simple function poses a number of challenges:
<div class="users">...</div>container in the current DOM. Obviously the Jasmine spec runner has no such container.
/usersand we want to prevent network interaction in our unit test…
PostgreSQL's Common Table Expressions can be used to extract sub-queries from bulky SQL statements into a temporary table to be referenced instead.
This is most useful to avoid ugly joins or sub-selects. CTEs can be used for
Example (from the PostgreSQL docs):
WITH regional_sales AS (
SELECT region, SUM(amount) AS total_sales
GROUP BY region
), top_regions AS (
WHERE total_sales > (SELECT SUM(t…
Like in any language, a
FLOAT will eventually corrupt data due to rounding errors.
DECIMAL, which has well-defined behavior for rounding and range overflows.
Situation: You want to write a spec for a function inside an Angular service. This function at some point makes an API request and acts upon response. Notably, your Angular app employs uiRouter, although it is not used nor actually required for this test.
# Capitalized expressions are intended to be replaced with YOUR values
describe 'SERVICE', ->
module ($urlRouterProvider) -> # Prevent uiRouter's initialization, i.e. do not sync the current URL # with its r...
Internet Explorer until version 9 has some limitations when parsing CSS files
Summarized, these are:
To test the selector limit for a specific browser, check this CSS selector limitation test website.
When you run into this issue, the following links might be helpful to fix the problem. The Idea is to split up the css fi…
HTTPie consists of a single http command designed for painless debugging and interaction with HTTP servers, RESTful APIs, and web services
It easy to use and has very nice defaults and coloured output which makes it good for local testing.
Usage examples with curl equivalent:
# curl post curl --data "foo=23&bar=42" https://example.org/blub # httpie post http https://example.org/blub foo=23 bar=42 # curl localhost curl localhost:3000/users # httpie localhost http :3000/users
git checkout -" you can switch back to the branch you previously worked on.
(master) $ git checkout foobar Switched to branch 'foobar' (foobar) $ git checkout - Switched to branch 'master' (master) $
This also works with other commands like
(master) $ git checkout foobar Switched to branch 'foobar' (foobar) $ git merge - Merged branch 'master'
PostgreSQL supports the SQL
OVERLAPS operator. You can use it to test if two date ranges overlap:
=> SELECT ('2001-02-16'::date, '2001-12-21'::date) OVERLAPS ('2001-12-20'::date, '2002-10-30'::date); overlaps -------- true
An important caveat is that the date ranges are defined as
start <= time < end. As such the later date is not included in the range:
=> SELECT ('2001-02-16'::date, '2001-12-21'::date) OVERLAPS ('2001-12-21'::date, '2002-10-30'::date); overlaps -------- false
Be careful when using buttons without a
type attribute, since browsers will consider them the default submit button of a form.
Suppose you have this form:
<form action="/save"> <input type="text" /> <button onclick="alert('Alert!')">Alert</button> <button type="submit">Save</button> </form>
If you press the enter key inside in the text input, browsers will trigger the first button and show the alert.
To fix this, add a
type="button" attribute to the first button.
window.opener, if the target is on the same domain.
Even if the target site is on another domain, it still has some access and can for example manipulate
window.location to perform a phishing attack.
You may use a
rel="noopener" attribute to avoid this in modern browsers, except IE or Edge.
If you try to listen to events on elements that are nested inside a
<fieldset disabled>, Firefox will stop event propagation once the event reaches the fieldset. Chrome and IE/Edge will propagate events.
Since we often bind event listeners to
document this can be annoying.
You could solve it by…
<fieldset>, around your eleme…
When writing XLSX files, there are gems like rubyXL or axlsx. While they do offer features like formatting or graphs, to represent spreadsheet cells, they have to keep several Ruby objects in memory. When writing huge files, both will become slow and consume lots of memory.
Enter Xlsxtream, a Ruby XLSX library with less features (e.g. no individual cell styles) but which does away with the memory issue by streaming …
Current webkit browsers like Chrome and Safari have a special variable in their consoles that refers to the selected DOM node in the elements panel. This lets us easily inspect Angular scopes.
Get the scope object and store it
s=$($0).scope() // That is: element = $0 // Store element $element = $(element) // Wrap with j...
RSpec allows you to mark a single Example/ExampleGroup so that only this will be run. This is very useful when using a test runner like guard.
Add the following config to
RSpec.configure do |config|
# These two settings work together to allow you to limit a spec run
# to individual examples or groups you care about by tagging them with
:focus metadata. When nothing is tagged with
:focus, all examples
# get run.
config.filter_run_including :focus => true