Rails 4.2.4,Rspec 3.3.1,shoulda-matcher 3.0.0。
我正在
require 'simplecov_helper'
require 'webmock/rspec'
WebMock.disable_net_connect!(allow_localhost: true)
require 'rspec/collection_matchers'
RSpec.configure do |config|
config.expect_with :rspec do |expectations|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end
config.mock_with :rspec do |mocks|
mocks.verify_partial_doubles = true
end
config.filter_run :focus
config.run_all_when_everything_filtered = true
config.disable_monkey_patching!
config.expose_dsl_globally = true
config.default_formatter = 'doc' if config.files_to_run.one?
config.order = :random
Kernel.srand config.seed
end
还有更多此类失败(看起来像是不合适的)。
rails_helper.rb:
spec/compositions/api
spec_helper.rb:
logging.accessLogConfig: src/main/resources/logback_access_dev.xml
好吧,我认为这个问题不适用于shoulda-matchers,而是使用active_attr gem,因为测试只会在我使用gem的@Configuration
public class TomcatConfiguration {
@Value("${logging.accessLogConfig}")
private String accessLogConfig;
@Bean
public EmbeddedServletContainerCustomizer containerCustomizer() {
return new EmbeddedServletContainerCustomizer() {
@Override
public void customize(ConfigurableEmbeddedServletContainer container) {
if (container instanceof TomcatEmbeddedServletContainerFactory) {
TomcatEmbeddedServletContainerFactory containerFactory =
(TomcatEmbeddedServletContainerFactory) container;
LogbackValve logbackValve = new LogbackValve();
logbackValve.setFilename(accessLogConfig);
containerFactory.addContextValves(logbackValve);
}
}
};
}
文件夹中失败。
答案 0 :(得分:7)
shoulda-matchers 3.0有选择地使其匹配器可用。我使用的ActiveModel匹配器只混合到模型规范中(af98a23)。
我有两个选择来解决这个问题:
spec/models
文件夹下使用active_attr gem; type: :model
添加到spec/compositions/api
文件夹中每个类的顶级描述块。我决定采用第二种选择,但它确实有效。
<强>旁注强>
现在,以确保(ensure_inclusion_in
,ensure_length_of
)开头的匹配器会重命名为validate_inclusion_in
,validate_length_of
(55c8d09)。