Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
因此,一些 ruby 库使用以下技巧兼作可执行文件:
if __FILE__ == $0 # act as executable... end
我正在编写一个迷你库,并且想知道是否有类似的技巧可以用来将我的 rspec 测试嵌入到文件中。某种常数或我可以检查的东西,例如:
if RSPEC_TARGET == $0 describe 'Foo' do it "should foo" #... end end
ARGV包含脚本的名称。我在我的模块中使用以下内容:
ARGV
if ARGV.include? File.basename(__FILE__) # unit tests here end