2014-07-22 99 views
0

我检查了所有页面的代码,它们看起来与Hartl的教程完全一样。不过,我得到了这些测试失败的错误,当我跑束的exec rspec的投机/,我很困惑:Michael Hartl的Rails教程第7.2.2章注册 - 测试失败

Pending: 
     StaticPagesHelper add some examples to (or delete) /Users/thaobach/Desktop/sample_app/spec/helpers/static_pages_helper_spec.rb 
     # No reason given 
     # ./spec/helpers/static_pages_helper_spec.rb:14 

    Failures: 

     1) Static pages Contact page it should behave like all static pages 
    Failure/Error: it { should have_title('h1', text:heading) } 
    ArgumentError: 
     wrong number of arguments (2 for 1) 
    Shared Example Group: "all static pages" called from ./spec/requests/static_pages_spec.rb:62 
    # ./spec/requests/static_pages_spec.rb:8:in `block (3 levels) in <top (required)>' 

    2) Static pages About page it should behave like all static pages 
    Failure/Error: it { should have_title('h1', text:heading) } 
    ArgumentError: 
     wrong number of arguments (2 for 1) 
    Shared Example Group: "all static pages" called from ./spec/requests/static_pages_spec.rb:53 
    # ./spec/requests/static_pages_spec.rb:8:in `block (3 levels) in <top (required)>' 

    3) Static pages Home page it should behave like all static pages 
    Failure/Error: it { should have_title('h1', text:heading) } 
    ArgumentError: 
     wrong number of arguments (2 for 1) 
    Shared Example Group: "all static pages" called from ./spec/requests/static_pages_spec.rb:34 
    # ./spec/requests/static_pages_spec.rb:8:in `block (3 levels) in <top (required)>' 

    4) Static pages Help page it should behave like all static pages 
    Failure/Error: it { should have_title('h1', text:heading) } 
    ArgumentError: 
     wrong number of arguments (2 for 1) 
    Shared Example Group: "all static pages" called from ./spec/requests/static_pages_spec.rb:44 
    # ./spec/requests/static_pages_spec.rb:8:in `block (3 levels) in <top (required)>' 

    5) User pages profile page 
    Failure/Error: it { should have_title('title', text: user.name) } 
    ArgumentError: 
     wrong number of arguments (2 for 1) 
    # ./spec/requests/user_pages_spec.rb:12:in `block (3 levels) in <top (required)>' 

    6) User pages profile page 
    Failure/Error: it { should have_title('h1', text: user.name) } 
    ArgumentError: 
     wrong number of arguments (2 for 1) 
    # ./spec/requests/user_pages_spec.rb:11:in `block (3 levels) in <top (required)>' 

    7) User pages signup page 
    Failure/Error: it { should have_title('title', text: 'Sign Up') } 
    ArgumentError: 
     wrong number of arguments (2 for 1) 
    # ./spec/requests/user_pages_spec.rb:19:in `block (3 levels) in <top (required)>' 

    8) User pages signup page 
    Failure/Error: it { should have_title('h1', text: 'Sign Up') } 
    ArgumentError: 
     wrong number of arguments (2 for 1) 
    # ./spec/requests/user_pages_spec.rb:18:in `block (3 levels) in <top (required)>' 

规格/控制器/ static_pages_controller_spec.rb

require 'spec_helper' 

describe StaticPagesController do 

    describe "GET '...'" do 
    it "returns http success" do 
     get '...' 
     response.should be_success 
    end 
    end 
end 

配置/ routes.rb中

SampleApp::Application.routes.draw do 
    resources :users 
    root to: 'static_pages#home' 
    match '/signup', to: 'users#new',   via: 'get' 
    match '/help', to: 'static_pages#help', via: 'get' 
    match '/about', to: 'static_pages#about', via: 'get' 
    match '/contact', to: 'static_pages#contact', via: 'get' 
end 

规格/请求/ 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_title('h1', text: user.name) } 
    it { should have_title('title', text: user.name) } 
    end 

    describe "signup page" do 
    before { visit signup_path } 

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

end 

应用程序/功能/请求/ static_pages_spec.rb

require 'spec_helper' 

describe "Static pages" do 

    subject { page } 

    shared_examples_for "all static pages" do 
    it { should have_title('h1', text:heading) } 
    it { should have_title(full_title(page_title)) } 
    end 

    it "should have the right links on the layout" do 
    visit root_path 
    click_link "About" 
    expect(page).to have_title(full_title('About Us')) 
    click_link "Help" 
    expect(page).to have_title(full_title('Help')) 
    click_link "Contact" 
    expect(page).to have_title(full_title('Contact')) 
    click_link "Home" 
    click_link "Sign up now!" 
    expect(page).to have_title(full_title('Sign up')) 
    click_link "sample app" 
    expect(page).to have_title(full_title('')) 
    end 



    describe "Home page" do 
    before { visit root_path } 
    let (:heading) { 'Sample App'} 
    let(:page_title) { '' } 

    it_should_behave_like "all static pages" 
    it { should_not have_title('| Home') } 
    end 

    describe "Help page" do 
    before { visit help_path } 

    let (:heading) { 'Help'} 
    let(:page_title) { 'Help' } 

    it_should_behave_like "all static pages" 
    end 

    describe "About page" do 
    before { visit about_path } 

    let (:heading) { 'About'} 
    let(:page_title) { 'About' } 

    it_should_behave_like "all static pages" 
    end 

    describe "Contact page" do 
    before { visit contact_path } 

    let (:heading) { 'Contact'} 
    let(:page_title) { 'Contact' } 

    it_should_behave_like "all static pages" 
    end 
end 

应用程序/控制器/ users_controller.rb

class UsersController < ApplicationController 
    def show 
    @user = User.find(params[:id]) 
    end 

    def new 
    @user = User.new 
    end 

    def create 
    @user = User.new(params[:user]) 
    if @user.save 
     #Handle successful save 
    else 
     render 'new' 
    end 
    end 
end 

Gemfile

source 'https://rubygems.org' 
ruby '2.0.0' 
#ruby-gemset=railstutorial_rails_4_0 

gem 'rails', '4.0.8' 
gem 'bootstrap-sass', '2.3.2.0' 
gem 'bcrypt-ruby', '~> 3.1.0' 


gem 'sprockets', '2.11.0' 
gem 'protected_attributes' 
gem 'devise', '3.0.0.rc' 

group :development, :test do 
    gem 'spork-rails', '4.0.0' 
    gem 'guard-spork', '1.5.0' 
    gem 'childprocess', '0.3.6' 
end 

group :development, :test do 
    gem 'sqlite3', '1.3.8' 
    gem 'rspec-rails', '2.13.1' 
    gem 'guard-rspec', '2.5.0' 
end 

group :test do 
    gem 'selenium-webdriver', '2.35.1' 
    gem 'capybara', '2.1.0' 
    gem 'factory_girl_rails', '4.1.0' 

    # Uncomment this line on OS X. 
    # gem 'growl', '1.0.3' 

    # Uncomment these lines on Linux. 
    # gem 'libnotify', '0.8.0' 

    # Uncomment these lines on Windows. 
    # gem 'rb-notifu', '0.0.4' 
    # gem 'wdm', '0.1.0' 

end 

gem 'sass-rails', '4.0.1' 
gem 'uglifier', '2.1.1' 
gem 'coffee-rails', '4.0.1' 
gem 'jquery-rails', '3.0.4' 
gem 'turbolinks', '1.1.1' 
gem 'jbuilder', '1.0.2' 

group :doc do 
    gem 'sdoc', '0.3.20', require: false 
end 

group :production do 
    gem 'pg', '0.15.1' 
    gem 'rails_12factor', '0.0.2' 
end 
+0

所有的错误几乎都是自我解释,它会为你打破。 –

回答

0

所有的错误几乎都是自我解释,它会为你打破它。

  1. 我不知道你想用什么来描述get '...',请再次参考本教程。

  2. 由于错误说“行动‘创造’不能为UsersController找到”添加行resources :users, only: [:create]在路由文件

  3. 同样的错误,第二个

4,5 ,6.在查看你的UsersController文件后,我可以更多地了解这一点。

+0

你好,我已经添加了我的'users_controller.rb'文件 –

+0

我也更新了错误列表。我意识到我的一些错误与使用Cabybara 2.1.0有关,因此我将'should have_selector'修复为'should have_title'。现在,有一个新的错误列表。 –

相关问题