0
내 레이크 사양을 실행하면 ResidenceInformations 컨트롤러 용 RSpec이 실패합니다.Rspec 컨트롤러 사양이 실패했습니다.
class ResidenceInformationsController < ApplicationController
def index
end
def show
render partial: 'subregion_select'
end
def new
@residence_info = ResidenceInformation.new
@saved_residence_info = ResidenceInformation.where('applicant_id=?', current_applicant.id)
end
def create
@residence_info = ResidenceInformation.new(residence_informations_params)
@residence_info.state = params[:order][:state]
@residence_info.applicant_id = current_applicant.id
#@residence_info.residence_type_id = params[:residence_type][:residence_type_id]
@residence_info.save!
if cookies[:residence_next] == 'true' && cookies[:add_another] == 'false'
redirect_to new_employment_information_path
elsif cookies[:residence_next] == 'false' && cookies[:add_another] == 'true'
#cookies[:add_another] = 'false'
redirect_to request.referer
elsif cookies[:residence_next] == 'false' && cookies[:add_another] == 'false'
redirect_to request.referer
end
end
def edit
@residence_info = ResidenceInformation.find(params[:id])
end
def update
end
def destroy
end
def subregion_options
render partial: 'subregion_select'
end
private
def residence_informations_params
params.require(:residence_information).permit(:address1, :address2, :country, :state, :city, :zip, :reason_for_moving, :resident_since, :resident_upto, :was_notice_given, :monthly_rent, :residence_type_id, :applicant_id)
end
end
를 다음과 같이 내 컨트롤러 코드는 그리고 이것은 위에서 언급 한 컨트롤러
require 'rails_helper'
RSpec.describe ResidenceInformationsController, :type => :controller do
describe 'GET #new' do
login_applicant
it 'should have a current_applicant' do
subject.current_applicant.should_not be_nil
end
it 'assigns a new ResidenceInformation to @residenceinfo' do
#residenceinfo = FactoryGirl.create(:residence_information, address1: 'dsada', country: 'india', state: 'wb', city: 'kolkata', zip: '700091', reason_for_moving: 'none', resident_since: '2015-01-05', was_notice_given: 'true', residence_type_id: 1, applicant_id: 13)
#puts"****************#{residenceinfo.inspect}***********************"
get :new
assigns(:residenceinfo).should be_a_new(ResidenceInformation)
end
it 'renders the :new template' do
get :new
response.should render_template :new
end
end
describe 'POST create' do
login_applicant
context 'with valid attributes' do
it 'should have a current_applicant' do
subject.current_applicant.should_not be_nil
end
it 'create a new ResidenceInformation' do
expect{
post :create, residenceinformation: FactoryGirl.create(:residence_information, address1: 'dsada', country: 'india', state: 'wb', city: 'kolkata', zip: '700091', reason_for_moving: 'none', resident_since: '2015-01-05', was_notice_given: 'true', residence_type_id: 1, applicant_id: 13)
}.to change(ResidenceInformation, :count).by(1)
end
end
end
end
이 사양 파일
Failure/Error: assigns(:residenceinfo).should be_a_new(ResidenceInformation)
expected nil to be a new ResidenceInformation(id: integer, address1: string, address2: string, country: string, state: string, city: string, zip: string, monthly_rent: integer, reason_for_moving: string, resident_since: date, resident_upto: date, was_notice_given: boolean, created_at: datetime, updated_at: datetime, residence_type_id: integer, applicant_id: integer)
# ./spec/controllers/residence_informations_controller_spec.rb:17:in `block (3 levels) in <top (required)>'
으로 실행했을 때 다음과 같은 오류를 얻고 내 사양 파일입니다 저는 RSpec에 완전히 익숙하지 않았기 때문에 여러분에게 도움이되는 어떤 종류의 도움에 감사 할 것입니다. 사전
죄송합니다 편집 감사, 내가 잘못된 스펙 파일을 부여했다. 이제 오른쪽이 부여됩니다
위의 파일은'./spec/controllers/residence_informations_controller_spec.rb'입니다. 사양 파일 자체에 포함되지 않았 음에 언급 된 주장을 볼 수 있습니다. 즉, 'assigns (: residenceinfo) .should be_a_new (ResidenceInformation) ' – anyarms
@anyarms 잘못된 사양 파일 코드를 제공했습니다. 지금 나는 올바른 것을 주었고 당신이 제안했지만 여전히 같은 오류를 얻는 변화를 만들었습니다. –