[英]Ruby File Delete Cucumber
I'm running tests where I download a PDF file from a webpage, confirm it's gone to the download folder then delete it (to stop the folder being overwhelmed with PDF's). 我正在运行测试,从网页上下载PDF文件,确认已进入下载文件夹,然后将其删除(以防止该文件夹被PDF淹没)。
When trying to use a wild card in the filepath so that others can run this test on their machine, I get an error saying that the file doesn't exist. 当尝试在文件路径中使用通配符,以便其他人可以在其计算机上运行此测试时,我收到一条错误消息,指出该文件不存在。
This is my code: 这是我的代码:
pdf_file = ("C:/Users/**/Downloads/myfile.pdf")
And(/^I can see the downloaded PDF$/) do
puts Dir['C:/**/**/Downloads/myfile.pdf'].last
File.delete(pdf_file)
end
It's odd that the wildcards work when confirming within the Dir. 在Dir中进行确认时,通配符起作用很奇怪。
As soon as I put the actual username in the file path, it works. 只要将实际的用户名放在文件路径中,它就会起作用。 Is there anyway to get around this?
反正有解决这个问题的方法吗?
Not sure if I'm reading this correctly, but--based on the code--you are passing a string that contains asterisks to File.delete
. 不知道我是否阅读正确,但是-基于代码-您正在将包含星号的字符串传递给
File.delete
。 You need to call Dir::[]
on that string to perform the wildcard conversion(s) before passing it to File.delete
. 您需要在该字符串上调用
Dir::[]
来执行通配符转换,然后再将其传递给File.delete
。 For example: 例如:
File.delete(Dir["C:/Users/**/Downloads/myfile.pdf"].last)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.