Ruby 文件路径问题
我喜欢实现的是使用watchr跟踪两个目录中的文件更改 我的文件结构如下:Ruby 文件路径问题,ruby,rubygems,Ruby,Rubygems,我喜欢实现的是使用watchr跟踪两个目录中的文件更改 我的文件结构如下: /PluginDir /classes Wrapper.php /Tests /classes WrapperTest.php autotest_watchr.rb watch("../../classes/(.*).php") do |match| run_test %{#{match[1]}Test.php} end
/PluginDir
/classes
Wrapper.php
/Tests
/classes
WrapperTest.php
autotest_watchr.rb
watch("../../classes/(.*).php") do |match|
run_test %{#{match[1]}Test.php}
end
watch(".*Test.php") do |match|
run_test match[0]
end
def run_test(file)
clear_console()
unless File.exists?(file)
puts "#{file} does not exists"
return
end
puts "Running #{file}"
results = `phpunit #{file}`
puts results
if results.match(/OK/)
notify "#{file}", "Tests Passed Successfuly", 4500
elsif results.match(/FAILURES\!/)
notify_failed file, results
end
end
def notify_failed cmd, results
failed_examples = results.scan(/([0-9]+\))\s+(.*)/)
notify "#{cmd}", failed_examples[0], 6000
end
def notify title, msg, show_time
systemMsg = "notifu.exe /p \"#{title}\" /m \"#{msg}\" /d #{show_time}"
systemMsg.gsub('“', "'")
system systemMsg
end
def clear_console
system "cls"
end
autotest_watchr.rb的内容如下:
/PluginDir
/classes
Wrapper.php
/Tests
/classes
WrapperTest.php
autotest_watchr.rb
watch("../../classes/(.*).php") do |match|
run_test %{#{match[1]}Test.php}
end
watch(".*Test.php") do |match|
run_test match[0]
end
def run_test(file)
clear_console()
unless File.exists?(file)
puts "#{file} does not exists"
return
end
puts "Running #{file}"
results = `phpunit #{file}`
puts results
if results.match(/OK/)
notify "#{file}", "Tests Passed Successfuly", 4500
elsif results.match(/FAILURES\!/)
notify_failed file, results
end
end
def notify_failed cmd, results
failed_examples = results.scan(/([0-9]+\))\s+(.*)/)
notify "#{cmd}", failed_examples[0], 6000
end
def notify title, msg, show_time
systemMsg = "notifu.exe /p \"#{title}\" /m \"#{msg}\" /d #{show_time}"
systemMsg.gsub('“', "'")
system systemMsg
end
def clear_console
system "cls"
end
然后从文件夹/PluginDir/Tests/classes/I中,从cmd执行以下命令:
watchr autotest_watchr.rb
在本例中,脚本正常启动执行,当我在测试文件中进行修改时,控制台会更新,但当我在/PluginDir/classes/*.php文件中创建修改时,我的控制台不会得到任何更新
为什么?
注意:在first watch(“../../classes/....”中,我也尝试了匹配[0],以防regex变量不正确,但脚本在第一个搜索字符串中仍然不起作用。。../../classes/(.*).php“我认为“.”字符实际上是任何单个字符的占位符。 对于您的使用,您可能需要使用反斜杠来转义它,因此:
“\.\./\.\../.\./.././././././././././././././.../././../.././../././././././../././.php”字符实际上是任何单个字符的占位符。
对于您的使用,您可能需要使用反斜杠来转义它,因此:
'\.\./\.\././classes/(.*)\.php'
Ruby来管理php,很好!;-)这是基于:)我不是那种大师!!:)Ruby来管理php,很好!;-)这是基于:)我不是那种大师!!:)