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
精彩评论