gpt4 book ai didi

Ruby:Minitest/spec 和 BDD Gherkin

转载 作者:太空宇宙 更新时间:2023-11-03 18:28:25 27 4
gpt4 key购买 nike

我似乎找不到太多关于 Minitest/spec 的文档,所以我想知道是否有人可以帮助我弄清楚如何做我需要做的事情。基本上我想对我所有的类和模块运行测试以确保它们 1.) 如果是静态或 2.) 则输出正确的值类型。) 在 to_symbols 的情况下,所有键都是符号。到目前为止,这是我尝试过的:

我认为小 cucumber 的样子:

Given binns
When the version method is called
then the return should be a float
and version should be a method or constant

我假设它会与 minitest/spec:

require 'minitest/autorun'
require 'minitest/spec'
require 'binns'

given Binns do
when "the version method is called" do
then "the return should be a float" do
# Do work
end
end
end

但是我得到:

syntax error, unexpected keyword_when (SyntaxError)
when "the version method is called" do
^

注意:我也愿意接受其他测试建议(我不太了解 cucumber ,听说它很重)或者如果有人有书籍建议,请告诉我我一直在寻找一本关于Ruby 单元测试。

最佳答案

MiniTest/Spec 使用 Rspec 风格的语法:desc, it, before, after...

require 'minitest/autorun'
require 'minitest/spec'
require 'binns'

desc Binns do
it "should return a float when the version method is called" do
# Do work
end
end

如果它能让您更轻松地进行转换,您可以将“desc”方法别名为“given”,将“it”方法别名为“when”。

Good tutorial from Peter Cooper here.

关于Ruby:Minitest/spec 和 BDD Gherkin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7656920/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com