Кто-нибудь может сказать, почему мой тест не запускается?

Я в самом конце главы 9 в Учебнике по Rails, и эта глава надрала мне задницу. Я просто хочу запустить этот тест (и пройти его), и я могу перейти к главе 10. Буду признателен за любую помощь.

rails_projects/sample_app/spec/requests/authentication_pages_spec.rb:155: syntax error, unexpected $end, expecting keyword_end (SyntaxError)    

это то, что я получаю при попытке запустить тесты, я знаю, что это означает, что мне где-то не хватает конца, но когда я добавляю конец к концу, он запрашивает другой, затем еще один, затем он говорит, что мне не хватает конца в user_pages.spec Затем я добавляю исправление в конец и получаю около 19 ошибок. В любом случае, вот мой код.

authentication_pages_spec.rb:

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



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

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

  it { should have_link('Users',    href: users_path) }
  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

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
        page.should have_selector('title', text: 'Edit user')
      end

      describe "when signing in again" do
        before do
          delete signout_path
          visit signin_path
          fill_in "Email", with: user.email
          fill_in "Password", with: user.password
          click_button "Sign in"
        end

        it "should render the default (profile) page" do
          page.should have_selector('title', text: user.name)
        end
      end
     end
   end

 describe "in the Users controller" do

 describe "visiting the edit page" do
  before { visit edit_user_path(user) }
  it { should have_selector('title', text: 'Sign in') }
end

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

describe "visiting the user index" do
  before { visit users_path }
  it { should have_selector('title', text: 'Sign in') }
  end

 end




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

  describe "visiting Users#edit page" do
    before { visit edit_user_path(wrong_user) }
    it { should_not have_selector('title', text: full_title('Edit user')) }
  end

  describe "submitting a PUT request to the Users#update action" do
    before { put user_path(wrong_user) }
    specify { response.should redirect_to(root_path) }
  end
 end


describe "as non-admin user" do
  let(:user) { FactoryGirl.create(:user) }
  let(:non_admin) { FactoryGirl.create(:user) }

  before { sign_in non_admin }

  describe "submitting a DELETE request to the Users#destroy action" do
    before { delete user_path(user) }
    specify { response.should redirect_to(root_path) }        
    end
    end
  end

  end

вот мой user_pages_spec.rb:

    require 'spec_helper'

describe "User pages" do

subject { page }

describe "index" do

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

 before(:each) 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
 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 "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 "Create my account" }.not_to change(User, :count)
  end

describe "error messages" do
before { click_button "Create my account" }

 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: "[email protected]"
  fill_in "Password", with: "foobar"
  fill_in "Confirmation", with: "foobar"
 end

it "should create a user" do
expect do
  click_button "Create my account"
 end.to change(User, :count).by(1)
end

describe "after saving the user" do
 before { click_button "Create my account" }
 let(:user) { User.find_by_email('[email protected]') }

 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
 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 "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
 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 "edit" do
 let(:user) { FactoryGirl.create(:user) }
 before do
  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) { "[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_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
 end
 end

вот мои ошибки:

   Failures:

 1) User pages delete links as an admin user should be able to delete another user
    Failure/Error: expect { click_link('delete') }.to change(User, :count).by(-1)
    Capybara::ElementNotFound:
      no link with title, id or text 'delete' found
    # (eval):2:in `click_link'
    # ./spec/requests/user_pages_spec.rb:47:in `block (5 levels) in <top (required)>'
    # ./spec/requests/user_pages_spec.rb:47:in `block (4 levels) in <top (required)>'

  2) User pages delete links as an admin user 
     Failure/Error: it { should have_link('delete', href: user_path(User.first)) }
      expected link "delete" to return something
   # ./spec/requests/user_pages_spec.rb:45:in `block (4 levels) in <top (required)>'

 3) signup page 
   Failure/Error: it { should have_selector('h1', text: 'Sign up') }
   expected css "h1" with text "Sign up" to return something
   # ./spec/requests/user_pages_spec.rb:65:in `block (2 levels) in <top (required)>'

 4) signup page 
   Failure/Error: it { should have_selector('title', text: full_title('Sign up')) }
    expected css "title" with text "Ruby on Rails Tutorial Sample App | Sign up" to return  something
  # ./spec/requests/user_pages_spec.rb:66:in `block (2 levels) in <top (required)>'

5) profile page 
   Failure/Error: it { should have_selector('h1', text: user.name) }
     expected css "h1" with text "Person 38" to return something
  # ./spec/requests/user_pages_spec.rb:58:in `block (2 levels) in <top (required)>'

6) profile page 
 Failure/Error: it { should have_selector('title', text: user.name) }
   expected css "title" with text "Person 39" to return something
 # ./spec/requests/user_pages_spec.rb:59:in `block (2 levels) in <top (required)>'

7) signup page 
 Failure/Error: it { should have_selector('h1', text: 'Sign up') }
   expected css "h1" with text "Sign up" to return something
 # ./spec/requests/user_pages_spec.rb:114:in `block (2 levels) in <top (required)>'

8) signup page 
 Failure/Error: it { should have_selector('title', text: full_title('Sign up')) }
   expected css "title" with text "Ruby on Rails Tutorial Sample App | Sign up" to return something
 # ./spec/requests/user_pages_spec.rb:115:in `block (2 levels) in <top (required)>'

9) signup with valid information edit with valid information 
 Failure/Error: it { should have_selector('title', text: new_name) }
   expected css "title" with text "New Name" to return something
 # ./spec/requests/user_pages_spec.rb:171:in `block (5 levels) in <top (required)>'

10) signup with valid information edit with valid information 
 Failure/Error: it { should have_link('Sign out', href: signout_path) }
   expected link "Sign out" to return something
 # ./spec/requests/user_pages_spec.rb:173:in `block (5 levels) in <top (required)>'

11) signup with valid information edit with valid information 
 Failure/Error: it { should have_selector('div.alert.alert-success') }
   expected css "div.alert.alert-success" to return something
 # ./spec/requests/user_pages_spec.rb:172:in `block (5 levels) in <top (required)>'

12) signup with valid information edit with invalid information 
 Failure/Error: it { should have_content('error') }
   expected there to be content "error" in "with invalid information"
 # ./spec/requests/user_pages_spec.rb:157:in `block (5 levels) in <top (required)>'

13) signup with valid information 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:151:in `block (5 levels) in <top (required)>'

14) signup with valid information 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:150:in `block (5 levels) in <top (required)>'

15) signup with valid information 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:149:in `block (5 levels) in <top (required)>'

16) signup with invalid information error messages 
 Failure/Error: it { should have_selector('title', text: 'Sign up') }
   expected css "title" with text "Sign up" to return something
 # ./spec/requests/user_pages_spec.rb:81:in `block (4 levels) in <top (required)>'

17) signup with valid information after saving the user 
 Failure/Error: it { should have_link('Sign out') }
   expected link "Sign out" to return something
 # ./spec/requests/user_pages_spec.rb:106:in `block (4 levels) in <top (required)>'

18) signup with valid information after saving the user 
 Failure/Error: it { should have_selector('div.alert.alert-success', text: 'Welcome') }
   expected css "div.alert.alert-success" with text "Welcome" to return something
 # ./spec/requests/user_pages_spec.rb:105:in `block (4 levels) in <top (required)>'

19) signup with valid information after saving the user 
 Failure/Error: it { should have_selector('title', text: user.name) }
   expected css "title" with text "Example User" to return something
 # ./spec/requests/user_pages_spec.rb:104:in `block (4 levels) in <top (required)>'

Завершено за 2,39 секунды 87 примеров, 19 неудач

Неудачные примеры:

rspec ./spec/requests/user_pages_spec.rb:46 # User pages delete links as an admin user should be able to delete another user
rspec ./spec/requests/user_pages_spec.rb:45 # User pages delete links as an admin user 
rspec ./spec/requests/user_pages_spec.rb:65 # signup page 
rspec ./spec/requests/user_pages_spec.rb:66 # signup page 
rspec ./spec/requests/user_pages_spec.rb:58 # profile page 
rspec ./spec/requests/user_pages_spec.rb:59 # profile page 
rspec ./spec/requests/user_pages_spec.rb:114 # signup page 
rspec ./spec/requests/user_pages_spec.rb:115 # signup page 
rspec ./spec/requests/user_pages_spec.rb:171 # signup with valid information edit with valid information 
rspec ./spec/requests/user_pages_spec.rb:173 # signup with valid information edit with valid information 
rspec ./spec/requests/user_pages_spec.rb:172 # signup with valid information edit with valid information 
rspec ./spec/requests/user_pages_spec.rb:157 # signup with valid information edit with invalid information 
rspec ./spec/requests/user_pages_spec.rb:151 # signup with valid information edit page 
rspec ./spec/requests/user_pages_spec.rb:150 # signup with valid information edit page 
rspec ./spec/requests/user_pages_spec.rb:149 # signup with valid information edit page 
rspec ./spec/requests/user_pages_spec.rb:81 # signup with invalid information error messages 
rspec ./spec/requests/user_pages_spec.rb:106 # signup with valid information after saving the user 
rspec ./spec/requests/user_pages_spec.rb:105 # signup with valid information after saving the user 

rspec ./spec/requests/user_pages_spec.rb:104 # регистрация с действительной информацией после сохранения пользователя


person jfoutch    schedule 15.12.2012    source источник


Ответы (2)


Верно. Вы пропустили 2 end в файле authentication_pages_spec. И есть один дополнительный end в файле user_pages_spec. Поместите (или уберите) эти концы в конец файлов и все. Я предлагаю использовать хороший редактор для кодирования. См. https://stackoverflow.com/questions/91445/best-ide-for-ruby-on-rails.

person atmaish    schedule 15.12.2012
comment
Итак, я сделал это, и тесты снова провалились с 19 ошибками. Не могли бы вы взглянуть на эти ошибки и посмотреть, сможете ли вы указать мне правильное направление? Спасибо также, я использую Sublime, поэтому я думаю, что мой редактор хорош, но мои навыки отладки отстой... Я добавлю свои ошибки выше - person jfoutch; 15.12.2012

Я понял. У меня был дополнительный конец после блока пагинации, поэтому я удалил его и добавил в конец Все тесты, проходящие сейчас. Эти зеленые точки никогда не выглядели так хорошо.

person jfoutch    schedule 15.12.2012
comment
Здорово, что вы решили свою проблему! Пожалуйста, примите ваш ответ для всеобщего ознакомления. - person Paul Fioravanti; 20.12.2012
comment
Спасибо за напоминание, которое я пытался сделать раньше, но это заставляет вас ждать 2 дня. - person jfoutch; 21.12.2012