Tbpgr Blog

Employee Experience Engineer tbpgr(てぃーびー) のブログ

RSpec | rspec command | tag option

概要

rspec command | tag option

詳細

rspec commandのtag optionで行数指定で実行します。

サンプルテストコード(hige_spec.rb)

# encoding: utf-8
require "spec_helper"
require "hige"

describe Hige do
  it "hige1 1", :hige1 => "hige", hige: true do
    # some spec
  end

  it "hige1 2", :hige1 => "hige", hige: true do
    # some spec
  end

  it "hige2", hige: true do
    # some spec
  end
end

rspec tagを試す

全てのケースに共通するタグを指定
$ rspec -fs -t hige
Run options: include {:focus=>true, :hige=>true}

Hige
  hige1 1
  hige1 2
  hige2

Finished in 0.001 seconds
3 examples, 0 failures
hige1の値がhigeのタグのみ抽出
$ rspec -fs -t hige1:hige
Run options: include {:focus=>true, :hige1=>"hige"}

Hige
  hige1 1
  hige1 2

Finished in 0 seconds
2 examples, 0 failures
hige1の値がhigeのタグ以外を抽出
$ rspec -fs -t ~hige1:hige
Run options:
  include {:focus=>true}
  exclude {:hige1=>"hige"}

All examples were filtered out; ignoring {:focus=>true}

Hige
  hige2

Finished in 0 seconds
1 example, 0 failures