首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >rspec,2路是一样的?

rspec,2路是一样的?
EN

Stack Overflow用户
提问于 2012-03-14 05:48:57
回答 1查看 73关注 0票数 0
代码语言:javascript
复制
@sponge = Factory(:user)
let(:event_type) { EventType.where( name: 'visit_site').first 

ONE:运行测试时 => false

代码语言:javascript
复制
subject{ Event.new user: @sponge, event_type: event_type, points_earned: event_type.points_value, description: {}}

context 'call #update_user_points when create a event' do
   it{should_receive(:update_user_points)}
end

2:运行测试时的 => true

代码语言:javascript
复制
it 'should call update_user_points after creation' do
   event = Event.new user: @sponge, event_type: event_type, points_earned:event_type.points_value, description: {}
   event.should_receive(:update_user_points)
   event.save
end

请给我一些建议。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-03-14 15:01:12

第二个示例与第一个示例不一样:它们都为Event#update_user_points设置了消息期望,但第二个示例之后调用了save;第一个示例没有。

我认为您不能像在第一个示例中所做的那样,在隐式主题中使用should_receive。rspec似乎没有抱怨,但我不认为它能做你想要的事情。因此,它这样做:

  1. 运行subject块来实例化一个事件。
  2. 设置了一个消息期望,表示主题(新创建的事件)应该接收update_user_points方法。
  3. 然后停止,因为示例中没有其他内容。

它失败了,因为从未收到该消息。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9696597

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档