Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 3 RoR,重构后RSpec测试失败_Ruby On Rails 3_Rspec_Railstutorial.org_Renderpartial - Fatal编程技术网

Ruby on rails 3 RoR,重构后RSpec测试失败

Ruby on rails 3 RoR,重构后RSpec测试失败,ruby-on-rails-3,rspec,railstutorial.org,renderpartial,Ruby On Rails 3,Rspec,Railstutorial.org,Renderpartial,我是编程新手,在Hartl的RubyonRails3教程中,我很难找出一个预期的错误。在重构了一些布局页面之后,我在{visit signup_path}上遇到了一个反复出现的错误 以下是我所做的部分重构: _部分字段: <%= render 'shared/error_messages' %> <%= f.label :name %> <%= f.text_field :name %> <%= f.label :email %> <%=

我是编程新手,在Hartl的RubyonRails3教程中,我很难找出一个预期的错误。在重构了一些布局页面之后,我在{visit signup_path}上遇到了一个反复出现的错误

以下是我所做的部分重构:

_部分字段:

<%= render 'shared/error_messages' %>
<%= f.label :name %>
<%= f.text_field :name %>

<%= f.label :email %>
<%= f.text_field :email %>

<%= f.label :password %>
<%= f.password_field :password %>

<%= f.label :password_confirmation, "Confirm Password" %>
<%= f.password_field :password_confirmation %>
以及运行bundle exec rspec spec后的终端输出/

Failures:

  1) User pages edit with valid information 
     Failure/Error: visit signup_path
     ActionView::Template::Error:
       /Users/ajorczak/rails_projects/sample_app/app/views/users/_fields.html.erb:14: syntax error, unexpected keyword_ensure, expecting $end
     # <internal:prelude>:10:in `synchronize'
     # ./app/views/users/new.html.erb:7:in `block in _app_views_users_new_html_erb__3426326572903275614_70133147147220'
     # ./app/views/users/new.html.erb:6:in `_app_views_users_new_html_erb__3426326572903275614_70133147147220'
     # ./spec/requests/user_pages_spec.rb:111:in `block (3 levels) in <top (required)>'

  2) User pages edit with valid information 
     Failure/Error: visit signup_path
     ActionView::Template::Error:
       /Users/ajorczak/rails_projects/sample_app/app/views/users/_fields.html.erb:14: syntax         error, unexpected keyword_ensure, expecting $end
     # <internal:prelude>:10:in `synchronize'
     # ./app/views/users/new.html.erb:7:in `block in _app_views_users_new_html_erb__3426326572903275614_70133147147220'
     # ./app/views/users/new.html.erb:6:in `_app_views_users_new_html_erb__3426326572903275614_70133147147220'
     # ./spec/requests/user_pages_spec.rb:111:in `block (3 levels) in <top (required)>'
故障:
1) 使用有效信息编辑用户页面
失败/错误:访问注册路径
ActionView::模板::错误:
/Users/ajorczak/rails\u projects/sample\u app/app/views/Users/\u fields.html.erb:14:语法错误,意外关键字\u sure,应为$end
#:10:在“同步”中
#./app/views/users/new.html.erb:7:in'block in_app_views_users_new_html_erb_3426326572903275614_70133147220'
#./app/views/users/new.html.erb:6:in`_app_views_users_new_html_erb_3426326572903275614_70133147220'
#./spec/requests/user\u pages\u spec.rb:111:in'block(3级)in'
2) 使用有效信息编辑用户页面
失败/错误:访问注册路径
ActionView::模板::错误:
/Users/ajorczak/rails\u projects/sample\u app/app/views/Users/\u fields.html.erb:14:语法错误,意外关键字\u sure,应为$end
#:10:在“同步”中
#./app/views/users/new.html.erb:7:in'block in_app_views_users_new_html_erb_3426326572903275614_70133147220'
#./app/views/users/new.html.erb:6:in`_app_views_users_new_html_erb_3426326572903275614_70133147220'
#./spec/requests/user\u pages\u spec.rb:111:in'block(3级)in'
我没有列出每个错误,因为我确信(Hartl说这是预期的)测试文档中的错误是相同的。有人能给我一些指导吗


谢谢您的时间。

不确定我做了什么来修复此问题,但其他方面似乎存在一些语法错误。找到了解决办法;文本从“确认”更改为“确认密码”。感谢那些吃了甘地的人。我会解决的

<% provide(:title, "Edit user") %> 
<h1>Update your profile</h1>

<div class="row">
  <div class="span6 offset3">
    <%= form_for(@user) do |f| %>
      <%= render 'fields', f: f %>
      <%= f.submit "Save changes", class: "btn btn-large btn-primary" %>
    <% end %>

    <%= gravatar_for @user %>
    <a href="http://gravatar.com/emails" target="_blank">change</a>
</div>
require 'spec_helper'

describe "User pages" do

  subject { page }

  describe "index" do

    let(:user) { FactoryGirl.create(:user) }

    before do
      sign_in user
      visit users_path
    end

    it { should have_selector('title', text: 'All users') }
    it { should have_selector('h1',    text: 'All users') }

    describe "pagination" do

      before(:all) { 30.times { FactoryGirl.create(:user) } }
      after(:all)  { User.delete_all }

      it { should have_selector('div.pagination') }

      it "should list each user" do
        User.paginate(page: 1).each do |user|
          page.should have_selector('li', text: user.name)
        end
      end
    end

    describe "delete links" do

      it { should_not have_link('delete') }

      describe "as an admin user" do
        let(:admin) { FactoryGirl.create(:admin) }
        before do
          sign_in admin
          visit users_path
        end

        it { should have_link('delete', href: user_path(User.first)) }
        it "should be able to delete another user" do
          expect { click_link('delete') }.to change(User, :count).by(-1)
        end
        it { should_not have_link('delete', href: user_path(admin)) }
      end
    end
  end

  describe "signup page" do
    before { visit signup_path }

    it { should have_selector('h1',    text: 'Sign up') }
    it { should have_selector('title', text: full_title('Sign up')) }
  end

  describe "profile page" do
  let(:user) { FactoryGirl.create(:user) }
  before { visit user_path(user) }

  it { should have_selector('h1',    text: user.name) }
  it { should have_selector('title', text: user.name) }
  end

  describe "signup" do

    before { visit signup_path }

    let(:submit) { "Create my account" }

    describe "with invalid information" do
      it "should not create a user" do
        expect { click_button submit }.not_to change(User, :count)
      end
      describe "after submission" do
        before { click_button submit }

        it { should have_selector('title', text: 'Sign up') }
        it { should have_content('error') }
      end
    end

    describe "with valid information" do
      before do
        fill_in "Name",         with: "Example User"
        fill_in "Email",        with: "user@example.com"
        fill_in "Password",     with: "foobar"
        fill_in "Confirmation", with: "foobar"
      end
      describe "after saving the user" do
        before { click_button submit }
        let(:user) { User.find_by_email('user@example.com') }

        it { should have_selector('title', text: user.name) }
        it { should have_selector('div.alert.alert-success', text: 'Welcome') }
        it { should have_link('Sign out') }
      end

      it "should create a user" do
        expect { click_button submit }.to change(User, :count).by(1)
      end
    end
  end

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

    describe "page" do
      it { should have_selector('h1',    text: "Update your profile") }
      it { should have_selector('title', text: "Edit user") }
      it { should have_link('change', href: 'http://gravatar.com/emails') }
    end

    describe "with invalid information" do
      before { click_button "Save changes" }

      it { should have_content('error') }
    end

    describe "with valid information" do
      let(:new_name)  { "New Name" }
      let(:new_email) { "new@example.com" }
      before do
        fill_in "Name",             with: new_name
        fill_in "Email",            with: new_email
        fill_in "Password",         with: user.password
        fill_in "Confirm Password", with: user.password
        click_button "Save changes"
      end

      it { should have_selector('title', text: new_name) }
      it { should have_selector('div.alert.alert-success') }
      it { should have_link('Sign out', href: signout_path) }
      specify { user.reload.name.should  == new_name }
      specify { user.reload.email.should == new_email }
    end
  end
end
Failures:

  1) User pages edit with valid information 
     Failure/Error: visit signup_path
     ActionView::Template::Error:
       /Users/ajorczak/rails_projects/sample_app/app/views/users/_fields.html.erb:14: syntax error, unexpected keyword_ensure, expecting $end
     # <internal:prelude>:10:in `synchronize'
     # ./app/views/users/new.html.erb:7:in `block in _app_views_users_new_html_erb__3426326572903275614_70133147147220'
     # ./app/views/users/new.html.erb:6:in `_app_views_users_new_html_erb__3426326572903275614_70133147147220'
     # ./spec/requests/user_pages_spec.rb:111:in `block (3 levels) in <top (required)>'

  2) User pages edit with valid information 
     Failure/Error: visit signup_path
     ActionView::Template::Error:
       /Users/ajorczak/rails_projects/sample_app/app/views/users/_fields.html.erb:14: syntax         error, unexpected keyword_ensure, expecting $end
     # <internal:prelude>:10:in `synchronize'
     # ./app/views/users/new.html.erb:7:in `block in _app_views_users_new_html_erb__3426326572903275614_70133147147220'
     # ./app/views/users/new.html.erb:6:in `_app_views_users_new_html_erb__3426326572903275614_70133147147220'
     # ./spec/requests/user_pages_spec.rb:111:in `block (3 levels) in <top (required)>'