How to call an app helper method from an RSpec test in Rails?

前端 未结 6 1991
太阳男子
太阳男子 2021-02-05 02:56

The title is self explanatory.

Everything I\'ve tried led to a \"undefined method\".

To clarify, I am not trying to test a helper method. I am trying to use a he

6条回答
  •  一向
    一向 (楼主)
    2021-02-05 03:14

    As you can see here https://github.com/rspec/rspec-rails , you should initialize the spec/ directory (where specs will reside) with:

    $ rails generate rspec:install
    

    this will generate an rails_helper.rb with the option

    config.infer_spec_type_from_file_location!
    

    and finally require the new rails_helper in you helper_spec.rb instead of requiring 'spec_helper'.

    require 'rails_helper'
    describe ApplicationHelper do
      ...
    end
    

    good luck.

提交回复
热议问题