我是测试和 Rails 的新手,但我正试图让我的 TDD 进程正常运行。
我想知道您是否使用任何范式来测试 has_many :through 关系?(或者我想一般只是 has_many )。
例如,我发现在我的模型规范中,我肯定会编写简单的测试来检查关系的两端是否有相关方法。
IE:
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
我还缺少什么?谢谢!!