【发布时间】:2015-07-09 10:07:24
【问题描述】:
我的测试:
RSpec.describe Populators::Fipe::Brand, type: :service do
before(:all) do
::Populators::Fipe::Brand.new.perform
end
it "update records and do not create new ones" do
expect{
::Populators::Fipe::Brand.new.perform
}.to_not change{
::Brand.maximum(:id)
}
end
end
当我跑步时:
rspec 规范
结果:
失败/错误:::Populators::Fipe::Brand.new.perform 无方法错误: '
中未定义的方法perform' for #<Brand:0x007fdcb6fb2788>
# ./spec/services/populators/fipe/brand_spec.rb:5:inblock(2 级)
当我跑步时:
rspec spec/services/populators/fipe/brand_spec.rb
结果:
Populators::Fipe::Brand 更新记录,不创建新记录 创建表 填写姓名 填充combo_code
在 1.04 秒内完成(文件加载需要 6.33 秒) 4 个示例,0 次失败
已编辑:
我有两个班级:
models/brand.rb
services/populators/fipe/brand.rb
代码试图做什么:
当 Populators::Fipe::Brand(服务)执行其操作时, 它使用来自网络服务的数据填充品牌(模型)。 但如果品牌(模型)已经存在,它只会更新。
rspec 在做什么:
但似乎 rspec 试图在“models/brand.rb”中调用方法“perform” 而不是正确的“services/populators/fipe/brand.rb”。 不知道为什么..
【问题讨论】:
标签: ruby-on-rails ruby rspec