Cucumber: Calling multiple steps from a step definition
Reusable Gherkin steps can be chained inside a new step definition with steps or step, but steps only processes lines starting with Gherkin keywords.
Strip carriage returns in submitted textareas
When submitting textareas, browsers sometimes include carriage returns (\r) instead of just line feeds (\n) at the end of each line. I don't know when this happens, and most of the time it doesn't matter.
In cases where it does matter, use the attached trait to remove carriage returns from one or more attributes like this:
class Note
does 'strip_carriage_returns', :prose, :code
end
Here is the test that goes with it:
describe Note do
describe 'before_validation' do...
WebMock 1.8.0 does not play nice with Curb < 0.7.16
Updating WebMock to 1.8.0 can let unstubbed specs send real HTTP requests when Curb is older than 0.7.16.
Marry Capybara with SSL-enabled applications
Capybara can lose the HTTPS state when specs cross between secure and insecure Rails actions, causing request URLs to fall back to the wrong protocol.
validates_acceptance_of is skipped when the attribute is nil
validates_acceptance_of silently skips nil attributes, so a missing checkbox or typo can leave acceptance unchecked; a boolean field with validates_presence_of is safer.
How to get a backtrace if rspec (or any other ruby process) hangs with no output
RSpec can freeze without output and ignore --backtrace or Ctrl-C; sending USR1 can print all thread backtraces from a running Ruby process.
Resque: Work off queues manually
Manual queue processing in Resque specs avoids relying on an external worker while keeping behavior close to real job execution.
Save ActiveRecord models without callbacks or validations (in Rails 2 and Rails 3)
Persist ActiveRecord records directly when callbacks and validations are unnecessary; Rails 2 has create_without_callbacks and update_without_callbacks, while Rails 3 needs sneaky-save.
JavaScript: How to log execution times to your browser console
Measure JavaScript code duration in the browser with console.time and console.timeEnd, including asynchronous flows and separate code locations. Works in modern browsers and recent Internet Explorer.
Fixing the warning Time#succ is obsolete; use time + 1
Deprecated Time#succ warnings can flood logs when time ranges are iterated or compared with include?; cover? or SQL BETWEEN avoid the issue.
How to: Throttle CPU in Google Chrome
Limit Chrome CPU speed to measure frontend performance and reproduce sluggish behavior in DevTools.
Handling duplicate links with Capybara and Cucumber
Duplicate links in Capybara can trigger Ambiguous match errors when any matching link is fine; switching Capybara.match to :first avoids the failure.
Geordi 1.9 released
Cleanup commands for leftover dump files and unneeded local MySQL, MariaDB, and Postgres databases, with whitelisting and flexible authentication methods.
RSpec 3 no longer chooses a spec's type based on its directory
RSpec 3 no longer infers spec type from folder names, which can break helpers like routing in existing suites. Set type explicitly or re-enable file-location inference.
Check if a field or button is disabled with Cucumber
Check whether form controls or buttons are disabled in Cucumber step definitions, using label-based assertions on Capybara or Webrat elements.
ping with timestamps
Timestamp each ping reply to correlate network latency with exact times and log connectivity events more easily.
How to change the class in FactoryBot traits
FactoryBot traits cannot use :class; a nested factory or initialize_with can build the desired subtype instead.
Spreewald 1.0.0 released
spreewald now provides a binary that lists available steps and can filter them by a search term.
Faker is now I18n aware, ships with unicorns
Faker now reads strings from locale files, which can trigger confusing translation missing errors when locale data is incomplete.
RSpec matcher "be_sorted"
Custom RSpec matcher for checking whether an array is naturally ordered; now part of Spreewald.
Configuring User Agents with Capybara + Selenium Webdriver
A while ago we were working on an application that had an entire version specially created for mobiles, such as the iPhone. This specific application was entirely tested with Capybara, Steak and Selenium Webdriver. Although the test suite wasn’t the fastest one in the world, the web application was very well tested, and to guarantee that we would also be testing the mobile version, we would have to simulate an iPhone user agent accessing the application.
But wait, you might be thinking that we are not able to change browser headers while ...
RSpec claims nil to be false
RSpec be_false matches nil, so a false check can pass unexpectedly. Use == false when the value must be exactly false.
postgres_ext: additional Rails bindings for PostgreSQL
Missing PostgreSQL types and query helpers for Rails 4.x make native array, CTE, and network-style filtering easier in ActiveRecord and Arel.
Typical .gitignore
Common ignore list for source control that keeps logs, temporary files, local databases, IDE settings, and generated assets out of git history.