2013-11-26 43 views
2

紅寶石2.0.0p247 的ActiveRecord-4.0.1 黃瓜1.3.10 阿魯巴-0.5.3 SimpleCove-0.8.2一個人如何配置黃瓜/阿魯巴使用SimpleCov?

我們在仍然使用ActiveRecord的一個NON-Rails項目中使用黃瓜阿魯巴。我們的黃瓜功能可以在進程內和進程外執行代碼。過程外的代碼使用相同的加載器序列在生產箱執行通過啓動存根:

#!/usr/bin/env ruby 
require 'bundler/setup' 
Bundler.require 

require 'pathname' 
my_dir = Pathname.new(
    File.join(File.dirname(
    __FILE__), '../', 'lib/')).realpath.to_s + '/' 

require my_dir + File.basename(__FILE__) 

HllThForexRssFetch::Main.new(ARGV).execute 
#EOF 

我們的特點/支撐/ env.rb文件包含此:

$ cat features/support/env.rb 
# Must load and start simplecov before any application code 
require 'simplecov' 
SimpleCov.start do 
    add_filter "/features/" 
    add_filter "/libexec" 
    add_filter "/lib/hll_active_record/" 
    add_filter "/test/" 
    add_filter "/tmp/" 
end 
SimpleCov.command_name("Cucumber Features") 

# Do not use cucumber/rails in standalone projects 
#require 'cucumber/rails' 

。 。 。

當我們一步定義調用通過Aruba的運行外部斌/ file命令步驟定義正常工作,並完成測試,預期,但代碼覆蓋率不與運行的其餘部分合並。我所尋求的是如何建立simplecov到與在處理黃瓜直接運行部分一起彙報進程外,測試的代碼覆蓋率的指令。

這是怎麼回事?

回答

5

我有類似你的環境中,這是我得到它的工作:

假設一個目錄樹,如:

project 
|- bin 
| |- binary 
|- lib 
| |- ... 
|- spec 
| |- ... 
|- features 
| |- support 
| | |- env.rb 
| |- ... 

拳檢查這個問題https://github.com/colszowka/simplecov/issues/234

它描述二進制應該開始simplecov。它的hackish,但我加入這個頭我的二進制文件(項目/斌/二進制):

if ENV['COVERAGE'] 
    require 'simplecov' 

    # As described in the issue, every process must have an unique name: 
    SimpleCov.command_name "binary #{Process.pid}" 

    # When running with aruba simplecov was using /tmp/aruba as the root folder. 
    # This is to force using the project folder 
    SimpleCov.root(File.join(File.expand_path(File.dirname(__FILE__)), '..')) 

    SimpleCov.start do 
    filters.clear 

    # Because simplecov filters everything outside of the SimpleCov.root 
    # This should be added, cf. 
    # https://github.com/colszowka/simplecov#default-root-filter-and-coverage-for-things-outside-of-it 
    add_filter do |src| 
     !(src.filename =~ /^#{SimpleCov.root}/) unless src.filename =~ /project/ 
    end 

    # Ignoring test folders and tmp for Aruba 
    add_filter '/spec/' 
    add_filter '/test/' 
    add_filter '/features/' 
    add_filter '/tmp/' 
    end 
end 

然後以二進制的調用內部黃瓜覆蓋環境變量應設置。 在在功能/支持/ env.rb子句前:

require 'simplecov' 
SimpleCov.command_name 'Cucumber' 

Before do 
    # This is using the aruba helper, 
    # cf. https://github.com/cucumber/aruba/blob/master/lib/aruba/api.rb 
    set_env('COVERAGE', 'true') 
    # This could also be accomplished with the "I set the environment variables to:" step 
end 

如果在你的環境中,你有兩個框架(如RSpec的黃瓜在這個例子中)不要忘記https://github.com/colszowka/simplecov#merging-results

+0

我會將此標記,當我返回到該項目,並嘗試這種解決方案對自己的答案。 –

0

使用上述,設定基於所述阿魯巴 進程的PID的COMMAND_NAME導致SimpleCov積累非常大的結果集,污染 與舊的運行結果。

我有更好的運氣設置命令名稱如下:

# As described in the issue, every process must have an unique name: 
SimpleCov.command_name ARGV.join(' ') 

導致只能用相同參數的最新運行得到列入 結果。