我有Ruby on Rails后端和一个安装了ReactJS前端的视图。通过devise + jwt进行身份验证。我使用黄瓜水豚测试前端。如何登录测试?如何在测试步骤中将jwt放在标题中?
功能
...
Background:
Given I am loged in user
...
步骤
Given(/^I am loged in user$/) do
how can I put jwt in headers here?
end
答案 0 :(得分:0)
您可以创建一个助手,以填写您的登录表单,如下所示:
# spec/support/features_helpers.rb
def login_user(user=nil)
visit '/#/login'
within '#login_form' do
fill_in 'email', with: user.email
fill_in 'password', with: 'foobarfoo'
page.find('button').click
end
expect(page).to have_no_css '#login_form'
end
然后在您的测试中使用:
let(:user) { create(:user) }
before do
login_user user
end
it '...' do
...
end