ruby-on-rails - Ruby on Rails, jwt auth, capybara cucumber testing
问题描述
I have Ruby on Rails backend and one view where ReactJS frontend is mounted. Authentication by devise + jwt. I use cucumber capybara for testing frontend. How can I sign in in tests? How can I put jwt in headers in steps of test?
Feature
...
Background:
Given I am loged in user
...
Steps
Given(/^I am loged in user$/) do
how can I put jwt in headers here?
end
解决方案
您可以创建一个帮助程序来填写您的登录表单,如下所示:
# 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
推荐阅读
- ajax - Laravel 加密密钥在页面加载时“消失”
- python - 将 struct.unpack() 数据作为指针传递给 c-function
- mysql - 加载类“com.mysql.jdbc.Driver”。这已被弃用。新的驱动程序类是`com.mysql.cj.jdbc.Driver'
- typescript - Promise 上的 TypeScript 条件逻辑
同步运行时允许代码执行 - excel - 用于从与以下模式匹配的文本文件中提取文本的 VBA 代码 #{pqfn:format('
') - android - 如何在确认捕获之前实现图像预览?
- python - 尝试将特定文件夹复制到另一个位置:主文件夹名称更改但子文件夹名称保持不变
- c++ - System Verilog DPI - 在 cpp 中运行并行线程,在 SV 中运行其他线程
- express - express 中的多个“res”语句会导致问题吗?
- r - 如何在 rvest 中跟踪具有特定 id 的元素的链接?