2013-10-09 46 views
0

時,Rspec找不到示例,此處的目標是在PHP'exec'命令內執行ruby腳本(使用rake.invoke)。當使用PHP exec()調用

我有一個工作rspec的配置,執行乾淨(這裏是無頭rake任務如,但要注意,它的工作原理都無頭和「領導」爲下面的例子)

FILE=./../tools/wr_audit_dom.rb WR_DEBUG=1 bundle exec rake local:headless 

我調用該耙目標和其他邏輯在紅寶石文件,如下所示:

Rake.application.init 
Rake.application.load_rakefile 
Rake.application['local:headless'].reenable 
Rake.application['local:headless'].invoke 
> ruby dom_audit_parser.rb 
(this runs as expected) 

上面的一切都執行得很好,我的測試運行,我得到了我的結果。

不過,我想通過PHP執行Ruby腳本,所以我有下面的代碼爲「EXEC」的命令:

$cmd = 'cd <_projectdirectory_snipped_>; ruby dom_audit_parser.rb'; 
exec($cmd, $results); 

問題:它沒有返回實例運行,因爲如果不能找到他們。

但是,我可以在運行所有示例的情況下直接在終端中運行相同的命令(從php的exec cmd複製而來)。誰能告訴我什麼可能是錯的?

下面的命令顯示文件正在被指定和找到,沒有任何示例被跳過,但沒有發現任何東西。從PHP Exec命令

輸出從直接在終端

/usr/bin/ruby1.9.1 -S rspec dom_audit_webdriver_spec.rb -f documentation --color 
Run options: include {:local=>true}  
Inspect the webpage to scrape the DOM object 
-- [LOCAL] Starting firefox : 
[2013-10-09 16:19:10 -0400] Logging in 
[2013-10-09 16:19:10 -0400] Opening webpage 
..... SNIP 
-- [LOCAL] quit firefox 
    should find the dom object for the html node  
Finished in 2 minutes 0.2 seconds 
1 example, 0 failures 

注運行紅寶石命令輸出

/usr/bin/ruby1.9.1 -S rspec dom_audit_webdriver_spec.rb -f documentation --color Run 
options: include {:local=>true} Finished in 0.00017 seconds 0 examples, 0 failures 

,我試過將代碼添加到一個spec目錄,而不是直接指定文件。它發現文件是'rspec spec'的方式,但同樣的問題被觀察到。

├── config.yaml 
├── dom_audit_parser.rb 
├── dom_audit_portal.php 
├── dom_audit_webdriver.rb 
├── Rakefile 

預先感謝您!

+0

如果直接在shell中執行完全一樣的命令,這是怎麼回事? –

+0

向question – Tallisado

+0

添加了更多詳細信息當shell在shell中運行相同的命令時,PHP進程是否與Ruby運行相同的用戶? –

回答

0

的vim的/ etc/sudoers文件 附加:

"www-data  ALL=NOPASSWD: ALL" 

從PHP:

exec("sudo xyz");