【问题标题】:MiniTest testing wrong classMiniTest 测试错误的类
【发布时间】:2015-10-10 04:44:56
【问题描述】:

我是 minitest 的新手,我过去一直使用 RSpec。我有一个问题,我在删除对象后将其移动到另一个表中。所以我有 2 个命名相似的类,一个是命名空间,另一个不是。请参阅下面的代码描述。我与 minitest 一起使用的其他一些 gem 是 minitest-spec-rails 和 shoulda。任何帮助表示赞赏。

用户.rb

class User < ActiveRecord::Base
  self.table_name = 'users'
end

缓存/user.rb

module Cache
  class User < ActiveRecord::Base
    self.table_name = 'cache_users'
  end
end

test/models/cache/user_test.rb

require 'test_helper'

module Cache
  class UserTest < ActiveSupport::TestCase
    #this tests User not Cache::User
  end
end

【问题讨论】:

  • 你试过class Cache::UserTest
  • 是的,我得到了同样的结果。
  • 你说“这测试用户而不是 Cache::User”,但没有说明如何。你为什么这么认为?
  • 这需要测试缓存::用户,但正在测试用户,抱歉造成混乱。

标签: ruby-on-rails ruby minitest shoulda


【解决方案1】:

我找到了解决方案。

class Cache::UserTest < ActiveSupport::TestCase
  @model = Cache::User #this tell what we're testing
end

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多