开发者

Difference between RR mock.instance_of and Mocha any_instance

开发者 https://www.devze.com 2022-12-15 09:08 出处:网络
I have the following rspec code: require \'spec_helper\' require \'mocha\' require \'rr\' describe ProjectsController, \"creating a new project\" do

I have the following rspec code:

require 'spec_helper'
require 'mocha'
require 'rr'

describe ProjectsController, "creating a new project" do
  integrate_views

  it "should redirect to project开发者_如何学C with a notice on successful save" do
    Project.any_instance.stubs(:valid?).returns(true)
    #mock.instance_of(Project).valid? {true}
    Project.any_instance.stubs(:create_default_packets)
    #mock.instance_of(Project).create_default_packets
    post 'create'
    assigns[:project].should_not be_new_record
  end
end

It passes successfully as written (RR syntax commented out) but when I switch to the RR syntax it fails with:

'ProjectsController creating a new project should redirect to project with a notice on successful save' FAILED expected new_record? to return false, got true

What is the difference between the two that RR would fail?


It appears the difference is that you can't call instance_of twice with rr.

EDIT: this may no longer be the case, see https://github.com/rr/rr#class-instances

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号