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

Updated . Posted . Visible to the public.

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.

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

describe CakesController, :type => :controller do
  ...
end
Profile picture of Henning Koch
Henning Koch
Last edit
License
Source code in this card is licensed under the MIT License.
Posted by Henning Koch to makandra dev (2012-10-17 12:54)