Rspec 和 Rails:在 lib 目录中测试库时出现问题
我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将 -b 或 --backtrace 添加到spec命令行或spec.opts文件中。
Add -b or --backtrace to spec command-line or to your spec.opts file.