0
레일에서 루비와 루비를 배우는 데 2 주 밖에 걸리지 않습니다. 현재 내 문제는 내가 지금은 RSpec에 이것으로 테스트하고있어, 너무 많은 이해하지 못하는 일치 테 경로 함께 : 난 내 UserController테스트 : 경로가 일치하지 않습니다 {: action => "show", : controller => "users", : id => nil}
class UsersController < ApplicationController
def new
@user = User.new
end
def create
@user = User.new(params[:user])
if @user.save
redirect_to user_session_path
else
redirect_to new_user_session_path
end
end
def show
@user = User.find(params[:id])
#redirect_to @user
end
end
을에이
require 'spec_helper'
describe UsersController do
it "should redirect to the user show page" do
post :create, :users => @attr
response.should redirect_to(user_path(assigns(:users)))
end
describe "signup" do
before { visit new_user_registration_path }
let(:submit) { "Sign up" }
describe "with invalid information" do
it "should not create a user" do
expect { click_button submit }.not_to change(User, :count)
end
end
describe "with valid information" do
before do
fill_in "Email", :with=> "[email protected]"
fill_in "Password", :with=> "foobar"
#fill_in "password_confirmation", :with=> "foobar"
end
it "should create a user" do
expect { click_button submit }.to change(User, :count).by(1)
end
end
end
end
하지만 난 실행할 때 대신 (단수) 사용자의 사용자 (복수)에 두 번 언급하고 귀하의 사양에
Failures:
1) UsersController should redirect to the user show page
Failure/Error: response.should redirect_to(user_path(assigns(:users)))
ActionController::RoutingError:
No route matches {:action=>"show", :controller=>"users", :id=>nil}
# ./spec/controllers/user_controller_spec.rb:7
2) UsersController signup with valid information should create a user
Failure/Error: expect { click_button submit }.to change(User, :count).by(1)
count should have been changed by 1, but was changed by 0
# ./spec/controllers/user_controller_spec.rb:29
내가 변경을하고, 지금 그러나 다만이 같은 동일한 오류를 보여줍니다 없음 경로 일치 {: 컨트롤러 => "사용자" 사용자 ID : nil, 전자 메일 : "", encrypted_password : "", reset_password_token : nil, reset_password_sent_at : nil, remember_created_at : nil, sign_in_count : 0, current_sign_in_at : nil, last_sign_in_at : nil, current_sign_in_ip : nil, last_sign_in_ip : nil, , created_at : nil, updated_at : nil>, : action => "show"} – Asantoya17
또한 변경 : 'post : create, : user => @ attr'? 또한 @attr은 어디에 설정합니까? –
예, 당신이 말했던 것입니다 – Asantoya17