【问题标题】:Unit tests fail after migrating from rails 2.0.1 to 2.3.17从 rails 2.0.1 迁移到 2.3.17 后单元测试失败
【发布时间】:2013-03-08 11:22:33
【问题描述】:

从 Rails 2.0.1 迁移到 2.3.17 后,单元测试不起作用。对于他们每个人,我都会遇到相同的错误:

"NoMethodError: 未定义的方法 `assert_valid_keys' for 假:假类”。

有什么线索吗?

  • RUBY 版本:1.8.7(2011-02-18 补丁级别 334)[i686-darwin10.8.0]
  • RUBYGEMS 版本:1.8.25

NoMethodError: undefined methodassert_valid_keys' for false:FalseClass (评估):12:在run' /Applications/RubyMine.app/rb/testing/patch/testunit/test/unit/ui/teamcity/testrunner.rb:93:insend' /Applications/RubyMine.app/rb/testing/patch/testunit/test/unit/ui/teamcity/testrunner.rb:93:in start_mediator' /Applications/RubyMine.app/rb/testing/patch/testunit/test/unit/ui/teamcity/testrunner.rb:81:instart'`

【问题讨论】:

  • 你能发布一个你的测试是什么样子的例子吗?
  • 我创建了新的 rails 2.3 应用程序,并从中获取了默认的 test_helper.rb 并创建了 test "the truth" do assert true end。如果我在我的应用程序中运行该测试,我仍然会收到同样的错误。
  • 好的,好像该方法是在 rails 3.0 中引入的,所以我认为您需要确保您确实使用的是 2.3
  • 您是否使用了此处所述的无效语法? stackoverflow.com/questions/9507770/…
  • 在 rails-23app enviroment.rb 中设置为RAILS_GEM_VERSION = '2.3.17' unless defined? RAILS_GEM_VERSION

标签: ruby-on-rails unit-testing migration ruby-1.8.7


【解决方案1】:

好的,我想我已经找到了解决方案。

在我正在开发的这个应用程序中使用了插件 fixture_scenarios,所以我更新了 lib/fixture_scenarios.rb 第 33 行:

connection.transaction(Thread.current['open_transactions'] == 0) do

到

connection.transaction(:requires_new => Thread.current['open_transactions'] == 0) do

现在大部分测试都通过了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-02-05
    • 2020-09-07
    • 2016-06-28
    • 2017-05-26
    • 2021-05-02
    • 1970-01-01
    • 2016-04-25
    • 1970-01-01
    相关资源
    最近更新 更多