ฉันค่อนข้างใหม่กับ Ruby & Rails; ยังไม่ได้เขียนโปรแกรมมากนัก แต่มีพื้นฐานด้านเทคโนโลยี
ฉันได้สร้างฟังก์ชันการทำงานเพียงเล็กน้อยซึ่งส่วนใหญ่ใช้ Railscasts และต้องการใช้ TDD และกำลังย้อนกลับไปและพยายามสร้างการทดสอบง่ายๆ ก่อนที่จะก้าวไปข้างหน้า
ฉันติดอยู่กับการทดสอบมุมมองและไม่พบสิ่งที่คล้ายกันมากพอที่จะทราบวิธีแก้ไขปัญหานี้ ฉันได้ดู Railscasts หนังสือ The RSpec ฯลฯ และค้นหามามากมาย
ดูเหมือนว่าฟังก์ชันที่ต้องการจะทำงานได้ดี แต่การทดสอบล้มเหลว
ความช่วยเหลือหรือทิศทางใด ๆ ที่ชื่นชม
ข้อผิดพลาด:
Failure/Error: render
ActionView::Template::Error:
No route matches {:action=>"show", :controller=>"email_verifies", :id=>nil}
# ./app/views/email_verifies/edit.html.haml:3:in `_app_views_email_verifies_edit_html_haml__3756516833416545914_70345184965780'
# ./spec/views/email_verifies/edit.html.haml_spec.rb:6:in `block (2 levels) in <top (required)>'
รหัส:
app/views/email_verify/edit.html.haml
%h1 Verify Email Address
= form_for @user, :url => email_verify_path(params[:id]) do |f|
.actions
= f.submit "Verify Email Address"
ข้อมูลจำเพาะ/views/email_verify/edit.html.haml_spec.rb
require 'spec_helper'
describe "email_verifies/edit.html.haml" do
let(:user) { FactoryGirl.create(:user, :email_verify_token => "anything") }
it "displays the text on the rendered page" do
render
rendered.should have_content("Verify Email Address")
end
end
ข้อมูลจำเพาะ/โรงงาน/factory.rb
FactoryGirl.define do
factory :user do
sequence :email do |n|
"foo#{n}@example.com"
end
password "secret"
end
end
ส่วนหนึ่งของ app/controllers/email_verifies_controller.rb (ไม่มีการดำเนินการ 'แสดง' ในคอนโทรลเลอร์นี้)
def edit
@user = User.find_by_email_verify_token(params[:id])
unless @user
redirect_to signup_path, :alert => "This email verification has expired. Please sign up again."
end
end
บางเส้นทาง:
edit_email_verify GET /email_verifies/:id/edit(.:format) email_verifies#edit
email_verify GET /email_verifies/:id(.:format) email_verifies#show
email_verifies GET /email_verifies(.:format) email_verifies#index
edit_email_verify GET /email_verifies/:id/edit(.:format) email_verifies#edit
email_verify GET /email_verifies/:id(.:format) email_verifies#show
PUT /email_verifies/:id(.:format) email_verifies#update
เวอร์ชัน:
ทับทิม 1.9.3p362
ราง (3.2.13)
Factory_girl (4.2.0)
Factory_girl_rails (4.2.1)
rspec (2.13.0)
rspec-core (2.13.1) )
rspec-expectations (2.13.0)
rspec-mocks (2.13.1)
rspec-rails (2.13.2)