我正在尝试为一个简单的应用程序的posts / show.html.erb视图编写规范,我将它们放在一起学习rspec。我试图弄清楚额外的“%2F”来自哪里,我有点难过。有什么想法吗?
我的规格......
it "should render a form to add a comment" do
render "posts/show.html.erb"
response.should have_selector("form[method=post]", :action => post_comments_path([@post, @comment])) do |form|
form.should have_selector("input[name='comment[author_name]']")
form.should have_selector("textarea[name='comment[body]']")
form.should have_selector("input[type=submit]")
end
end
带有额外%2F的规格输出......
'posts/show.html.erb should render a form to add a comment' FAILED
expected following output to contain a <form[method=post] action='/posts/1001%2F/comments'/> tag:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body>
<p>#[Post:0x1288146 @name="Post_1001"]
#[Post:0x1288146 @name="Post_1001"]
#[Post:0x1288146 @name="Post_1001"]
Comments<br></p>
<form action="/posts/1001/comments" class="new_comment" id="new_comment" method="post">
</form>
</body></html>
./spec/views/posts/show.html.erb_spec.rb:13:
答案 0 :(得分:0)
你的post-id在某种程度上是否有一个尾随空格?
答案 1 :(得分:0)
你的form_for在erb中是什么样的?对于在rails中工作正常的某些路由场景,Rspec可能会表现得很奇怪。
您使用的是什么版本的rspec(最近是否更新过)?
为什么要指定你的观点而不只是使用黄瓜?