2013-06-21 2 views
1

Я изучаю Ruby on Rails из уроков Майкла Хартла.
И теперь я застрял в главе 9.2.1.
Вот код в книге:
Ошибка авторизации Ruby on Rails (Michael Hart Tutorial) (глава 9.2.1)

authentication_pages_spec.erb требуют '' spec_helper

describe "Authentication" do 

    subject { page } 

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

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

    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 
    end 
    describe "authorization" do 

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

     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 { put user_path(user) } 
      specify { response.should redirect_to(signin_path) } 
     end 
     end 
    end 
    end 
end 

Но когда я проверяю:

rspec spec/ 

есть 2 ошибки, которые я надеваю» t не знает, как фиксировать на линии:

it { should have_title('Sign in') } 

и линия:

specify { response.should redirect_to(signin_path) } 

Вот изображение ошибки: http://i.stack.imgur.com/85WaX.png

+1

Каковы эти ошибки? –

+0

К сожалению, извините! Вот изображение. http://i.stack.imgur.com/85WaX.png –

ответ

0

Вы пропустили before { sign_in user } внутри describe "visiting the edit page" do блока.

Но вы использовали, что правильно для других блоков, например:

let(:user) { FactoryGirl.create(:user) } 
before { sign_in user } 
+0

Это не работает. Есть ли другое решение? –

Смежные вопросы