
取り急ぎ、今年もよろしくお願いします!
describe Array do
describe '#empty?' do
context 'just initialized' do
subject { Array.new }
it { should be_empty }
end
end
end
describe Array do
subject { @array }
context 'just initialized' do
before do
@array = Array.new
end
describe '#empty?' do
it { should be_empty }
end
end
end
テストしている内容(itの中)はどちらも同じです。両者で違うのは(ほぼ)describeとcontextの順番だけです。
describe 'HogeController' do
describe 'GET index' do
context 'login as Teacher' do
...
end
context 'login as Student' do
...
end
end
end
これも同じように、describeとcontextを逆転させると次のようにも書けます。
describe 'HogeController' do
context 'login as Teacher' do
describe 'GET index' do
...
end
end
context 'login as Student' do
describe 'GET index' do
...
end
end
end
ただ、少なくとも普段は下のような書きかたはしません。それは、これから作るのがメソッド(アクション)であり、そのメソッドを検証する観点としてコンテキストがあるからです。