Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/68.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 有人能告诉我为什么我的考试赢了吗;我跑不了?_Ruby On Rails_Ruby On Rails 3_Railstutorial.org - Fatal编程技术网

Ruby on rails 有人能告诉我为什么我的考试赢了吗;我跑不了?

Ruby on rails 有人能告诉我为什么我的考试赢了吗;我跑不了?,ruby-on-rails,ruby-on-rails-3,railstutorial.org,Ruby On Rails,Ruby On Rails 3,Railstutorial.org,我已经到了Rails教程第9章的末尾,这一章一直在踢我的屁股。我只是想让这些测试运行(并通过),然后我可以继续到第10章。任何帮助都将不胜感激 rails_projects/sample_app/spec/requests/authentication_pages_spec.rb:155: syntax error, unexpected $end, expecting keyword_end (SyntaxError) 这是我在尝试运行测试时得到的结果,我知道这意味着我在某个地方缺少

我已经到了Rails教程第9章的末尾,这一章一直在踢我的屁股。我只是想让这些测试运行(并通过),然后我可以继续到第10章。任何帮助都将不胜感激

rails_projects/sample_app/spec/requests/authentication_pages_spec.rb:155: syntax error, unexpected $end, expecting keyword_end (SyntaxError)    
这是我在尝试运行测试时得到的结果,我知道这意味着我在某个地方缺少了一个端点,但当我在端点上添加一个端点时,它会要求另一个端点,然后在user_pages.spec中显示我缺少一个端点,然后我在那里添加修复端点,并得到大约19个错误。无论如何,这是我的密码

身份验证\u页面\u 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: "wrong@example.com") }
  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
    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: "user@example.com"
  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('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
 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: "user@example.com"
   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) { "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
 end
 end
以下是我的用户\u页面\u 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: "wrong@example.com") }
  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
    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: "user@example.com"
  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('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
 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: "user@example.com"
   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) { "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
 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)>'

rspec./spec/requests/user_pages_spec.rb:104#保存用户后使用有效信息注册

正确。您在身份验证页面规范中遗漏了2个
end
,在用户页面规范中还有一个额外的
end
。请将这些端点放入(或删除)文件的末尾,这样就可以了。我建议使用一些好的编辑器进行编码。参考。

我想出来了。我在分页块之后有一个额外的端点,所以我删除了它,并将所有通过的测试添加到端点。那些绿点看起来从来没有这么好过。

好吧,我就这样做了,测试再次失败,出现了19个错误。你介意看看这些错误,看看能不能给我指出正确的方向?谢谢,我也在使用Sublime,所以我认为我的编辑器很好,但我的调试技能很差。。。我会在上面加上我的错误那太好了你解决了你自己的问题!请接受你的答案,供大家参考。感谢我之前的提醒,但这让你等了2天。