在单个lambda请求中断言多个更改期望

Ric*_*stí 13 rspec2

我有这样的测试:

lambda { post("/api/users", parameters) }.should change(User,:count).by(1)
lambda { post("/api/users", parameters) }.should_not change(ActionMailer::Base, :deliveries)
Run Code Online (Sandbox Code Playgroud)

但我想这样做:

lambda { post("/api/users", parameters) }.should change(User,:count).by(1).and_not change(ActionMailer::Base, :deliveries)
Run Code Online (Sandbox Code Playgroud)

是否可以在不需要两个帖子的情况下进行?

谢谢

Ric*_*stí 11

我找到了一个测试它的解决方案.

lambda{
  lambda { post("/api/users", params) }.should change(User,:count).by(1)
}.should change(ActionMailer::Base.deliveries, :count).by(1)
Run Code Online (Sandbox Code Playgroud)