Spec "content_for" calls in helpers

RSpec helper specs can leak content_for state between examples, making repeated checks fail. A fresh helper instance avoids stale instance variables.

Webservice to mock HTTP responses

Need a simple way to fake server replies during development when external APIs are unavailable or unreliable.

Cerberus: Home

Cerberus is a lightweight and easy-to-use Continuous Builder software for Ruby. It could be run periodically from a scheduler and check if application tests are broken. In case of failed tests Cerberus sends notification to developers.

The WHATWG Blog » Blog Archive » The longdesc lottery

It turned out that the test subject didn't know that longdesc even existed before the tester told him about it. Can you blame him?

jasonm's parallel_specs at master - GitHub

Rake tasks to run specs and tests in parallel, to use multiple CPUs and speedup test runtime.

http://mockito.org/

Mockito is a mocking framework that tastes really good. It lets you write beautiful tests with clean & simple API. Mockito doesn't give you hangover because the tests are very readable and they produce clean verification errors.

rest-client - Project Hosting on Google Code

RESTClient is a Java application to test RESTful webservices. It can be used to test variety of HTTP communications.

thoughtbot's bourne at master - GitHub

Test spies are a form of test double that preserves the normal four-phase unit

How to fix routing error when using concerns in Rails up to 3.2.22.1

Routing error in Rails 3.2.22.1 can appear when concerns is passed as an option to resources, producing broken routes and failed controller specs.

Gem development: When your specs don't see dependencies from your Gemfile

Bundler does not auto-require gems, so specs may miss dependencies unless the environment calls Bundler.require; direct dependencies still must be required by the gem itself.

Spreewald: When using `patiently do`, don't reuse existing variable names

patiently do repeats a block until it passes or times out; reusing outer variable names inside the repeated block can make repeated evaluations fail.

Machinist: Refer to another named blueprint inside a blueprint

Named Machinist blueprints can reuse another blueprint’s fields, letting variants combine shared defaults without repeating attribute definitions.

RSpec: Stubbing a method that takes a block

RSpec stubs for methods that yield blocks need and_yield instead of and_return; multiple yields can be chained, and return values can be combined.

Show details of TLS/SSL connections of remote hosts

sslscan reports TLS/SSL cipher support and certificate details for remote hosts, helping identify weak protocols, preferred ciphers, and certificate validity.

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.

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.

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.