0
我想做一个简单的应用程序。当我在浏览器中进行测试时,everytyhing工作得很好。 Howerver,当我尝试运行RSpec(2.5)的某些测试时,它失败了:创建控制器测试。RSpec和怪异的测试结果
这里是我的创造方法:
def create
@website = Website.new(params[:website])
if @website.save
flash[:notice] = "Website created."
redirect_to(:action => 'list')
else
render('new')
end
end
控制器测试:
describe WebsitesController do
render_views
.
.
.
describe "POST 'create'" do
before(:each) do
@attr = { :adres => "www.excc.pl", :opis => "aaa "*22, :tagi => "aaa aaa aaa",
:preview => File.new(Rails.root + 'spec/fixtures/rails.png'),
:preview_mini => File.new(Rails.root + 'spec/fixtures/rails.png')}
end
describe "success" do
it "should have the right title" do
response.should have_selector("title", :content=>"Lista witryn w portfolio")
end
end
.
.
.
这个测试的结果:
1) WebsitesController POST 'create' should have the right title
Failure/Error: response.should have_selector("title", :content=>"Lista witryn w portfolio")
expected following output to contain a <title>Lista witryn w portfolio</title> tag:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
# ./spec/controllers/websites_controller_spec.rb:34:in `block (4 levels) in
websites_controller_spec.rb:34指到c reate方法
然而,这个测试是正确传递(对于不正确的数据应该被重定向回与指定标题“新”的网站):
it "should have the right title" do
post :create, :website => @attr.merge(:adres => "")
response.should have_selector("title", :content=>"Dodaj stronę WWW")
end
第二个问题是...... 有一个当我有一个测试结果这样的时刻:
<html><body>You are being <a href="http://test.host/websites/list">redire cted</a>.</body></html>
...这是造成我拉我的头发了一段时间,直到我做了某事(我真的不知道是什么)和它不见了。然而,当我认为它可能会在未来回来毁了我的幸福时,它会让我感到害怕。
对此的任何想法将不胜感激。
我已经在下面发布我的答案... – 2011-04-04 09:27:00