2013-08-12 2 views
0

나는 ruby ​​on rails 튜토리얼에서 작업 해왔다. 나는이 물건에 완전히 새로운 것이다. 나는 9 장에서 완전히 붙어있다. 누군가가 오류 메시지를 해독하도록 도와 줄 수 있기를 바랍니다. 지금까지 나는 방금 그들을 검색하고 알아 냈습니다.하지만 문제를 해결하기 위해 오류 메시지를 해독하는 방법을 배우는 것이 더 중요하다고 생각합니다. 만약 너무 길거나 설명하기가 번거 롭다면, 아무도 그것을하고 싶어하지 않는다면 완전히 이해할 것입니다. 나는 이것으로 스스로 도울 수있는 온라인 무언가를 찾을 수 없었다. 여기 ruby ​​on rails 튜토리얼 오류 9 장

내가 현재 무엇입니까 오류를이다 유효한 정보 인증으로 로그인 절차

1) AuthenticationPages 비 로그인 한 사용자가 원하는 보호 페이지

렌더링해야 로그인 후 보호 된 페이지를 방문 할 때 유효 정보 인증으로 로그인 절차
Failure/Error: click_button "Sign in" 
Capybara::ElementNotFound: 
    Unable to find button "Sign in" 
# ./spec/requests/authentication_pages_spec.rb:61:in `block (7 levels) in <top (required)>' 

2) AuthenticationPages 비 로그인 한 편집 페이지

Failure/Error: it { should have_title('Sign in') } 
    expected #has_title?("Sign in") to return true, got false 
# ./spec/requests/authentication_pages_spec.rb:76:in `block (8 levels) in <top (required)>' 
를 방문하는 사용자 컨트롤러의 사용자 유효 정보 인증으로 로그인 절차

3) AuthenticationPages 비 로그인 한 사용자가 잘못된 사용자 방문 사용자 # 편집 페이지와 사용자 컨트롤러에서 비 로그인에 대한 올바른 정보 인증으로 로그인 절차

Failure/Error: before { sign_in user, no_capybara: true } 
NoMethodError: 
    undefined method `sign_in' for #<RSpec::Core::ExampleGroup::Nested_2::Nested_2::Nested_2::Nested_2::Nested_1::Nested_2::Nested_3::Nested_1:0xabbb9e4> 
# ./spec/requests/authentication_pages_spec.rb:87:in `block (8 levels) in <top (required)>' 

4) AuthenticationPages 6.6 초 만에 완성 사용자 # 업데이트 작업을

Failure/Error: before { sign_in user, no_capybara: true } 
NoMethodError: 
    undefined method `sign_in' for #<RSpec::Core::ExampleGroup::Nested_2::Nested_2::Nested_2::Nested_2::Nested_1::Nested_2::Nested_3::Nested_2:0xa82d354> 
# ./spec/requests/authentication_pages_spec.rb:87:in `block (8 levels) in <top (required)>' 

에 PATCH 요청을 제출 잘못된 사용자와 사용자의 컨트롤러의 사용자 65 예, 4 개 실패

실패 예 :

RSpec에 ./spec/requests/authentication_pages_spec.rb:66 # 유효 정보 인증으로 로그인 절차 AuthenticationPages 비 로그인 한 사용자 가에서해야 로그인 한 후 보호 된 페이지를 방문 할 때 시도 원하는 보호 된 페이지를 렌더링

RSpec에 ./spec/requests/authentication_pages_spec.rb:76 번호에 대한 올바른 정보 인증으로 로그인 절차 AuthenticationPages 비 로그인 한 편집 페이지

를 방문하는 사용자 컨트롤러의 사용자 16,

RSpec에 대한 올바른 정보 인증으로 로그인 절차 ./spec/requests/authentication_pages_spec.rb:91 # AuthenticationPages 비 로그인 한 사용자 # 편집 페이지를 사용자에게

RSpec에 방문 잘못된 사용자와 사용자의 컨트롤러 ./ 사양/요청/authentication_pages_spec.rb : 96 # 사용자 # 업데이트 작업을

본격에 PATCH 요청을 제출 잘못된 사용자와 사용자의 컨트롤러 비 로그인 한 사용자에 대한 올바른 정보 인증으로 로그인했습니다 AuthenticationPages ication_pages_spec.rb

require 'spec_helper' 

describe "AuthenticationPages" do 


subject { page } 


describe "signin page" do 
    before { visit signin_path } 

    it { should have_content('Sign in') } 
    it { should have_title('Sign in') } 
end 

describe "signin" do 
    before { visit signin_path } 

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

     it { should have_title('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', text: 'Invalid') } 
     end 
    end 

    describe "with valid information" do 
     let(:user) { FactoryGirl.create(:user) } 

     before do 
      fill_in "Email",  with: user.email.upcase 
      fill_in "Password", with: user.password 
      click_button "Sign in" 
     end 

     it { should have_title(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 

     describe "authorization" do 

      describe "for non-signed-in users" do 
       let(:user) { FactoryGirl.create(:user) } 

       describe "when attempting to visit a protected page" do 
        before do 
         visit edit_user_path(user) 
         fill_in "Email", with: user.email 
         fill_in "Password", with: user.password 
         click_button "Sign in" 
        end 

        describe "after signing in" do 

         it "should render the desired protected page" do 
          expect(page).to have_title('Edit user') 
         end 
        end 
       end 

       describe "in the Users controller" do 

        describe "visiting the edit page" do 
         before { visit edit_user_path(user) } 
         it { should have_title('Sign in') } 
        end 

        describe "submitting to the update action" do 
         before { patch user_path(user) } 
         specify { expect(response).to redirect_to(signin_path) } 
        end 

        describe "as wrong user" do 
         let(:user) { FactoryGirl.create(:user) } 
         let(:wrong_user) { FactoryGirl.create(:user, email: "[email protected]") } 
         before { sign_in user, no_capybara: true } 

         describe "visiting Users#edit page" do 
          before { visit edit_user_path(wrong_user) } 
          it { should_not have_title(full_title('Edit user')) } 
         end 

         describe "submitting a PATCH request to the User#update action" do 
          before { patch user_path(wrong_user) } 
          specify { expect(response).to redirect_to(root_url) } 
         end 
        end 
       end 
      end 
     end 
    end 
    end 
end 

user_pages_spec.rb

 require 'spec_helper' 

describe "User pages" do 

subject { page } 

describe "signup page" do 
before { visit signup_path } 

it { should have_content('Sign up') } 
it { should have_title(full_title('Sign up')) } 
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_title('Sign up') } 
    it { should have_content('error') } 
    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 new user" do 
     expect { click_button submit }.to change(User, :count).by(1) 
    end 

    describe "after saving the user" do 
     before { click_button submit } 
     let(:user) { User.find_by(email: '[email protected]') } 

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

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

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

     describe "page" do 
     it { should have_content("Update your profile") } 
     it { should have_title("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) { "[email protected]" } 
     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_title(new_name) } 
     it { should have_selector('div.alert.alert-success') } 
     it { should have_link('Sign out', href: signout_path) } 
     specify { expect(user.reload.name).to eq new_name } 
     specify { expect(user.reload.email).to eq new_email } 
     end 
    end 
    end 
    end 
    end 
end 

특히 "블록 (7 단계)"의 의미는 무엇인지 궁금합니다. 해당 페이지에서 레벨이 무언가입니까? 아니면 다른 것을 언급하고 있습니까? '블록'이란 무엇입니까?

나는 또한 내가 얻는 카피 바라의 오류를 이해하는 것처럼 보일 수 없다. 8 장에 나타나서 떠났고 지금 돌아 왔습니다. 내가 capybara가 그것을 추측 할 정도로 그것을 끌어 올릴 때 버튼이 페이지에있다. 아무도 그 작동 원리를 설명 할 수 있습니까?

이를 깨 '좋은 웹 사이트? "

를 참조 중첩되어하는

아는 사람을 무엇? 나는 나 자신을 일을하기 위해보다 더 행복 할 것입니다하지만 난 하나를 찾을 수 없습니다. 내가 정말로 사랑 그냥 인터넷 검색을하고 어딘가 대답을 기대하거나 모든 시간을 설명하기 위해 다른 사람에 의존하는 대신 자신이 해독 할 수 있습니다. 귀하의 시간과 어떤 도움

정말 고마워요. 이제

답변

1

내가 오버플로 할 때 스택 오버플로 (overflow) 시간이다. (구글의 '루비 블록'으로 이것에 대해 더 많이 읽는다.) 루비 블록은 인수와 같은 메소드로 전달되는 코드. 예를 들어,

[1,2,3].each{|n| puts n * n } 

each

메소드 (어레이 호출은 [1,2,3])이고, 괄호 안의 모든 블록이다.

|the first element is 1| puts 1 * 1 
|next is 2| puts 2 * 2 
|etc| puts 3 * 3 

블록 : 작동 each 방법이 방법은, 상기 코드 블록에 대한 시간에 열거 호출`의 ([1,2,3])과 산출 한 요소의 각 요소를 가져 do...end 사이에 쓸 수도 있습니다. 루비 방법은 블록을 한 줄에 넣을 수 있다면 괄호를 사용하고, 그렇지 않으면 do...end을 사용하는 것입니다. 도처에 do이 있고 사양에 일치하는 end은 다른 블록 내부에 중첩 된 블록입니다. 이 메소드는 RSpec이 자연어처럼 보이기 때문에주의하기가 더 어렵지만 라인 시작 부분에 describe 또는 it을 작성할 때마다 메소드 호출이 이루어집니다. (그래서 사양에 한 줄 블록으로 호출되는 그 문제에 대해, letbeforesubjectexpect입니다.)

그래서 메시지 '블록 (7 단계)는'당신의 오류가 많은 블록에 중첩 된 의미 :

describe "AuthenticationPages" do #starts the first block 
    ... 
    describe "signup" do #starts the second 

등등.

이제 오류 메시지가 표시됩니다. 첫 번째와 두 번째는 기본적으로 동일한 것을 말하고 있습니다. edit_user_path(user)을 방문하면 페이지 제목에 "로그인"버튼이나 "로그인"이 표시되지 않습니다. log/test.log 파일을 확인하십시오 - 해당 페이지를 방문하면 어떻게됩니까? 로그인 페이지로 리디렉션됩니까? 그것은 있어야하지만 그것이 아닌 것처럼 보입니다.

다른 두 개의 오류 메시지는 정확하게 동일한 것을 말합니다. 사양은 sign_in의 의미를 모릅니다. RSpec은 spec 자체에서 찾을 수 있거나 spec의 맨 위에있는 require 인 spec_helper 파일이나 spec_helper 내부에 require d라는 파일을 찾을 수있는 어딘가에 정의 된 이름으로 메소드를 가질 필요가있다.

마지막으로 Hartl이 맞다고 생각합니다. Google은 오류 메시지와 스택 추적을 할 수 있으며, 찾고있는 것을 찾을 수 없을 때 물어볼 수 있습니다. 그러면 스스로를 더 잘 이해할 수 있습니다. 시각.

+0

자세한 답변을 주셔서 감사합니다. –

1

Re : sign_in - sign_in 함수는 9.1.1, 목록 9.6 (레일즈 4 버전의 책에서)의 spec/support/utilities.rb에 추가되었습니다.

utilities. rb의 내 기능이 밑줄없이 "로그인"했기 때문에 동일한 오류가 발생했습니다. 밑줄을 추가하고 (일치하는 동일한 함수에 다른 참조를 변경 한) 테스트는 녹색으로 바뀌 었습니다.

관련 문제