【发布时间】:2015-10-28 23:20:53
【问题描述】:
在 gem 文件中我这样写:
group :test do
gem 'rspec-rails'
gem 'shoulda-matchers', require: false
gem 'factory_girl'
end
我的 rails_helper
require 'rspec/rails'
require 'shoulda/matchers'
我的 spec_helper
require 'rails_helper'
RSpec.configure do |config|
config.expect_with :rspec do |expectations|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end
config.include FactoryGirl::Syntax::Methods
config.mock_with :rspec do |mocks|
mocks.verify_partial_doubles = true
end
Shoulda::Matchers.configure do |config|
config.integrate do |with|
# Choose a test framework:
with.test_framework :rspec
# Choose one or more libraries:
with.library :active_record
with.library :active_model
with.library :action_controller
end
end
最后是我的测试:
require 'spec_helper'
describe Person do
it {should validate_presence_of(:identifier)}
end
我得到 nomethoderror
Failure/Error: it {should validate_presence_of(:identifier)}
NoMethodError:
undefined method `validate_presence_of' for #<RSpec::ExampleGroups::Person:0x007fe58d13ca20>
我只是不明白。在其他项目中以同样的方式工作。这里没有。我花了两天时间来解决这个问题。 Rails 中是否有更好的 Shoulda Matchers 替代品?
【问题讨论】:
-
摆脱
require: false
标签: ruby-on-rails ruby nomethoderror shoulda