我无法使用Fabricate gem获取我的一个rspec / capybara集成规范。
这是我的规格:
it "shows current node as top node on page" do
@node = Fabricate(:node)
visit node_path(@node)
page.should have_content(@node.title)
end
我的制作者:
Fabricator(:node) do
title { Faker::Lorem.words(3).join(" ") }
description {Faker::Lorem.paragraphs(3).join("\n") }
end
我的节点的show动作:
def show
@node = Node.find(params[:id])
end
我的show.html.haml:
%h1= @node.title
我的规格输出:
1) Node shows current node as top node on page
Failure/Error: page.should have_content(@node.title)
expected #has_content?("nostrum qui sed") to return true, got false
最后,我在视图上放了一个save_and_open_page,一个debug(params)和debug(@node),这是输出:
action: show
controller: nodes
id: "1"
--- !ruby/object:Node
attributes:
id: "1"
title:
description:
created_at: 2011-06-01 03:14:45.645663
updated_at: 2011-06-01 03:14:45.645663
attributes_cache: {}
changed_attributes: {}
destroyed: false
marked_for_destruction: false
new_record: false
previously_changed: {}
readonly: false
任何人都知道为什么标题和描述没有保存到数据库中?
提前致谢!
-----------------更新6-1 ------------------------
我的节点模型:
class Node < ActiveRecord::Base
attr_accessor :title, :description
validates :title, :presence => true
validates :description, :presence => true
end
答案 0 :(得分:0)
介于两者之间
@node = Fabricate(:node)
visit node_path(@node)
尝试插入保存!看看它是否是某种验证问题:
@node = Fabricate(:node)
@node.save!
visit node_path(@node)
答案 1 :(得分:0)
你应该做一个:
class Node < ActiveRecord::Base
attr_accessible :title, :description
validates :title, :presence => true
validates :description, :presence => true
end
答案 2 :(得分:0)
你的模特应该是
class Node < ActiveRecord::Base
validates :title, :presence => true
validates :description, :presence => true
end