【问题标题】:Why am I getting "Test is not a class" in this Ruby script?为什么我在这个 Ruby 脚本中得到“测试不是一个类”?
【发布时间】:2010-08-10 06:09:22
【问题描述】:

我在这门课上有问题

require "test/unit"
require "selenium/client"

class Test < Test::Unit::TestCase

  def setup
    @verification_errors = []
    @selenium = Selenium::Client::Driver.new \
      :host => "localhost",
      :port => 4444,
      :browser => "*chrome",
      :url => "http://change-this-to-the-site-you-are-testing/",
      :timeout_in_second => 60

    @selenium.start_new_browser_session
  end

  def teardown
    @selenium.close_current_browser_session
    assert_equal [], @verification_errors
  end

  def test_test
    @selenium.open "/apj/gestionnaire/flux.ex"
    @selenium.wait_for_pop_up "_self", "30000"
  end
end

它告诉我它不是一个类:

/test.rb:4: Test is not a class (TypeError)
 from C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
 from C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
 from C:/Documents and Settings/Micro/My Documents/Aptana RadRails Workspace/.metadata/.plugins/org.rubypeople.rdt.testunit/ruby/RemoteTestRunner.rb:301

有人知道吗? 问候 比西耶

【问题讨论】:

    标签: ruby class testunit


    【解决方案1】:

    使用Test 作为你的类名是个坏主意。只要你需要test/unit,它就是一个现有的常量(指一个模块)

    require "test/unit"
    Test.class # => Module
    

    为您的测试用例使用不同的名称。

    【讨论】:

      【解决方案2】:

      使用 Test 作为类名是个坏主意。

      错了!今天发布了一个新版本的 rspec-rails gem,在某些情况下修复了这个问题。

      你可以看看the changelog文件:

      修复在 Rails 4.1 和 4.2 中使用自定义测试类时出现“Test is not a class (TypeError)”错误。 (亚伦·克罗默,#1295)

      【讨论】:

        猜你喜欢
        • 2019-02-05
        • 2020-05-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-03-16
        • 2014-03-21
        • 2010-11-09
        • 2013-05-26
        相关资源
        最近更新 更多