1
我測試了我的Rails應用程序的視圖層。如何使用RSpec模擬出現錯誤的模型
這種觀點是對客戶的模式,在那裏我打電話的錯誤吧,像這樣(HAML):
- if @customer.errors.present?
- flash[:warn] = ""
- @customer.errors.full_messages.each do |msg|
- flash[:warn] += msg + "<br />"
= form_for :customer, :url => customer_registration_path do |f|
- validated = resource.errors.any?
.field{ :class => !validated ? "" : (resource.errors.has_key?(:email) ? "failed" : "passed") }
= f.text_field "email", :placeholder => "почта", :autocomplete => "off"
.status
.field{ :class => !validated ? "" : (resource.errors.has_key?(:password) ? "failed" : "passed") }
= f.password_field "password", :placeholder => "пароль", :autocomplete => "off"
.status
.field{ :class => !validated ? "" : (resource.errors.has_key?(:password_confirmation) ? "failed" : "passed") }
= f.password_field "password_confirmation", :placeholder => "повторите пароль", :autocomplete => "off"
.status
= f.submit "" # Зарегистрироваться
我需要測試的,也就是說存在,來包裹「電子郵件」欄中,標明作爲「失敗」。
如何爲客戶模型編寫模擬模擬相應錯誤的存在?
我認爲這是重複:https://stackoverflow.com/questions/ 6248335 /如何對模擬模型與 - 錯誤 - 使用 - rspec的 – 2014-11-14 02:49:16