使用 RSpec 编写测试有 2 种语法 (afaik):
经典/旧方式:
  describe "when user_id is not present" do
    before { @micropost.user_id = nil }
    it "should not be valid" do
      @micropost.should_not be_valid
    end
  end
失败时会出现此错误:
rspec ./spec/models/micropost_spec.rb:19 # 当 user_id 不存在时微贴应该是无效的
和简短的语法:
  describe "when user_id is not present" do
    before { @micropost.user_id = nil }
    it { should_not be_valid }
  end
失败时会出现此错误:
rspec ./spec/models/micropost_spec.rb:18 # 当 user_id 不存在时的微博
最后一个缺少“不应有效”部分。
有没有办法获得完整的测试失败消息,也许是我不知道的标志?
注意:无论如何,仍然存在更完整的错误消息:
  1) Micropost when user_id is not present 
     Failure/Error: it { should_not be_valid }
       expected #<Micropost id: nil, content: "Lorem ipsum", user_id: nil, created_at: nil, updated_at: nil> not to be valid
     # ./spec/models/micropost_spec.rb:18:in `block (3 levels) in <top (required)>'
但最后的回顾是不完整的。