Ruby on rails 如何检查';一种';,至';计数';或者在RSpec'内运行其他方法;其';特征?
我正在使用RubyonRails3.0.9、RSpecRails2和FactoryGirl。我正在尝试检查Ruby on rails 如何检查';一种';,至';计数';或者在RSpec'内运行其他方法;其';特征?,ruby-on-rails,ruby,ruby-on-rails-3,rspec,rspec2,Ruby On Rails,Ruby,Ruby On Rails 3,Rspec,Rspec2,我正在使用RubyonRails3.0.9、RSpecRails2和FactoryGirl。我正在尝试检查的种类,以计数。。。在RSpecits功能中使用\显示在数组中的项。也就是说,我想做如下的事情: subject do Factory( :user, :articles => 3.times.inject([]) { |articles,i| articles << Factory(
的种类
,以计数
。。。在RSpecits
功能中使用\显示在数组中的项。也就是说,我想做如下的事情:
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 }
subject do
工厂(
:用户,
:articles=>3.times.injection([]){| articles,i|
物品工厂(:用户)
)
}
结束
#注意“first”、“count”方法的用法(错误!)
它的(:articles){first.should_kind_of(articles)}
它的(:articles){count.should==10}
但是,由于我有错误,似乎不可能以我在上面代码中所做的(错误!)方式来做有没有办法(检查种类?
,计数
,…)?:
describe Person do
subject do
Person.new.tap do |person|
person.phone_numbers << "555-1212"
end
end
its("phone_numbers.first") { should eq("555-1212") }
end
its('articles.first') { should be_kind_of(Article) }
its('articles.count') { should == 10 }