【问题标题】:Rails performance tests "rake test:benchmark" and "rake test:profile" give me errorsRails 性能测试“rake test:benchmark”和“rake test:profile”给我错误
【发布时间】:2010-03-30 02:33:27
【问题描述】:

我正在尝试使用 Ruby 1.9 和 Rails 2.3.5 运行空白默认性能测试,但我无法让它工作!我在这里错过了什么???

rails testapp
cd testapp
script/generate scaffold User name:string
rake db:migrate
rake test:benchmark

-

/usr/local/bin/ruby19 -I"lib:test" "/usr/local/lib/ruby19/gems/1.9.1/gems/rake-0.8.7/lib/rake/rake_test_loader.rb" "test/performance/browsing_test.rb" -- --benchmark
Loaded suite /usr/local/lib/ruby19/gems/1.9.1/gems/rake-0.8.7/lib/rake/rake_test_loader
Started
/usr/local/lib/ruby19/gems/1.9.1/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:105:in `rescue in const_missing': uninitialized constant BrowsingTest::STARTED (NameError)
    from /usr/local/lib/ruby19/gems/1.9.1/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:94:in `const_missing'
    from /usr/local/lib/ruby19/gems/1.9.1/gems/activesupport-2.3.5/lib/active_support/testing/performance.rb:38:in `run'
    from /usr/local/lib/ruby19/1.9.1/minitest/unit.rb:415:in `block (2 levels) in run_test_suites'
    from /usr/local/lib/ruby19/1.9.1/minitest/unit.rb:409:in `each'
    from /usr/local/lib/ruby19/1.9.1/minitest/unit.rb:409:in `block in run_test_suites'
    from /usr/local/lib/ruby19/1.9.1/minitest/unit.rb:408:in `each'
    from /usr/local/lib/ruby19/1.9.1/minitest/unit.rb:408:in `run_test_suites'
    from /usr/local/lib/ruby19/1.9.1/minitest/unit.rb:388:in `run'
    from /usr/local/lib/ruby19/1.9.1/minitest/unit.rb:329:in `block in autorun'
rake aborted!
Command failed with status (1): [/usr/local/bin/ruby19 -I"lib:test" "/usr/l...]

【问题讨论】:

    标签: ruby-on-rails ruby performance-testing


    【解决方案1】:

    好的,问题是 ruby​​ 1.8 使用 Test::Unit 作为它的默认测试库。在 ruby​​ 1.9 中更改为 MiniTest。

    3.1.0 之前的 ActiveSupport 版本假定为 Test::Unit。看起来它已在 3.1.0 及更高版本中得到解决。但是,如果您使用的是 rails 3.0.9,它依赖于 activesupport 3.0.9,因此您不能在 Gemfile 中要求更高版本。

    通过 Google 找到 this。显然,Test::Unit 库仍然可用,但作为一个名为“test-unit”的 gem。

    所以在我的 Gemfile 顶部的 rails gem 之前,我放了:

    gem 'test-unit', '~> 2.3.0'
    

    然后我运行了 rake test:benchmark 并且成功了!

    【讨论】:

      【解决方案2】:

      我认为这是一个错误。我可以使用 ruby​​ 1.8.6 (2008-08-11 patchlevel 287) [universal-darwin9.0] 运行代码。在 Ruby 1.9.1 下,我遇到了您所描述的异常。

      当它到达 ActiveSupport::Testing::Performance#run(在 rails 中)时,它会在 yield(self.class::STARTED, name) 行引发异常,并在该行尝试查找常量 ::START。 Ruby Prof 也有类似的方法,在 RubyProf::Test#run 下。

      我不知道是谁的错。

      【讨论】:

        【解决方案3】:

        this。 有关补丁,请参阅here

        【讨论】:

        • 引用的补丁并没有真正解决我的问题。我正在运行 Ruby 1.9.2,但出现此错误。
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-09-17
        • 2011-03-25
        • 1970-01-01
        • 2015-08-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多