gpt4 book ai didi

ruby - ruby, rspec 中 describe, it 和 def 的区别

转载 作者:数据小太阳 更新时间:2023-10-29 08:44:34 26 4
gpt4 key购买 nike

我是 rspec 的新手。通过教程,我陷入了困境。当我使用 WATIRcucumber 框架时,我从未见过 describeit

那有什么区别呢?什么时候用什么?

最佳答案

Describe 用于解释正在进行的工作。通常,您要描述一个类,它会围绕所有 it 调用。 it 是在 describe block 中执行的测试用例:

describe Foo do
it "will return true" do
expect(Foo.bar).to eq(true)
end

it "will return false" do
expect(Foo.baz).to eq(false)
end
end

# When run, rspec output is:
Foo
will return true
will return false

在上面的例子中,it 方法描述了 barbaz 如何作用于 Foo类(class)。 A good read is the rspec documentation on this.

关于ruby - ruby, rspec 中 describe, it 和 def 的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33673410/

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