Reputation: 19969
I have the following sample code that is using a vanilla spec_helper. I'm trying to use the sign_in_as but am getting an error saying it doesn't exist. I hadn't really seen this config syntax before so I'm not sure if this is being used right. Any help would be appreciated? thx
in helpers/sign_in_helpers.rb
module SignInHelpers
def say_hello
puts 'hello'
end
def sign_in
sign_in_as '[email protected]'
end
def sign_in_as email
visit root_path
fill_in 'Email address', with: email
click_button 'Sign In'
end
end
RSpec.configure do |config|
config.include SignInHelpers
end
Upvotes: 0
Views: 55
Reputation: 24815
Some errors in your code.
you should have this code on top of the file
require 'spec_helper'
The place to put the file is spec/support
, not spec/helpers
Also, for the following code, better to keep them all inside spec/spec_helper.rb inside the configure block, though your way should work as well.
RSpec.configure do |config|
config.include SignInHelpers
end
By the way, better to define the type as your helper are for features only, and not going to work in controller tests.
config.include SignInHelpers type: :feature
Upvotes: 1
Reputation: 6501
In theory, yes. Your call looks like a valid use of the include syntax
https://www.relishapp.com/rspec/rspec-core/docs/helper-methods/define-helper-methods-in-a-module
Upvotes: 1