我认为你自己做可能是一种更好的学习体验,但我会让你开始使用一些伪代码。我会故意松懈我的语法。
require spec-helper
describe FeedbackFormsController
before each
controller should receive :authenticate_user! and return true
describe new
it should assign a new feedback form
get new
assigns feedback_form should be a new Feedbackform
it should call for the referer
request should receive referer
get new
it should set session value
request stub referer and return nonsense
expect
get new
to change session return_to to nonsense
describe create
it should create a new Feebackform
Feebackform should receive new with nonsense
post create nonsense
it should create a new Feebackmailer
mock = mock_model Feedbackform
Feedbackform stub new and return mock
Feedbackmailer should receive new with mock
post create nonsense
it should deliver a message
mock = mock_model FeedbackMailer
Feedbackform stub new
FeedbackMailer stub new and return mock
mock should receive deliver
post create nonsense
it should redirect
Feedbackform stub new
Feedbackmailer stub new
post create nonsense
response should redirect to session[return to]
希望这能让你开始。