gpt4 book ai didi

ruby-on-rails - 为什么此测试失败 - 未实现错误 Rspec 3.1.x 和 Rails 4.1.9

转载 作者:太空宇宙 更新时间:2023-11-03 18:14:34 25 4
gpt4 key购买 nike

我正在测试以下方法:

  def deal_with_response(site, responses, request_url)
response.each do |response|
if response.code == 200
send_request(site.site_api_url, site.site_api_key, response, request_url)
elsif response.code == 404
send_request(site.site_api_url, site.site_api_key, response, request_url)
GeneralMailer.recieved_404(ENV['ADMINISTRATOR_NAME'], ENV['ADMINISTRATOR_EMAIL'], site, response).deliver_now
elsif response.code == 500
send_request(site.site_api_url, site.site_api_key, response, request_url)
GeneralMailer.recieved_500(ENV['ADMINISTRATOR_NAME'], ENV['ADMINISTRATOR_EMAIL'], site, response).deliver_now
else
send_request(site.site_api_url, site.site_api_key, response, request_url)
GeneralMailer.recieved_error(ENV['ADMINISTRATOR_NAME'], ENV['ADMINISTRATOR_EMAIL'], site, response).deliver_now
end
end
end

这是通过这段代码测试的:

it "should send no email (200)" do
response = double("response", :code => 200)
site = double("site", :site_api_url => 'http://google.ca', site_api_key: 'sdsadsasada')
send_request_method = double()
send_request_method.stub(:send_request).with(site.site_api_url, site.site_api_key, [response], 'http://google.ca').and_return nil

expect{ BlackBird::PublishToSites::User.deal_with_response(response) }.to_not change{ ActionMailer::Base.deliveries.count }.by(1)
end

结果是:

 Failure/Error: expect{ BlackBird::PublishToSites::User.deal_with_response(response) }.to_not change{ ActionMailer::Base.deliveries.count }.by(1)
NotImplementedError:
`expect { }.not_to change { }.by()` is not supported
# ./spec/blackbird/publish_to_sites/user_spec.rb:129:in `(root)'

我错过了什么吗?我在其他测试中正在做类似的代码,它工作正常。我是否做错了 expect block ?

最佳答案

随着错误消息的出现,expect {}.not_to change { }.by() 不受支持。当您将更改匹配器与 not_to 一起使用时,您只能指定 from 值。

尝试以下任一方法:

expect{ BlackBird::PublishToSites::User.deal_with_response(response) }.to_not change{ ActionMailer::Base.deliveries.count }

expect{ BlackBird::PublishToSites::User.deal_with_response(response) }.to_not change{ ActionMailer::Base.deliveries.count }.from(original_delivery_count)

http://www.rubydoc.info/gems/rspec-expectations/RSpec/Matchers#change-instance_method

关于ruby-on-rails - 为什么此测试失败 - 未实现错误 Rspec 3.1.x 和 Rails 4.1.9,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28289159/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com