我试图作一个简单的说明。 当在浏览器中测试时,便会做一些细微的工作。 当我试图与RSpec(2.5)进行一些测试时,它在对控制器进行以下测试时失败了。
Here s my create method:
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
网站_ Controller_spec.rb:34 系指制造方法
然而,这一测试是正确的(关于不正确的数据,应当重新定位到有具体所有权的新地点):
it "should have the right title" do
post :create, :website => @attr.merge(:adres => "")
response.should have_selector("title", :content=>"Dodaj stronę WWW")
end
The second problem is... There was a time when I ve got a test result like this:
<html><body>You are being <a href="http://test.host/websites/list">redire cted</a>.</body></html>
......这给我带来了一些时间,直到我做完th(我并不真正知道什么)和去了。 然而,当我认为它今后能够恢复我幸福的废墟时,它使我感到悲伤。
任何这方面的想法都将受到高度赞赏。