开发者

Rspec doesn't fail this trivial code, even though it should

开发者 https://www.devze.com 2023-04-04 10:37 出处:网络
Controller: class FooController <开发者_如何学JAVA ApplicationController def create end end Controller spec:

Controller:

class FooController <开发者_如何学JAVA ApplicationController
  def create
  end
end

Controller spec:

describe FooController
  it "does bar" do
    Foo.should_receive(:new).with("text" => "Lorem ipsum")
    post :create, foo: { "text" => "Lorem ipsum" }
  end
end

When I run this, rspec says that it's a success. However, Foo.new is never called in the create method. If I change the Lorem ipsum in the post function call to something else, however, it fails. I would expect this to fail, and succeed if I added Foo.new(params[:foo]) to the body of the create method. Why is this not the case?


Looks like you are missing a "do" on the describe block. Try:

describe FooController do
  it "does bar" do
    Foo.should_receive(:new).with("text" => "Lorem ipsum")
    post :create, foo: { "text" => "Lorem ipsum" }
  end
end
0

精彩评论

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