경로에 따라Turnip에 쓰인feature에 다른 유형을 추가하는 방법

4273 단어 RubyTurnip
이 글은 Okinawa.rb Advent Calendar 2018 12일째 되는 글이다.
어제@hanachin_선생님load 상수 이름을 다시 쓰는 importasgem 소개입니다.
내일은 @hanachin_씨의 Ruby로 JavaScript의 Template literals 따라하기입니다.

Turnip으로 여러 type의feature 견본 응용 프로그램 쓰기


창고는 다음과 같다.
https://github.com/hanachin/turnip_example
Turnip 테스트는 다음과 같습니다.
  • spec/models/article.feature: metadata[:type]:model모델spec
  • spec/system/article.feature: metadata[:type]:system의 시스템 스펙트럼
  • Turnip.type 영원히 하나


    Turnip.type을 설정하면 Turnip의 example 메타데이터 type을 변경할 수 있습니다.
    하지만 Turnip.type은 하나만 설정할 수 있습니다!
    예를 들어 모델 스펙이나 시스템 스펙 다 Ghekin으로 쓰려고 하면 곤란해요.

    Turnip의 example 그룹에 대해 다른 type을 설정하는 방법


    define_derived_metadata를 사용하면 덮어쓸 수 있습니다!도시락
    예를 들어 spec/models/article.feature의 type을 모델로 변경하려면 다음과 같은 file_path 옵션에서feature와 일치하는 정규 표현식을 지정하고 덮어쓰십시오 metadata[:type].
    RSpec.configure do |config|
      config.define_derived_metadata(:file_path => %r{/spec/models/.*.feature}) do |metadata|
        metadata[:type] = :model
      end
    end
    
    모델 이외의feature가 시스템 스펙으로 작동하고자 하는 경우 다음과 같이 기본Turnip.type:system,spec/models이하의feature의 type을:model으로 설정하면 된다.
    Turnip.type = :system
    RSpec.configure do |config|
      config.define_derived_metadata(:file_path => %r{/spec/models/.*.feature}) do |metadata|
        metadata[:type] = :model
      end
    end
    

    총결산

  • Turnip.type를 사용하면 Turnip의 example groupo type
  • 을 설정할 수 있습니다.
  • Turnip.type 하나만 설정 가능

  • 사용define_derived_metadata 경로에 따라 메타데이터를 다시 쓸 수 있음
  • 그럼 Turnip 생활 잘 보내세요~

    좋은 웹페이지 즐겨찾기