0
我在控制器很高興設置閃光燈的消息是這樣的:有沒有可以在rails中設置'全局'flash消息的地方?
redirect_to root_path, error: 'This is a highly eloquent and specialised error message just for you, my iridescent, transcendent and all round marvellous bundle of joy! You are not allowed in here you cheeky chappy, you!'
不過,我覺得我做了很多複製粘貼的,當涉及到刻錄功能規格來測試這些郵件是渲染:
context 'when user has eaten all the pies' do
let(:cheeky) { FactoryGirl.build(:cheeky_user) }
subject { page }
before do
log_in cheeky
click_link 'steal pies'
end
it_should_behave_like 'home page'
it{ should have_selector('.error', text: 'This is a highly eloquent and specialised error message just for you, my iridescent, transcendent and all round marvellous bundle of joy! You are not allowed in here you cheeky chappy, you!') }
end
它可以是一個痛苦時斷言,因爲我缺少一個字符會失敗,但越是這樣,當得到一堆因爲我已經調整了一些錯誤信息沒有規範的。
測試錯誤消息這可能是一個脆弱的規範的例子,但我想測試顯示正確的錯誤消息。
我真的希望能夠做到這一點:
#somewhere in rails
ERROR_MSG_23 = 'This is a highly eloquent and specialised error message just for you, my iridescent, transcendent and all round marvellous bundle of joy! You are not allowed in here you cheeky chappy, you!'
#controller
redirect_to root_path, error: ERROR_MSG_23
#spec
context 'when user has eaten all the pies' do
let(:cheeky) { FactoryGirl.build(:cheeky_user) }
subject { page }
before do
log_in cheeky
click_link 'steal pies'
end
it_should_behave_like 'home page'
it{ should have_selector('.error', text: ERROR_MSG_23) }
end
是否有寶石的呢?或者這可以在香草欄中實施?