Rails Rspec error - undefined method `visit'

后端 未结 2 1059
太阳男子
太阳男子 2020-12-10 05:31

So I\'m new to TDD & I\'m throwing some Rspec errors here on my tests...Basically after running bundle exec rspec spec, I get an undefined method \'visit\'

相关标签:
2条回答
  • 2020-12-10 06:09

    The problem is here:

    ./spec/requests/user_pages_spec.rb
    

    You put the Capybara integration tests in requests folder. That's why the method visit won't work.

    To fix, just move all the tests from spec/requests to spec/features.

    0 讨论(0)
  • 2020-12-10 06:25

    This happens because you are trying to use the visit method from Capybara::DSL. If you check the documentation:

     Capybara is no longer supported in
     request specs as of Capybara 2.0.0. The recommended way to use Capybara is
     with feature specs.
    

    To solve this problem you should move your tests to spec/features folder or include Capybara::DSL for the request specs:

    #spec_helper.rb
    RSpec.configure do |config|
      #...
      config.include Capybara::DSL, :type => :request
    
    0 讨论(0)
提交回复
热议问题