如何解决rspec:“在示例组中不可用例如,“ describe”或“ context”块
下面提到的代码已成功为1个用户使用,我想为许多用户实现以下工作代码,因此我尝试使用迭代。
##### Below is the working code for 1 user #######
# user
let!(:pi_user) { FactoryBot.create(:read_only) }
# PI oauth
let!(:oauth_app_02) { FactoryBot.create(:oauth_application,owner: pi_user) }
let!(:oauth_access_token_02) do
FactoryBot.create(:oauth_access_token,application: oauth_app_02,resource_owner_id: pi_user.id)
end
describe 'GET /api/proposals return all proposals for PI user' do
before(:each) { @headers = set_api_headers_with_user_auth(pi_user,oauth_access_token_02) }
it 'INDEX GET /api/proposals (return all) - successful' do
get api_proposals_path,params: {},headers: @headers
get_all_proposals(prop_01,prop_02,prop_03)
expect(response).to be_successful
end
end
##### I tried for many users #######
let!(:pi_user) { FactoryBot.create(:read_only) }
let!(:beamline_expert_user) { FactoryBot.create(:read_only) }
# BE oauth
let!(:oauth_app_01) { FactoryBot.create(:oauth_application,owner: beamline_expert_user) }
let!(:oauth_access_token_01) do
FactoryBot.create(:oauth_access_token,application: oauth_app_01,resource_owner_id: beamline_expert_user.id)
end
# PI oauth
let!(:oauth_app_02) { FactoryBot.create(:oauth_application,resource_owner_id: pi_user.id)
end
describe 'GET (INDEX) /api/proposals return all proposals for all users' do
abc = [beamline_expert_user,pi_user]
xyz = [oauth_access_token_01,oauth_access_token_02]
abc.zip(xyz).each do |user,token|
describe "GET /api/proposals return all proposals for #{user} user" do
before(:each) { @headers = set_api_headers_with_user_auth(user,token) }
it 'INDEX GET /api/proposals (return all) - successful' do
get api_proposals_path,headers: @headers
get_all_proposals(prop_01,prop_03)
expect(response).to be_successful
end
end
end
end
但是在执行以上规范时会出现错误
Failure/Error: abc = [beamline_expert_user,pi_user]
`beamline_expert_user` is not available on an example group (e.g. a `describe` or `context` block). It is only available from within individual examples (e.g. `it` blocks) or from constructs that run in the scope of an example (e.g. `before`,`let`,etc).
所以不是
“描述”
我尝试了“
它
”,但仍然无法实现所需的输出。您能否建议我如何通过对许多用户使用迭代来使其工作。
预先感谢
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。