Tbpgr Blog

Recruiting Operations tbpgr(てぃーびー) のブログ

RSpec | rspec metadata | described_class

概要

rspec metadata | described_class

詳細

described_class変数でトップレベルのdescribeにクラスが設定されていた場合、
該当クラスを取得できます。

hige_spec.rb

require 'spec_helper'
require 'hige'

describe Hige do
  it "hige1" do
    puts described_class
    puts described_class.new("msg").hige
  end
end

テスト結果

$ rspec
Run options: include {:focus=>true}

All examples were filtered out; ignoring {:focus=>true}
Hige
hige-str
.

Finished in 0 seconds
1 example, 0 failures