【发布时间】:2019-07-17 05:40:24
【问题描述】:
我的attendance_rspec.rb 文件包含:
require "rails_helper"
RSpec.describe Attendance, type: :model do
it { should have_db_column(:date).of_type(:date) }
end
当我使用rspec spec/models/attendance_spec.rb从终端运行它时
显示错误:
Failures:
1) Attendance
Failure/Error: it { should have_db_column(:date).of_type(:date) }
NoMethodError:
undefined method `of_type' for #<RSpec::Matchers::BuiltIn::Has:0x000055e5c65dd3e0>
# ./spec/models/attendance_spec.rb:4:in `block (2 levels) in <main>'
我已经配置了 FactoryBot 以及 database_cleaner 和 capybara gems。我在rails_helper.rb 中缺少什么宝石或缺少任何配置?
我关注 this link 设置 Rspec
【问题讨论】:
-
奇怪,您似乎使用了正确的语法github.com/thoughtbot/shoulda-matchers/blob/master/lib/shoulda/…。你能检查你的 gem 版本吗?
-
gem 'rspec-rails', '~> 3.5' gem 'factory_bot_rails' gem 'database_cleaner' gem 'capybara', '>= 2.15', '< 4.0' -
还有应该匹配的宝石吗?
-
我列出了我为 rspec 安装的所有 gem。我还需要更多吗?
标签: ruby-on-rails rspec rubygems