0

我正在阅读 Michael Hartl 的 Rails 教程,现在在第 5 章。但是,我无法运行我的 Rspec、spark 和 auto 测试。当我尝试让它们运行时,我收到一条错误消息:

Paul-Denlingers-MacBook-Pro:sample_app_2 pdenlinger$ rspec spec/
No DRb server is running. Running in local process instead ...
/Users/pdenlinger/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/rspec-core-2.6.4/lib/rspec/core/configuration.rb:419:in `load': /Users/pdenlinger/rails_projects/sample_app_2/spec/controllers/pages_controller_spec.rb:14: syntax error, unexpected keyword_end, expecting $end (SyntaxError)
    from /Users/pdenlinger/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/rspec-core-2.6.4/lib/rspec/core/configuration.rb:419:in `block in load_spec_files'
    from /Users/pdenlinger/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/rspec-core-2.6.4/lib/rspec/core/configuration.rb:419:in `map'
    from /Users/pdenlinger/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/rspec-core-2.6.4/lib/rspec/core/configuration.rb:419:in `load_spec_files'
    from /Users/pdenlinger/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/rspec-core-2.6.4/lib/rspec/core/command_line.rb:18:in `run'
    from /Users/pdenlinger/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/rspec-core-2.6.4/lib/rspec/core/runner.rb:80:in `run_in_process'
    from /Users/pdenlinger/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/rspec-core-2.6.4/lib/rspec/core/runner.rb:66:in `rescue in run'
    from /Users/pdenlinger/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/rspec-core-2.6.4/lib/rspec/core/runner.rb:62:in `run'
    from /Users/pdenlinger/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/rspec-core-2.6.4/lib/rspec/core/runner.rb:11:in `block in autorun'

这是什么意思,我该如何解决?提前致谢!

pages_controller_spec.rb

require 'spec_helper'

describe "LayoutLinks" do


  it "should have a Home page at '/' do"
    get '/'
    response.should have_selector('title', :content => "Home")
  end

  it "should have a Contact page at '/contact' do"
    get '/contact'
    response.should have_selector('title', :content => "Contact")
  end

  it "should have a About page at '/about' do"
    get '/about'
    response.should have_selector('title', :content => "About")
  end

  it "should have a Help page at '/help' do"
    get '/help'
    response.should have_selector('title', :content => "Help")
  end
end
4

2 回答 2

0

您的所有do关键字都包含在您的示例描述中。改变:

it "should have a Home page at '/' do"

至:

it "should have a Home page at '/'" do

并重复你的每个例子。

于 2012-02-08T03:23:26.953 回答
0

如果您阅读了错误消息,则该文件中似乎缺少end

spec/controllers/pages_controller_spec.rb

在第 14 行。


@pdenlinger 修复他的帖子后更新:

当您不应该将do关键字括在引号中时。它应该看起来像这样:

require 'spec_helper'

describe "LayoutLinks" do
  it "should have a Home page at '/'" do
    get '/'
    response.should have_selector('title', :content => "Home")
  end

  it "should have a Contact page at '/contact'" do
    get '/contact'
    response.should have_selector('title', :content => "Contact")
  end

  it "should have a About page at '/about'" do
    get '/about'
    response.should have_selector('title', :content => "About")
  end

  it "should have a Help page at '/help'" do
    get '/help'
    response.should have_selector('title', :content => "Help")
  end
end
于 2012-02-07T21:18:47.370 回答