Capybara 2.0 and rspec-rails - helpers do not work in specs / functions

I'm trying to use a method from a helper module, but rspec does not seem to recognize the test helpers in spec/features . Note that the only change to spec_helper.rb was the addition of require 'capybara/rspec' .

I tried moving helper.rb to spec/support , spec/helpers and spec/features (the directory containing my tests), but no luck. The test continues to indicate that the helper method is undefined.

The only way to make it β€œwork” is to move my test to another directory, for example spec/integration . But now capybara will not work ( visit undefined ) because it is not in spec/features .

Here is my helper module ( authentication_helper.rb ):

 module AuthenticationHelper def sign_in_as!(user) visit '/users/sign_in' fill_in "Email", with: user.email fill_in "Password", with: "password" click_button "Sign in" page.should have_content("Signed in successfully.") end end RSpec.configure do |c| c.include AuthenticationHelper, type: :request end 
+4
source share
1 answer

put this helper file in spec / support /

and this line spec_helper.rb

  # Requires supporting ruby files with custom matchers and macros, etc, # in spec/support/ and its subdirectories. Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f } 
0
source

Source: https://habr.com/ru/post/1482153/


All Articles