Testing Views that use Devise with RSpec

前端 未结 2 1429
暗喜
暗喜 2020-12-09 16:20

I am trying to get a previously passing rspec \"view spec\" to pass after adding Devise\'s user_signed_in? method to the view template in question. The template

相关标签:
2条回答
  • 2020-12-09 16:39

    Have a look at Rails Composer, this will guide you through a new rails project creation with options like testing, UI etc..

    Create a sample project, cool thing is it will create all the test for you including view testing with devise. Then you can get an idea from those testing specs.

    worked for me :D

    HTH

    0 讨论(0)
  • 2020-12-09 16:52

    The error you're receiving is because you need to include the devise test helpers

    Generally you'll add this (and you might already have) to spec/support/devise.rb

    RSpec.configure do |config|
      config.include Devise::TestHelpers, :type => :controller
    end
    

    But since you're creating a view spec, you'll want something like this:

    RSpec.configure do |config|
      config.include Devise::TestHelpers, :type => :controller
      config.include Devise::TestHelpers, :type => :view
    end
    
    0 讨论(0)
提交回复
热议问题