[英]Use Ruby, Cucumber and Aruba to check for file in testing home directory
我正在使用 Cucumber 和 Aruba 来测试在GLI之上编写的 Ruby 命令行应用程序。 为了防止测试影响生产数据,我更新ENV['HOME']
以指向一个测试目录。 我想检查测试ENV['HOME']
目录中是否存在文件。 我想为此使用 Aruba,但我一直无法让ENV['HOME']
正确扩展。
例如:
Scenario: Testing config files are found
Given I switch ENV['HOME'] to be "set_a" of test_arena
Then a file named "#{ENV['HOME']}/config.xml" should exist
是否可以将 ENV['HOME'] 传递给 Aruba Then a file named "" should exist
step_definition 并将其扩展为完整路径?
我仍然有兴趣看看是否可以使用 Cucumber/Aruba 本地完成此操作。 同时,这是我正在做的事情的一个简化示例:
在features/app_name.feature
文件中,定义以下场景:
Scenario: Testing config files are found
Given I switch ENV['HOME'] to be "test_arenas/set_a"
Then a test_arena file named "config.xml" should exist
然后,在features/step_definitions/app_name.rb
文件中定义步骤:
Given(/^I switch ENV\['HOME'\] to be "(.*?)"$/) do |testing_dir|
ENV['HOME'] = File.join(File.expand_path(File.dirname(__FILE__)),
'..','..', testing_dir)
end
Then(/^a test_arena file named "(.*?)" should exist$/) do |file_name|
file_path = "#{ENV['HOME']}/#{file_name}"
expect(File.exists?(file_path)).to be_truthy
end
这在 Aruba 的check_file_presence
没有那么强大,但它完成了基本工作。
对于更多背景知识,这种方法背后的想法是在应用程序目录结构的根目录下放置一个test_arenas
目录。 对于每个测试,都会创建一个单独的test_arenas/set_X
目录,其中包含必要的文件。 在每次测试之前,ENV['HOME'] 指向各自的test_arenas/set_X
目录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.