이 테스트를 통과하려고했지만 도움이 될 도움이 필요한 사람이 필요합니다. 지금은RSpec 기능 테스트가 잘못된 위치로 리디렉션됩니다.
describe 'PUT posts/:id' do
describe 'with valid attributes' do
let(:mock_post) { mock_model('Post', title: 'hey! iam a mock!', description: 'a sexy model', location: 'everywhere') }
login_user
it 'should update the object and redirect to the post' do
Post.stub!(:find).with(mock_post.id).and_return(mock_post)
Post.any_instance.should_receive(:update_attributes).with({"these" => "params"}).and_return(true)
response.should redirect_to post_path(mock_post)
put :update, id: mock_post.id, post: { these: 'params' }
end
it 'should have a current_user' do
subject.current_user.should_not be_nil
end
end
, 위 테스트 및 다음과 같은 오류가 뭔가를 가지고 :
1) PostsController PUT posts/:id with valid attributes should update the object and redirect to the post
Failure/Error: response.should redirect_to post_path(mock_post)
Expected response to be a <:redirect>, but was <200>
# ./spec/controllers/posts_controller_spec.rb:200:in `block (4 levels) in <top (required)>'
가 PostsController : 또한
class PostsController < ApplicationController
load_and_authorize_resource except: [:index, :show]
before_filter :authenticate_user!, except: [:index, :show, :tags]
before_filter :find_post, only: [:show, :edit, :update, :suspend, :suspend_alert]
def update
if @post.update_attributes(params[:post])
flash[:success] = 'Cool.'
redirect_to post_path(@post)
else
render :edit
end
end
protected
def find_post
@post = Post.find(params[:id])
end
end
, 어떻게 내가 render :edit
에 대한 테스트를 작성해야 부품?
'login_user'가 갈해야'전 (각)' 블록; mock_post ID의 값을 하드 코드하지 마십시오. 그냥'1001'을'mock_post.id'로 대체하십시오. 'put' 테스트 액션을 기대 한대로 돌리십시오. 각 예제에 대해'put' 테스트 액션을 반복하십시오. – zetetic
확인. 지침에 따라 소식을 업데이트했습니다. 'login_user'는'Devise' [wiki 페이지] (https://github.com/plataformatec/devise/wiki/How-To:-Controllers-and-Views-tests-with)에서 복사 한'ControllerMacro'입니다. -Rails-3- (및 -rspec)). –
'log/test.log'를 체크하면 리다이렉트가 일어나지 않는 이유를 알 수 있습니다. – zetetic