我有一个名为test_spec.rb的rspec ruby文件。我想在文件中添加以下命令,以便在运行rspec文件时运行它。
exec("sudo gsutil cp test_object.txt gs://sample-bucket1")
但是当我在上面的命令运行时运行我的代码时,它会停止进一步的执行。我该如何防止它。
以下是我的Rspec代码。
A=C.new
context "Bucket Resource : " do
#setup data
before('The Original should create object') do
#some code here
exec("sudo gsutil cp test_object.txt gs://sample-bucket1")
end
#Positive Test cases
describe "The Original should create object" do
it "Should execute successfully and return an instance " do
#define namevar
entity = "vivekkumarmishra17@gmail.com"
#define build params
build_params = {
entity: "user-vivekkumarmishra17@gmail.com",
role: "OWNER",
}
expect(A.create_instance(build_params)).to be_an_instance_of(B)
end
end
after('The Original should create object') do
#some code here
end
end
运行上面的代码后,不调用hook。
答案 0 :(得分:1)
您可以在rspec文件中使用back tick:
`sudo gsutil cp test_object.txt gs://sample-bucket1`