简体   繁体   English

MiniTest测试错误的类

[英]MiniTest testing wrong class

I am new to minitest, I have always used RSpec in the past. 我是最小测试的新手,过去我一直使用RSpec。 I have an issue where I put move an object into another table after its been deleted. 我有一个问题,在删除对象后将对象移动到另一个表中。 So I have 2 classes named similar one that is namespace and the other is not. 因此,我有两个名称类似的类,一个是名称空间,另一个不是。 See below for a description in code. 参见下面的代码说明。 Some of the other gems I am using with minitest is minitest-spec-rails and shoulda. 我与minitest一起使用的其他一些宝石是minitest-spec-rails和Shoulda。 Any help is appreciated. 任何帮助表示赞赏。

user.rb user.rb

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

cache/user.rb 缓存/user.rb

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

test/models/cache/user_test.rb 测试/模型/缓存/user_test.rb

require 'test_helper'

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

I found the solution for this. 我找到了解决方案。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM