我想创建用于计算字符的rspec文件。我使用这段代码:
private
def generate_transaction_id(length = 25)
chars = [*('a'..'z'), *(0..9)]
(0..length).map {chars.sample}.join
end
rspec的:
it "checks transaction id length" do
trx_id = request.send("generate_transaction_id")
puts trx_id
expect(trx_id).to have(25).characters
end
输出:
.lt3s5gxr0zkm02d0gf2f0vce1o
Fsome output
.
Failures:
1) with no argument checks transaction id length
Failure/Error: expect(trx_id).to have(25).characters
NoMethodError:
undefined method `have' for #<RSpec::ExampleGroups::Anonymous::WithNoArgument:0x007fde1f0fb590>
你知道如何解决这个问题吗?
答案 0 :(得分:1)
我不确定为什么你认为rspec
理解人类语言。
expect(trx_id.length).to eq(25)