2013-05-12 2 views
0
나는 오류 메시지의 첫 번째 집합을했다하지만 난 아직도, 사용자 편집 장 9.1.1 시험에 붙어있어

에 실패 - 감사합니다 당신에게 사람을 그에 도움을. 새로운 테스트 실패 오류가 발생한 위치와 동일한 위치에서 새로운 오류가 발생했으며 새 질문을 열 것을 권장했습니다. 여기에 업데이트 된 코드를 넣을 것입니다.Rspec 테스트가 실패합니다 Hartl tutorial Chap. 9.1 - 사용자 편집 제목

나는이 테스트를 실행 해요 : $ 번들 간부 RSpec에 사양/요청/user_pages_spec.rb -e "편집 페이지" 오류가 검색의 톤 후, 어디에서 오는 난 그냥 볼 수 없습니다. 내가 카피 바라 2.0.0 업데이트했다 또한

Failures: 

    1) User pages signup edit page 
    Failure/Error: it { should have_selector('title', text: "Edit user") } 
    Capybara::ExpectationNotMet: 
     expected to find css "title" with text "Edit user" but there were no matches. Also found "",   which matched the selector but not all filters. 
    # ./spec/requests/user_pages_spec.rb:60:in `block (5 levels) in <top (required)>' 

Finished in 0.56475 seconds 
3 examples, 1 failure 

가 여기에 사용자 페이지의 사양입니다 :

require 'spec_helper' 

describe "User pages" do 

    subject { page } 

    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 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 "signup" do 

    before { visit signup_path } 

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


    describe "with valid information" do 
     before do 
     fill_in "Name",   with: "Example User" 
     fill_in "Email",  with: "[email protected]" 
     fill_in "Password",  with: "foobar" 
     fill_in "Confirmation", with: "foobar" 
     end 

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

    describe "after saving the user" do 
     before { click_button submit } 
     it { should have_link('Sign out') } 
    end 
     end 
    end 

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

     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 
    end 
end 
end 

여기 내 수정 된 사용자 컨트롤러 : 또한 부착

class UsersController < ApplicationController 

    def show 
    @user = User.find(params[:id]) 
    end 

    def new 
    @user = User.new 
    end 

    def create 
    @user = User.new(params[:user]) 
    if @user.save 
     sign_in @user 
     flash[:success] = "Welcome to the Your App!" 
     redirect_to @user 
    else 
     render 'new'  
     end 
    end 

    def edit 
    @user = User.find(params[:id]) 
    end 
end 

가 edit.html이다가. ERB

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

<div class="row"> 
    <div class="span6 offset3"> 
    <%= form_for(@user) do |f| %> 
    <%= 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, "Confirmation" %> 
     <%= f.password_field :password_confirmation %> 

     <%= f.submit "Save changes", class: "btn btn-large btn-primary" %> 
    <% end %> 

    <% gravatar_for @user %> 
    <a href="http://gravatar.com/emails">change</a> 
    </div> 

여기에 인증 규격입니다 :

require 'spec_helper' 

describe "Authentication" do 

    subject { page } 

    describe "signin page" do 
    before { visit signin_path } 

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

    describe "signin" do 
    before { visit signin_path } 

    describe "with invalid information" do 
     before { click_button "Sign in" } 

    it { should have_selector('title', text: 'Sign in') } 
    it { should have_selector('div.alert.alert-error', text: 'Invalid') } 

    describe "after visiting another page" do 
     before { click_link "Home" } 

    it { should_not have_selector('div.alert.alert-error') } 
    end 
end 


    describe "with valid information" do 
    let(:user) { FactoryGirl.create(:user) } 
     before do 
      fill_in "Email", with: user.email 
      fill_in "Password", with: user.password 
      click_button "Sign in" 
    end 

    it { should have_selector('title', text: user.name) } 
    it { should have_link('Profile', href: user_path(user)) } 
     #it { should have_link('Settings', href: edit_user_path(user)) } 
    it { should have_link('Sign out', href: signout_path) } 
    it { should_not have_link('Sign in', href: signin_path)} 


    describe "followed by signout" do 
    before { click_link "Sign out" } 
    it { should have_link('Sign in') } 
end 
end 
end 
end 

그리고 헤더 html.erb 파일

<header class="navbar navbar-fixed-top navbar-inverse"> 
<div class="navbar-inner"> 
    <div class="container"> 
     <%=link_to "sample app", root_path, id: "logo" %> 
     <nav> 
      <ul class="nav pull-right"> 
       <li><%= link_to "Home", root_path %></li> 
       <li><%= link_to "Help", help_path %></li> 
          <% if signed_in? %> 
          <li><%= link_to "Users", users_path %></li> 
    <li id="fat-menu" class="dropdown">" 
     <a href="#" class="dropdown-toggle" data-toggle="dropdown"> 
     Account <b class="caret"></b> 
     </a> 
     <ul class="dropdown-menu"> 
     <li><%= link_to "Profile", current_user %></li> 
     <li><%= link_to "Settings", edit_user_path(current_user) %></li> 
     <li class="divider"></li> 
     <li> 
      <%= link_to "Sign out", signout_path, method: "delete" %> 
     </li> 
     </ul> 
    </li> 
    <% else %>      

    <li><%= link_to "Sign in", signin_path %></li> 
    <% end %>     
      </ul> 
     </nav> 
    </div> 
</div> 
</header> 
+0

는'content_for 시도 잘못된 원인이 될 수 있습니다 : 제목 { '사용자 편집'을}' –

+0

<% = content_for (: 제목, "사용자 편집") %>이 라인 didn를 오류를 변경하지 마십시오 – PatrickLightning

+0

또한 헤더 태그가 닫히지 않았습니다. 단편 일 수도 있습니다. –

답변

0

당신이 당신의 설명 블록이 잘못 중첩 할 수 있습니다 것 같습니다.

이 편집 페이지가 '가입'에 중첩되는 것을 보여주고있다

'사용자의 페이지 편집 페이지를 제휴 프로그램에 가입', 그것은 사용자의 페이지 아래에 있어야한다.

이 컨텍스트는

require 'spec_helper' 

describe "User pages" do 

    subject { page } 

    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 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 "signup" do 

    before { visit signup_path } 

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


     describe "with valid information" do 
     before do 
      fill_in "Name", with: "Example User" 
      fill_in "Email", with: "[email protected]" 
      fill_in "Password", with: "foobar" 
      fill_in "Confirmation", with: "foobar" 
     end 

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

     describe "after saving the user" do 
      before { click_button submit } 
      it { should have_link('Sign out') } 
     end 
     end 
    end 
    end 


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

    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 
    end 
end 
+0

감사합니다. @muttonlamb 알아 보겠습니다. 레일스 대회에서 중첩에 대해 배우기를 권하는 곳은 어디입니까? – PatrickLightning

+0

레일에 중첩하는 것이 그다지 중요하지 않습니다. 테스트 컨텍스트가 RSpec에서 설정되는 방법입니다. 다양한 수준의 설명 블록은 서로 다른 컨텍스트를 설정합니다. 내가 대답하기 위해 업데이트 한 - 기본적으로 나는 끝, 사용자 페이지에서 둥지 편집 페이지 위해서는 순서 – muttonlamb

+0

를 벗어 나는 설명 절을 들여 쓰기를 변경하거나 이동해야 할, 당신의 할 일을 생각한다 (지난 16 개 라인 정도) 쪽으로? 블록을 다른 순서로 배치해야합니까? hartl의 코드를 github에서 공부하려고합니다. – PatrickLightning

관련 문제