2009-10-05 17 views
18

私はここに行く//テストでテストコンテキスト内で「Foo.Sub-fooがバーなければならない」取得できます。このrspecの現在のコンテキスト名を取得するには?

describe 'Foo' do 
    // init go here 
    describe 'Sub-Foo' do 
     it "should Bar" do 
     // test go here 
     // puts ... <-- need "Foo.Sub-Foo should Bar" here 
     end 
    end 
end 

のようなRSpecのを持っている場合は?

specdocsで書かれた書式と似ていますが、それを内部でどうやって取得するのですか?

答えて

22
describe 'Foo' do 
    describe 'Sub-Foo' do 
     it "should Bar" do 
     puts "#{self.class.description} #{description}" 
     end 
    end 
end 

上記のコードは、「Foo Sub-Foo should Bar」を出力します。

+0

これは私が探しているものです。ありがとう – Jirapong

+3

#{description}は私のためには機能しません。 –

関連する問題