1

我是 Rails 的新手,正在阅读 Michael Hartl 的 RubyOnRails 教程……我已经阅读了第 9 章的类似问题,但我没有解决我自己的问题,所以这是我的 github 存储库和失败的测试……也许有人可以帮助我, 非常感谢 ;)

https://github.com/AntonioCortinaL/sample_app

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)>'

在 Paul Fioravanti 回答后编辑:

好的,谢谢...我为此更改了它:

 before do
  sign_in user
  visit edit_user_path(user) 
 end

现在它的 5 个错误

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)>'
4

2 回答 2

1

您的user_pages_spec.rb测试说:

describe "edit" do
  let(:user) { FactoryGirl.create(:user) }
  before { visit edit_user_path(user) }
  # ...
end

你在ingsign_in之前忘记了。visitedit_user_path

这是本教程的等效规范

编辑

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

于 2013-04-10T11:06:09.833 回答
0

确保在运行测试套件之前使用 rails 控制台为每个用户提供有效的记忆令牌。遵循 8.2.4 以获得准确的说明。

于 2014-08-10T21:54:28.090 回答