问题描述
我的“recaptcha_v3”需要参数,但不确定使用 let() 对其进行模拟/存根的语法更正。
我的助手代码:
# frozen_string_literal: true
module FormCaptchaHelper
def recaptcha_element(event_name)
if @show_checkBox_recaptcha
content_tag :div do
recaptcha_tags
end
else
content_tag :div do
concat recaptcha_v3(action: event_name,site_key: '123')
concat hidden_field_tag :dog,'dog'
end
end
end
end
我的 rspec 测试
require "rails_helper"
RSpec.describe FormCaptchaHelper,type: :helper do
let(:recaptcha_tags) { 'v2' }
let(:recaptcha_v3) { 'v3' }
describe "#recaptcha_element" do
it "should show v2 when show_checkBox_recaptcha is true" do
@show_checkBox_recaptcha = true
expect( recaptcha_element('test')).to eql("<div class=\"go\">v2</div>")
end
it "should show v3 when show_checkBox_recaptcha is false" do
@show_checkBox_recaptcha = false
expect( recaptcha_element('test')).to eql('v3')
end
end
end
Failures:
1) FormCaptchaHelper#recaptcha_element should show v3 when show_checkBox_recaptcha is false
Failure/Error: concat recaptcha_v3(action: event_name,site_key: '123')
ArgumentError:
wrong number of arguments (given 1,expected 0)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)