无法在 Ruby on Rails 应用程序上运行 Rspec、spork 和自动测试

发布于 2025-01-03 14:05:29 字数 2308 浏览 1 评论 0原文

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

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'

这是什么意思,我该如何修复它?提前致谢!

页面控制器规范.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

Am working my way through Michael Hartl's Rails Tutorial and am now in Chapter 5. However, I cannot get my Rspec, spark and auto tests to run. When I try to get them to run, I get an error message:

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'

What does this mean, and how can I fix it? Thanks in advance!

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

独留℉清风醉 2025-01-10 14:05:29

所有 do 关键字都包含在示例描述中。将:更改

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

为:

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

并对每个示例重复。

All of your do keywords are enclosed in your example descriptions. Change:

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

to:

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

and repeat for each of your examples.

辞别 2025-01-10 14:05:29

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

spec/controllers/pages_controller_spec.rb

第 14 行


@pdenlinger 修复其帖子后更新:

您正在附上 < code>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

If you read the error message, it looks like you have a missing end in this file:

spec/controllers/pages_controller_spec.rb

at line 14.


Update after @pdenlinger fixed his post:

You are enclosing the do keyword in quotes when you shouldn't. It should look like this instead:

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文