Read more

RSpec: Change the type of a spec regardless of the folder it lives in

Henning Koch
October 17, 2012Software engineer at makandra GmbH

In a Rails application, *_spec.rb files get special treatment depending on the file's directory. E.g. when you put a spec in spec/controllers your examples will have some magic context like controller, post or get that appears out of nowhere.

Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

If you want that magic context for a spec in another folder, use the :type option:

describe CakesController, :type => :controller do
  ...
end
Posted by Henning Koch to makandra dev (2012-10-17 14:54)