应用程序:Sinatra + ActiveRecord
尝试使用最佳实践来测试关联的存在。
我真的很喜欢 Shoulda 语法:
describe Bar do
it { should belong_to(:foo) }
end
但是,RSpec 似乎找不到 belong_to
方法。
1) ResOutcome
Failure/Error: it { should belong_to(:foo) }
NoMethodError:
undefined method `belong_to' for #<RSpec::Core::ExampleGroup::Nested_1:0x00000103ac6760>
# ./spec/models/bar_spec.rb:48:in `block (2 levels) in <top (required)>'
有什么提示吗?
关联测试是否应该只在 Rails 应用程序中工作(使用 rspec-rails)?
感谢大家抽出宝贵的时间。
最佳答案
您是否将 shoulda-matchers
gem 添加到您的 Gemfile 中?
https://github.com/thoughtbot/shoulda-matchers
更新:
将 require 'shoulda/matchers
添加到您的 spec_helper.rb
配置中。
关于activerecord - 在非 Rails 应用程序中测试 ActiveRecord 与 Shoulda 的关联,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11035311/