Capybara methods are undefined

前端 未结 2 478
暗喜
暗喜 2021-01-15 09:48

I cannot get capybara to work. I am using capybara 2.0.0

I get this error

Failure/Error: visit \"/users/sign_in\"
     NoMethodError:
       undefine         


        
相关标签:
2条回答
  • 2021-01-15 09:54

    In my case, I got this error because I forgot to putrequire "spec_helper" at the top of my new spec file.

    I've done it enough times that I'm adding an answer to an already answered question in hopes that it helps some other knucklehead (or most likely me searching this again in the future).

    0 讨论(0)
  • 2021-01-15 09:58

    If you've got version >= 2.0, any tests that use Capybara methods like visit should go under a spec/features directory, and not under spec/requests, where they'd normally reside in Capybara 1.1.2.

    Have a look at the following links for more information:

    • rspec-rails and capybara 2.0: what you need to know
    • rspec-rails gem Capybara page

    If you don't want to use a spec/features directory, you should be able to mark a test as a feature in the following way and have Capybara methods work:

    describe "Some action", type: :feature do
      before do
        visit "/users/sign_in"
        # ...
      end
      # ...
    end
    
    0 讨论(0)
提交回复
热议问题