0
请告诉我,为什么会发生?为什么我的验收测试中出现错误?
我不明白,如果我写:
feature "Article Creation" do
#here i write (:all)
before(:all) do
sign_up_helper
end
我得到的错误:
Article Creation allows user to visit to creating article page
Failure/Error: fill_in :article_title, :with => 'test_title'
Capybara::ElementNotFound:
Unable to find field :article_title
或
1) Article Creation allows user to visit to article page
Failure/Error: expect(page).to have_content I18n.t('articles.articles_new')
expected to find text "New Article:" in "Toggle navigation Blog Rails New Contacts Sign in --- !ruby/hash:ActionController::Parameters controller: devise/sessions action: new {\"controller\"=>\"devise/sessions\", \"action\"=>\"new\"} nil You need to sign in or sign up before continuing. Sign in: Email Password Remember me Sign up Forgot your password?"
,但是,如果我写:
feature "Article Creation" do
#here i write(:each)
before(:each) do
sign_up_helper
end
没关系。所有的测试工作。我的问题 - 为什么?
这是我测试:
*#before all test visitor signs up
#here I've changed :all and :each*
feature "Article Creation" do
before(:all) do
sign_up_helper
end
scenario "allows user to visit to article page" do
visit new_article_path
expect(page).to have_content I18n.t('articles.articles_new')
end
scenario "allows user to visit to created article page" do
visit new_article_path
fill_in :article_title, :with => 'test_title'
fill_in :article_text, :with => 'example_text'
click_button 'Save Article'
expect(page).to have_content 'example_text'
end
这是sign_up_helper方法:
#spec/support/session_helper.rb
def sign_up_helper
visit new_user_registration_path
fill_in :user_email, :with => '[email protected]'
fill_in :user_username, :with => 'mike'
fill_in :user_password, :with => '[email protected]#'
fill_in :user_password_confirmation, :with => '[email protected]#'
click_button 'Sign up'
end
这是HTML表单:
<p>
<label for="article_title">Title</label><br/>
<input type="text" name="article[title]" id="article_title" />
</p>
<p>
<label for="article_text">Text</label><br/>
<textarea name="article[text]" id="article_text">
</textarea>
</p>
我该怎么做,它会正确吗? – Vladimir
做'之前:每个'。 –