如何解决请帮忙Rspec:模拟/存根/错误数量的参数
我的“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 举报,一经查实,本站将立刻删除。