关于 ruby?? on rails:RSpec should_receive 宏,包含需要测试的 id | 珊瑚贝

RSpec should_receive macro that includes id of what needs to be tested


我怎样才能写出这样它才能通过而不用硬编码1。鸡和蛋。

1
2
3
4
5
6
7
8
9
@sender = Factory(:user)
@receiver = Factory(:user)

mailer = double
mailer.should_receive(:deliver)
Mailer.should_receive(:email).with(1, @sender.id, @receiver.id).and_return(mailer)

# This will create an object with id #1 to make this test pass
@object = Object.create(:sender => @sender, :receiver => @receiver)

  • 我认为 rspec 使用 should-matchers 来验证 \\’should_receive\\’ 上的预期参数,否则任何东西()之类的东西都不起作用?我的想法是编写一个自己的参数匹配器,它与数据库中的第一个 id 匹配。
  • 虽然这仍然是一个抽象的问题,但我在我的具体问题中解决了它。我在 test.rb 中打开了投递,并正在使用 ActionMailer::Base.deliveries 来测试邮件。


这个怎么样?

1
Mailer.should_receive(:email).with(an_instance_of(Fixnum), @sender.id, @receiver.id).and_return(mailer)


来源:https://www.codenong.com/7397177/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_9231.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?