我写了一个包含一些测试的通用测试文件。 我想编写一些将使用这些测试的文件,每个文件将运行特定的测试(不是全部)。
一个测试例子:
class AccountBase
describe "TC_ACCOUNT" do
it "Fill info Fields" do
#test here
end
end
end
我们称它为 baseTests.rb。 现在我有另一个文件 - infoTest.rb 。 如何从 infoTest 中调用“填充信息字段” 谢谢。
最佳答案
听起来你需要 Rspec 的共享示例: Shared examples on Relish , or in the Rspec API docs
您的示例可能类似于:
class AccountBase
shared_examples "TC_ACCOUNT" do
it "Fill info Fields" do
#test here
end
end
end
然后您可以在 infoTest.rb 文件中包含共享示例:
include_examples "TC_ACCOUNT"
或:
it_behaves_like "TC_ACCOUNT"
然后可以编写共享示例来检查包含它的上下文中的元数据,或者接受由包含规范传入的 block 的参数,以便根据包含它的测试文件更改它的行为。
关于ruby - 如何从 ruby 中的另一个文件调用特定测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39269004/