我正在構建一個實現忘記密碼功能的Rails應用程序。我需要使用RSpec爲它編寫測試用例。我對RSPEC非常陌生,並從教程和屏幕錄像中瞭解了rspec的工作原理。但我不確定如何對控制器進行測試。在我的控制器方法中,如果我從數據庫中檢索用戶,那麼如何使用rspec來測試它。我是否提供了用於測試rspec的虛擬數據?請找到下面的例子。Rspec控制器測試
在Usercontroller.rb
高清forgot_pass
user = User.find_by_email(params[:email])
forget_pass = ForgetPassword.new
forgetpass.userid = user.email
forgetpass.status = true
forgetpass.save!
redirect_to login_url
末
在我password_reset_spec
require 'spec_helper'
describe "PasswordResets" do
it "emails when user requesting password reset" do
user=User.new
forget_pwd = ForgetPassword.new
#forget_pwd.userid.should == "prasad"
#forget_pwd.token.should == "123456"
forget_pwd.userkey = "14dd"
visit auth_index_path
click_link "Forgot Password"
fill_in "Email", :with=> '[email protected]'
click_button "Submit"
current_path.should eq(login_path)
page.should have_content("A verification mail has been sent to your email id. Click on the confirmation link to change the password")
last_email.to.should include('[email protected]')
end
end
在測試如何測試用戶是否存在,並分配屬性。就我而言, 用戶= User.find_by_email(PARAMS [:郵箱]) forgetpass.userid = user.email
請幫我在Rspec的