首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >第9章测试失败的rails教程

第9章测试失败的rails教程
EN

Stack Overflow用户
提问于 2013-04-10 10:50:36
回答 2查看 534关注 0票数 1

我是Rails的新手,我正在阅读Michael的RubyOnRails教程.我读过关于第9章类似的问题,但我没有解决我自己的问题,所以这里是我的github存储库和失败的测试.也许有人能帮我,非常感谢;)

应用程序

代码语言:javascript
复制
1) UserPages edit page 
 Failure/Error: it { should have_selector('h1',       text: "Update your profile") }
   expected css "h1" with text "Update your profile" to return something
 # ./spec/requests/user_pages_spec.rb:61:in `block (4 levels) in <top (required)>'

2) UserPages edit page 
 Failure/Error: it { should have_selector('title',    text: "Edit user") }
   expected css "title" with text "Edit user" to return something
 # ./spec/requests/user_pages_spec.rb:62:in `block (4 levels) in <top (required)>'

3) UserPages edit page 
 Failure/Error: it { should have_link('change', href: 'http://gravatar.com/emails') }
   expected link "change" to return something
 # ./spec/requests/user_pages_spec.rb:63:in `block (4 levels) in <top (required)>'

4) UserPages edit with invalid information 
 Failure/Error: before { click_button "Save changes" }
 Capybara::ElementNotFound:
   no button with value or id or text 'Save changes' found
 # (eval):2:in `click_button'
 # ./spec/requests/user_pages_spec.rb:67:in `block (4 levels) in <top (required)>'

5) UserPages edit with valid information 
 Failure/Error: fill_in "Name",             with: new_name
 Capybara::ElementNotFound:
   cannot fill in, no text field, text area or password field with id, name, or label 'Name' found
 # (eval):2:in `fill_in'
 # ./spec/requests/user_pages_spec.rb:76:in `block (4 levels) in <top (required)>'

6) UserPages edit with valid information 
 Failure/Error: fill_in "Name",             with: new_name
 Capybara::ElementNotFound:
   cannot fill in, no text field, text area or password field with id, name, or label 'Name' found
 # (eval):2:in `fill_in'
 # ./spec/requests/user_pages_spec.rb:76:in `block (4 levels) in <top (required)>'

7) UserPages edit with valid information 
 Failure/Error: fill_in "Name",             with: new_name
 Capybara::ElementNotFound:
   cannot fill in, no text field, text area or password field with id, name, or label 'Name' found
 # (eval):2:in `fill_in'
 # ./spec/requests/user_pages_spec.rb:76:in `block (4 levels) in <top (required)>'

8) UserPages edit with valid information 
 Failure/Error: fill_in "Name",             with: new_name
 Capybara::ElementNotFound:
   cannot fill in, no text field, text area or password field with id, name, or label 'Name' found
 # (eval):2:in `fill_in'
 # ./spec/requests/user_pages_spec.rb:76:in `block (4 levels) in <top (required)>'

9) UserPages edit with valid information 
 Failure/Error: fill_in "Name",             with: new_name
 Capybara::ElementNotFound:
   cannot fill in, no text field, text area or password field with id, name, or label 'Name' found
 # (eval):2:in `fill_in'
 # ./spec/requests/user_pages_spec.rb:76:in `block (4 levels) in <top (required)>'

编辑保罗·菲奥拉万蒂后回答:

好的,谢谢..。我为了这个改变了它

代码语言:javascript
复制
 before do
  sign_in user
  visit edit_user_path(user) 
 end

现在它的5个错误

代码语言:javascript
复制
1) UserPages edit with valid information 
 Failure/Error: fill_in "Confirm Password", with: user.password
 Capybara::ElementNotFound:
   cannot fill in, no text field, text area or password field with id, name, or label 'Confirm Password' found
 # (eval):2:in `fill_in'
 # ./spec/requests/user_pages_spec.rb:81:in `block (4 levels) in <top (required)>'

2) UserPages edit with valid information 
 Failure/Error: fill_in "Confirm Password", with: user.password
 Capybara::ElementNotFound:
   cannot fill in, no text field, text area or password field with id, name, or label 'Confirm Password' found
 # (eval):2:in `fill_in'
 # ./spec/requests/user_pages_spec.rb:81:in `block (4 levels) in <top (required)>'

3) UserPages edit with valid information 
 Failure/Error: fill_in "Confirm Password", with: user.password
 Capybara::ElementNotFound:
   cannot fill in, no text field, text area or password field with id, name, or label 'Confirm Password' found
 # (eval):2:in `fill_in'
 # ./spec/requests/user_pages_spec.rb:81:in `block (4 levels) in <top (required)>'

4) UserPages edit with valid information 
 Failure/Error: fill_in "Confirm Password", with: user.password
 Capybara::ElementNotFound:
   cannot fill in, no text field, text area or password field with id, name, or label 'Confirm Password' found
 # (eval):2:in `fill_in'
 # ./spec/requests/user_pages_spec.rb:81:in `block (4 levels) in <top (required)>'

5) UserPages edit with valid information 
 Failure/Error: fill_in "Confirm Password", with: user.password
 Capybara::ElementNotFound:
   cannot fill in, no text field, text area or password field with id, name, or label 'Confirm Password' found
 # (eval):2:in `fill_in'
 # ./spec/requests/user_pages_spec.rb:81:in `block (4 levels) in <top (required)>'
EN

回答 2

Stack Overflow用户

发布于 2013-04-10 11:06:09

测试说:

代码语言:javascript
复制
describe "edit" do
  let(:user) { FactoryGirl.create(:user) }
  before { visit edit_user_path(user) }
  # ...
end

你忘了sign_in,然后visitvisitedit_user_path

以下是本教程的相应规范

编辑

至于第二个问题,请参阅Rails教程这里中的等效链接。比较一下您的user_pages_spec.rb 这里这里:您可以看到您正在尝试fill_in一个"Confirm Password"字段和一个"Confirmation"字段,其中只有一个实际存在于您的应用程序中……

票数 1
EN

Stack Overflow用户

发布于 2014-08-10 21:54:28

确保在运行测试套件之前,使用rails控制台为每个用户提供一个有效的记住令牌。按照8.2.4获得精确的指示。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15923769

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档