Rspec 和 Rails:在 lib 目录中测试库时出现问题

发布于 2024-09-19 20:06:02 字数 881 浏览 6 评论 0原文

我在 lib 目录中有一些类,我想测试它。我想测试的类看起来像:

class StatAggregation
  class << self
    def skills_rate(user_id)
      user_id = User.find_by_id(user_id)
      ...
    end
  end
end

我创建了规范:

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')

describe StatAggregation do
  fixtures [
    :users
  ]

  describe 'skills_rate method' do
    it 'should work' do
      @user_id = 1
      @user = mock_model(User)
      User.should_receive(:find_by_id).with(@user_id).and_return(@user)    
      ...
      StatAggregation.skills_rate(@user_id)
    end
  end
end

它工作正常,但它没有显示出现错误的位置:

1)
ArgumentError in 'PxStatAggregation skills_rate method should work'
wrong number of arguments (1 for 0)
script/spec:10:

Finished in 0.326331 seconds

如何获取出现错误“参数数量错误(1 代表 0)”的行数?

I have some classes in the lib directory, and I want to test it. My class which I want to test looks like:

class StatAggregation
  class << self
    def skills_rate(user_id)
      user_id = User.find_by_id(user_id)
      ...
    end
  end
end

I created spec:

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')

describe StatAggregation do
  fixtures [
    :users
  ]

  describe 'skills_rate method' do
    it 'should work' do
      @user_id = 1
      @user = mock_model(User)
      User.should_receive(:find_by_id).with(@user_id).and_return(@user)    
      ...
      StatAggregation.skills_rate(@user_id)
    end
  end
end

It works ok, but it doesn't show where appeared error:

1)
ArgumentError in 'PxStatAggregation skills_rate method should work'
wrong number of arguments (1 for 0)
script/spec:10:

Finished in 0.326331 seconds

How to get number of line where appeared error "wrong number of arguments (1 for 0)"?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一指流沙 2024-09-26 20:06:13

将 -b 或 --backtrace 添加到spec命令行或spec.opts文件中。

Add -b or --backtrace to spec command-line or to your spec.opts file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文