Ruby on rails 如何在RSpec中编写可重用的共享示例
每次运行此操作时,我总是得到一个Ruby on rails 如何在RSpec中编写可重用的共享示例,ruby-on-rails,testing,rspec,Ruby On Rails,Testing,Rspec,每次运行此操作时,我总是得到一个错误数量的参数(1代表0)。我做错了什么 describe Payment do before { @payment = build_stubbed(:payment) } subject { @payment } shared_examples 'a foreign key' do |key| it "can't be nil, blank, or not an int" do [nil, "", " ", "a", 1.1]
错误数量的参数(1代表0)
。我做错了什么
describe Payment do
before { @payment = build_stubbed(:payment) }
subject { @payment }
shared_examples 'a foreign key' do |key|
it "can't be nil, blank, or not an int" do
[nil, "", " ", "a", 1.1].each do |value|
@payment.send key, value
@payment.should_not be_valid
end
end
end
describe "validation" do
describe "order_id" do
it_behaves_like 'a foreign key', :order_id
end
end
end
失败消息:
1) Payment validation order_id behaves like a foreign key can't be nil, blank, or not an int
Failure/Error: @payment.send(key, value)
ArgumentError:
wrong number of arguments (1 for 0)
Shared Example Group: "a foreign key" called from ./spec/models/payment_spec.rb:27
# ./spec/models/payment_spec.rb:18:in `block (4 levels) in <top (required)>'
# ./spec/models/payment_spec.rb:17:in `each'
# ./spec/models/payment_spec.rb:17:in `block (3 levels) in <top (required)>'
1)支付验证顺序\u id的行为与外键的行为类似,外键不能为零、空或非整数
失败/错误:@payment.send(键,值)
参数错误:
参数数目错误(1代表0)
共享示例组:./spec/models/payment_spec.rb:27调用的“外键”
#./spec/models/payment_spec.rb:18:in'block(4层)in'
#/规格/型号/付款规格rb:17:“每个”
#./spec/models/payment_spec.rb:17:in'block(3层)in'
我没有正确提供setter方法:@payment.send(key,value)
相反,我需要使用@payment.send(“#{key}=”,value)