【发布时间】:2011-08-01 01:29:38
【问题描述】:
再次,似乎被困在一个简单的视图测试上。代码如下:
require 'spec_helper'
describe "posts/show.html.erb" do
setup do
@post = Factory(:post)
end
it "should not render a canonical link rel" do
get :show, :id => @post.id
response.should_not have_tag("link[rel=?]", "canonical")
end
end
当我从控制台执行 Factory(:post) 时,没有问题,可以完美地创建它。但是当我在命令行上运行它时,我得到以下信息:
rspec spec/views/posts/show.html.erb_spec.rb
F
Failures:
1) posts/show.html.erb should not render a canonical link rel
Failure/Error: get :show, :id => @post.id
RuntimeError:
Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id
# ./spec/views/posts/show.html.erb_spec.rb:11
Finished in 0.06532 seconds
1 example, 1 failure
任何想法我错过了什么?
【问题讨论】:
标签: ruby-on-rails-3 testing rspec factory-bot