2012-06-08 43 views
1

我很努力地尝试通过这个Hartl 9.3测试,但没有运气。RoR Hartl教程第9.3章失败测试

bundle exec rspec spec/requests/user_pages_spec.rb -e "edit page" 

终端返回

sis-macbook-pro:sample_app Lagaspi$ bundle exec rspec spec/requests/user_pages_spec.rb -e "edit page" 
/Users/Lagaspi/.rvm/gems/[email protected]/gems/rspec-core-2.10.1/lib/rspec/core/configuration.rb:746:in `load': /Users/Lagaspi/rails_projects/sample_app/spec/requests/user_pages_spec.rb:111: syntax error, unexpected $end, expecting keyword_end (SyntaxError) 
from /Users/Lagaspi/.rvm/gems/[email protected]/gems/rspec-core-2.10.1/lib/rspec/core/configuration.rb:746:in `block in load_spec_files' 
from /Users/Lagaspi/.rvm/gems/[email protected]/gems/rspec-core-2.10.1/lib/rspec/core/configuration.rb:746:in `map' 
from /Users/Lagaspi/.rvm/gems/[email protected]/gems/rspec-core-2.10.1/lib/rspec/core/configuration.rb:746:in `load_spec_files' 
from /Users/Lagaspi/.rvm/gems/[email protected]/gems/rspec-core-2.10.1/lib/rspec/core/command_line.rb:22:in `run' 
from /Users/Lagaspi/.rvm/gems/[email protected]/gems/rspec-core-2.10.1/lib/rspec/core/runner.rb:69:in `run' 
from /Users/Lagaspi/.rvm/gems/[email protected]/gems/rspec-core-2.10.1/lib/rspec/core/runner.rb:10:in `block in autorun' 

我觉得问题可能出在这个文件中,spec/requests/user_pages_spec.rb

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 "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 
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 { 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

缺少结束... :) –

+0

缩进你的代码正确将使缺少'end's相当明显。 –

回答

1

有结束在你的代码丢失,你应该尝试以正确格式的代码,它可以帮助你把事情做好更快:

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 "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 
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 { 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 
+0

谢谢,但它没有奏效。 –

+1

你是什么意思,它没有工作?什么没有工作?它如何不起作用?我的水晶球今天没有表现出来:)(RubyMine说这个代码是有效的,顺便说一句) - 请看这里的代码 - https://gist.github.com/1664206717def0774de2 –

+0

对不起毛里西奥,测试没有通过。终端返回这个: –

0

,我认为你是在你的文件的末尾缺少end。有一种不匹配的做法,它没有end。尝试把在(一个或两个)end在文件的结尾

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 "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 { 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 
end 
相关问题