2013-01-23 41 views
1

我目前正試圖運行一個從repo下載代碼的sinatra框架,在代碼上執行rspec,然後處理來自RSpec的結果。但是,當我從不同的應用程序調用rspec時,我無法運行rspec。從完全不同的sinatra應用程序運行Rspec?

我不斷收到以下錯誤:

/Users/dir/.rvm/gems/[email protected]/gems/bundler-1.1.5/lib/bundler/rubygems_integration.rb:147:in `block in replace_gem': rspec-core is not part of the bundle. Add it to Gemfile. (Gem::LoadError) 
    from /Users/dir/.rvm/gems/ruby-1.9.3-p194/bin/rspec:22:in `<main>' 

運行萬噸的產量之後,它基本上可以歸結紅寶石執行束Exec之前沒有切換到正確的目錄。我已經嘗試了幾乎所有的東西來讓它無法工作......看起來即使我改變了目錄,它仍會繼續嘗試在我正在運行的應用程序上運行RSpec,而不是我想要的那個做到這一點。

Dir.chdir('../target_app'){ 
    exe = "bundle exec rspec spec" 
    `#{exe}` 
    } 

我也嘗試了反引號,exec和system()這樣沒有成功。

`cd ../target_app && bundle exec rspec spec` 

我也曾嘗試之類的子進程,但沒有成功:

p = ChildProcess.build('bundle', 'exec', 'rspec', 'spec') 
    p.io.inherit! 
    p.cwd = '../target_app' 
    p.start 

任何線索或對如何解決這一將不勝感激幫助!

編輯:

我也試過bundle install --binstub --path vendor

與此代碼:

Dir.chdir('../target_app'){ 
    puts `pwd`.chomp 
    exe = "bin/rspec spec -o ../tmp.txt" 
    puts exe 
    `#{exe}` 
    } 

我得到這樣的輸出:

/Users/me/dev/target_app 
bin/rspec spec -o ../tmp.txt 
/Users/me/.rvm/gems/[email protected]/gems/bundler-1.1.5/lib/bundler/rubygems_integration.rb:223:in `block in replace_bin_path': can't find executable rspec (Gem::Exception) 
    from bin/rspec:16:in `<main>' 

回答

2

生成binstubs的捆紮機bundle install --binstubs和使用binstub而不是rspec,以便正確的rspec一個d始終使用Gemfile。

http://gembundler.com/v1.2/man/bundle-exec.1.html(在聯機手冊頁binstubs更多信息)

+2

+1。我現在總是爲每個項目都這樣做。我還加了'--path vendor',這真的有助於從我正在處理的其他任何東西中整理整個項目。 YMMV – iain

+0

我剛試過這個,但仍然沒有成功。我按照從這裏的方向:http://robots.thoughtbot.com/post/15346721484/use-bundlers-binstubs,我仍然得到相同的錯誤。我想我需要從該文件夾中加載gemfile,但我不確定這是否正常工作或者這是正確的方法 – roloenusa

+0

您想要執行'bin/rspec'相對於您的初始應用程序,而不是目標應用程序。在使用'rspec = File.expand_path(「./ bin/rspec」)''執行'Dir.chdir'之前設置路徑爲bin/rspec(如果這樣的話,得到基於File.dirname(__ FILE__ )'可能更加健壯。 –

相關問題