我一直在愉快地使用应该是这样的:
context "test world" do
setup do
@world = ...
end
should "be spinning" do
assert_equal "spinning", @world.movement
end
... and so on
end
我需要一个技巧来理解这种变化:
class PostTest < Test::Unit::TestCase
should belong_to(:user)
should have_many(:tags).through(:taggings)
should validate_uniqueness_of(:title)
should validate_presence_of(:body).with_message(/wtf/)
should validate_presence_of(:title)
should validate_numericality_of(:user_id)
end
我不清楚的是各种“应该属于_to(:user)”等等的操作。换句话说,很明显它们是在 Post 的一个实例上运行的,但是是什么决定了它呢?'should xxx' 行的主题是什么?
我知道这是一个新手问题,所以任何指针都会很棒!