【发布时间】:2011-04-27 18:55:07
【问题描述】:
我是测试和 Rails 的新手,但我正试图让我的 TDD 流程正常运行。
我想知道您是否使用任何范式来测试 has_many :through 关系? (或者我想一般只是 has_many)。
例如,我发现在我的模型规范中,我肯定会编写简单的测试来检查关系的两端是否有相关方法。
即:
require 'spec_helper'
describe Post do
before(:each) do
@attr = { :subject => "f00 Post Subject", :content => "8ar Post Body Content" }
end
describe "validations" do
...
end
describe "categorized posts" do
before(:each) do
@post = Post.create!(@attr)
end
it "should have a categories method" do
@post.should respond_to(:categories)
end
end
end
然后在我的类别规范中我进行反向测试并检查@category.posts
我还缺少什么?谢谢!!
【问题讨论】:
标签: ruby-on-rails ruby rspec has-many has-many-through