2013-11-26 1 views
2

루비 2.0.0p247 액티브-4.0.1 오이 1.3.10 아루바-0.5.3 SimpleCove-0.8.2SimpleCov를 사용하기 위해 Cucumber/Aruba를 어떻게 구성합니까?

우리는 그럼에도 불구하고 액티브를 사용하는 비 레일 프로젝트 아루바와 오이를 사용합니다. 우리의 오이 기능은 진행중인 코드와 프로세스 외의 코드를 모두 실행합니다. 아웃 오브 프로세스 코드는 빈에서 시작 스텁을 통해 생산과 같은 로더 시퀀스를 사용하여 실행됩니다

$ 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' 

:

#!/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 파일이 포함 . . .

아루바의 실행 명령을 통해 단계 정의가 외부 bin/파일을 호출하면 단계 정의가 올바르게 작동하고 테스트가 예상대로 완료되지만 코드 적용 범위가 나머지 실행과 병합되지 않습니다. 내가 찾고있는 것은 공정 간 테스트의 코드 적용 범위를 오이가 직접 프로세스 내에서 실행하는 부분과 함께보고하기 위해 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에서 을 :


환경에서 (이 예에서는 RSpec에와 오이 등)이 프레임 워크가있는 경우

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 
https://github.com/colszowka/simplecov#merging-results

하는 것을 잊지 마세요
+0

프로젝트로 돌아와이 솔루션을 직접 사용해 보았을 때 응답으로 플래그를 지정합니다. –

0

위와 같이 aruba 프로세스의 PID를 기반으로 command_name을 설정하면 SimpleCov가 매우 큰 결과 집합을 누적 시키며 이전 실행으로 결과를 오염시킵니다. 같은 인수와 최신 실행됩니다

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

이 결과 에 포함하려면 :

나는 다음과 같이 명령 이름을 설정하는 더 좋은 행운이 있었다.