ruby-on-rails - 当方法不存在时,如何使用 rspec 导致测试失败?
问题描述
我有一个 Rails 5 应用程序。我创建了这个工人阶级
类 PrinterWorker 包括 Sidekiq::Worker
def perform
...
service = PrinterService.new(args)
service.printtt
...
end
我正在使用 rspec 对我的工人进行单元测试。我有这些规格...
RSpec.describe PrinterWorker, :type => :worker do
context "#perform" do
let(:printer_service) { instance_double("PrinterService") }
...
context "calls perform successfully" do
before do
...
allow(PrinterService).to receive(:new).and_return(printer_service)
allow(printer_service).to receive(:printtt)
...
subject.perform
end
it "makes proper service calls" do
...
expect(printer_service).to have_received(:printtt).once
end
我发现的问题是,如果服务“PrinterService”没有“printtt”方法,那么这个规范就可以通过了。这对我来说似乎是错误的。如果我试图调用一个不存在的方法,我觉得规范应该失败。但是,我不确定如何以不同的方式配置我的测试来实现这一点。
解决方案
推荐阅读
- lua - lua 获取文件扩展名第一次出现
- php - html按钮显示php脚本结果
- python - 块大小与 Python 中的多处理/pool.map 无关?
- python - Discord.py 上的作者
- asp.net - ASP.NET Core 2.1 API 不带参数
- amazon-s3 - 从 Amazon S3 Windows 命令行实用程序下载文件
- javascript - 为什么使用解构导入 react-bootstrap 并不理想
- amazon-web-services - 自定义 Terraform 输入
- javascript - 在对象存在之前创建方法链
- tomcat - 如果配置不完整,防止 (tomcat) Web 应用程序启动