Ruby on rails Mongomapper-在rails上使用shoulda进行单元测试2.3.5

Ruby on rails Mongomapper-在rails上使用shoulda进行单元测试2.3.5,ruby-on-rails,tdd,shoulda,mongomapper,Ruby On Rails,Tdd,Shoulda,Mongomapper,我正在尝试使用mongomapper在rails 2.3.5应用程序上实现shoulda单元测试 到目前为止,我已经: 已配置使用mongomapper的rails应用程序(该应用程序正常工作) 将shoulda添加到我的gems中,并使用rake gems:install 将config.frameworks-=[:active_record,:active_resource]添加到config/environment.rb中,因此不使用ActiveRecord 我的模型是这样的: class

我正在尝试使用mongomapper在rails 2.3.5应用程序上实现shoulda单元测试

到目前为止,我已经:

  • 已配置使用mongomapper的rails应用程序(该应用程序正常工作)
  • 将shoulda添加到我的gems中,并使用
    rake gems:install
  • config.frameworks-=[:active_record,:active_resource
    ]添加到
    config/environment.rb
    中,因此不使用
    ActiveRecord
  • 我的模型是这样的:

    class Account
      include MongoMapper::Document
    
      key :name, String, :required => true
      key :description, String
      key :company_id, ObjectId
      key :_type, String
    
      belongs_to :company
      many :operations
    
    end
    
    我对该模型的测试如下:

    class AccountTest < Test::Unit::TestCase
    
      should_belong_to :company
      should_have_many :operations
    
      should_validate_presence_of :name
    
    end
    
    你知道为什么这样不行吗?我应该尝试不同于shoulda的东西吗


    我必须指出,这是我第一次尝试使用shoulda,而且我对测试本身还很陌生。

    在更深入地研究shoulda之后,我意识到了问题所在

    Shoulda的宏(
    应该属于
    应该有很多
    应该验证
    的存在)仅可用于ActiveRecord—在定义了所有宏之后

    如果要使用这些,我必须为Shoulda::MongoMapper::macros实现宏。我不确定这是否值得


    我希望这有助于任何人找到这篇文章。

    我很确定thoughtbot的人迟早会把这些东西移到Shoulda::ActiveModel::Macros。无所谓。我意识到这种测试(应该属于等等)并不是真正需要测试的重要事情。看见
    ./test/unit/account_test.rb:3: undefined method `should_belong_to' for AccountTest:Class (NoMethodError)