간단한 응용 프로그램을 만들려고합니다. 브라우저에서 Im을 테스트 할 때 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
두 번째 문제는 ... 이이었다 나는이 같은 테스트 결과를 가지고 시간 : 내가 STH 할 때까지 나를 몇 시간 동안 내 머리를 꺼내 일으키는
<html><body>You are being <a href="http://test.host/websites/list">redire cted</a>.</body></html>
가 ... (내가 정말 무엇을 알고하지 않는 것) 그것은 사라졌습니다. 그러나 그것은 내가 미래에 내 행복을 망칠 수 있다고 생각할 때 나를 지옥처럼 무서워하게 만듭니다.
이 문제에 대한 의견을 보내 주시면 감사하겠습니다.
아래 내 대답을 게시 ... –