自动测试无法测试集成测试

发布于 2024-12-27 11:56:34 字数 2048 浏览 1 评论 0原文

我正在学习 Hartl 的 RoR 教程,现在正在进行集成测试部分。按照指示,我修改了 .autotest :

require 'autotest/growl'
require 'autotest/fsevent'
require "autotest/restart" 

Autotest.add_hook :initialize do |autotest|
  autotest.add_mapping(/^spec\/requests\/.*_spec\.rb$/) do
    autotest.files_matching(/^spec\/requests\/.*_spec\.rb$/)
  end  
end

我的设置:

Z-Kidds-MacBook-Air:sample_app zkidd$ ruby -v
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin11.2.0]
Z-Kidds-MacBook-Air:sample_app zkidd$ rails -v
Rails 3.1.3

我读出的错误是这样的:

/Users/zkidd/.rvm/rubies/ruby-1.9.2-p290/bin/ruby -rrubygems -S /Users/zkidd/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/bin/rspec --tty '/Users/zkidd/rails_projects/sample_app/spec/controllers/pages_controller_spec.rb' '/Users/zkidd/rails_projects/sample_app/spec/requests/layout_links_spec.rb'
Exception encountered: #<SyntaxError: /Users/zkidd/rails_projects/sample_app/spec/requests/layout_links_spec.rb:7: syntax error, unexpected ':', expecting ')'
    response.should have_selector('title,' :content => 'Home')
                                            ^
/Users/zkidd/rails_projects/sample_app/spec/requests/layout_links_spec.rb:7: syntax error, unexpected ')', expecting keyword_end>
backtrace: . . . .

我看到错误在 :content 下有一个小胡萝卜,表示自动测试需要“)”而不是冒号。但教程具体说明了我写的内容。这是layout_links_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 an About page at '/about'" do
    get '/contact'
    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 

I am going through Hartl's RoR tutorial and am now in the section for integration testing. As instructed I modified .autotest with:

require 'autotest/growl'
require 'autotest/fsevent'
require "autotest/restart" 

Autotest.add_hook :initialize do |autotest|
  autotest.add_mapping(/^spec\/requests\/.*_spec\.rb$/) do
    autotest.files_matching(/^spec\/requests\/.*_spec\.rb$/)
  end  
end

My set-up:

Z-Kidds-MacBook-Air:sample_app zkidd$ ruby -v
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin11.2.0]
Z-Kidds-MacBook-Air:sample_app zkidd$ rails -v
Rails 3.1.3

My error read out is this:

/Users/zkidd/.rvm/rubies/ruby-1.9.2-p290/bin/ruby -rrubygems -S /Users/zkidd/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.6.4/bin/rspec --tty '/Users/zkidd/rails_projects/sample_app/spec/controllers/pages_controller_spec.rb' '/Users/zkidd/rails_projects/sample_app/spec/requests/layout_links_spec.rb'
Exception encountered: #<SyntaxError: /Users/zkidd/rails_projects/sample_app/spec/requests/layout_links_spec.rb:7: syntax error, unexpected ':', expecting ')'
    response.should have_selector('title,' :content => 'Home')
                                            ^
/Users/zkidd/rails_projects/sample_app/spec/requests/layout_links_spec.rb:7: syntax error, unexpected ')', expecting keyword_end>
backtrace: . . . .

I see that the error has that little carrot under the :content saying that autotest is expecting ")" instead of a colon. But the tutorial specifics exactly what I wrote. Here is the layout_links_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 an About page at '/about'" do
    get '/contact'
    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技术交流群

发布评论

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

评论(1

若相惜即相离 2025-01-03 11:56:34

在您发布的代码中,所有类似的行都

response.should have_selector('title,' :content => 'Home')

应该是

response.should have_selector('title', :content => 'Home')

(逗号在字符串之外)

对于最后一个测试,它也是 'title' 而不是 '/title'

In the code you posted, all the lines like

response.should have_selector('title,' :content => 'Home')

should be

response.should have_selector('title', :content => 'Home')

(the comma is outside the String).

For the last test, it's also 'title' instead of '/title'

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