Make login processing common.
・ Ruby: 2.5.7 Rails: 5.2.4 ・ Rspec-rails: 4.0.1 ・ Vagrant: 2.2.7 -VirtualBox: 6.1 ・ OS: macOS Catalina
support
directory$ mkdir support
support
directory$ touch spec/support/login_macros.rb
login_macros.rb
module LoginMacros
def login(user)
fill_in 'mail address', with: user.email
fill_in 'password', with: user.password
click_button 'Login'
end
end
rails_helper.rb
rails_helper.rb
#Comment out line 23
Dir[Rails.root.join('spec', 'support', '**', '*.rb')].sort.each { |f| require f }
RSpec.configure do |config|
config.include LoginMacros #Postscript
end
support
directory.Dir[Rails.root.join('spec', 'support', '**', '*.rb')].sort.each { |f| require f }
2
to be used.config.include LoginMacros
require 'rails_helper'
RSpec.describe 'Authentication test', type: :feature do
let(:user) { create(:user) }
subject { page }
describe 'User authentication test' do
context 'User login test' do
it 'Being able to log in' do
visit new_user_session_path
login(user) #Use method
is_expected.to have_content 'Log out'
end
end
end
end
Recommended Posts