【问题标题】:Trouble on testing a model method call in a spec file在规范文件中测试模型方法调用时遇到问题
【发布时间】:2011-09-16 15:44:29
【问题描述】:

我正在使用 Ruby on Rails 3.0.10、RSpec 2 和 FactoryGirl。我正在尝试验证用户帐户数据。

在我的模型中,我有:

class Users::Account < ActiveRecord::Base
  ...

  def get_account_password_salt(password)
    make_user_account_password_salt(password)
  end
end

在我的规范文件中

it "should have a valid password salt" do
  users_account.password_salt.should == Users::Account.get_account_password_salt('123456')
end

当我运行rspec 命令时,我收到以下错误:

Users::Account should have a valid password salt
Failure/Error: users_account.password_salt.should == Users::Account.get_account_password_salt('123456')
NoMethodError:
  undefined method `get_account_password_salt' for #<Class:0x0000010729c9f0>

有什么问题,我该如何解决?

我也尝试过使用::Users::Account.get_account_password_salt('123456')(注意开头的::)但还是不行。

【问题讨论】:

  • @antonversal - 是的,我确定。 “用户”是一个命名空间。

标签: ruby-on-rails ruby ruby-on-rails-3 testing rspec


【解决方案1】:

解决方案

问题是我必须跑

users_account.get_account_password_salt('123456')

代替:

Users::Account.get_account_password_salt('123456')

【讨论】:

    猜你喜欢
    • 2014-06-04
    • 1970-01-01
    • 1970-01-01
    • 2022-06-22
    • 1970-01-01
    • 2011-12-15
    • 1970-01-01
    • 2016-11-02
    • 2019-09-18
    相关资源
    最近更新 更多