1
在Firefox中,如果我嘗試提交沒有標題的帖子,我會得到:1個錯誤禁止將此帖保存。爲什麼我的測試不適用於此表單?
但是當我運行我的測試。這是一個不同的故事。
我的帖子模特有validates_presence_of :title
。我的測試是這樣的:
require 'spec_helper'
describe 'Users' do
it 'registered users should not be able to post without a title', :js => true do
user = Factory(:user)
visit new_post_path
current_path.should eq(new_post_path)
fill_in 'post[markdown_description]', :with => 'Bar'
click_on 'Submit your post'
page.should have_content('error')
end
end
順便說一句,我使用的硒(:js => true
),因爲我提交按鈕實際上是一些JS的錨鏈接。基本上,當鏈接被點擊時,JS觸發表單被提交。
Rspec的返回:
Running: spec/requests/users_spec.rb
F
Failures:
1) Users registered users should be able to post
Failure/Error: page.should have_content('error')
expected there to be content "error" in ""
# ./spec/requests/users_spec.rb:13:in `block (2 levels) in <top (required)>'
Finished in 7.9 seconds
1 example, 1 failure
Failed examples:
rspec ./spec/requests/users_spec.rb:4 # Users registered users should be able to post