2
我正在使用Ruby on Rails 3.0.9,RSpec-rails 2和FactoryGirl。我試圖用RSpec its
功能中的\檢查kind_of?
,至count
,...數組中存在的項目。也就是說,我想提出類似如下:如何檢查'kind_of?','計數'或在RSpec'its'特徵中運行其他方法?
subject do
Factory(
:user,
:articles => 3.times.inject([]) { |articles,i|
articles << Factory(
:article,
:user_id => Factory(:user)
)
}
end
# Note the (wrong!) usage of 'first', 'count' methods
its(:articles) { first.should be_kind_of(Article) }
its(:articles) { count.should == 10 }
但是,因爲我得到的錯誤,似乎不可能使在我在上面的代碼做了它(錯了!)的方式。 有沒有辦法做到這一點(檢查kind_of?
,count
,...)?