rails / rspec没有看到匹配器

时间:2015-10-22 12:11:11

标签: ruby-on-rails rspec rspec-rails ruby-on-rails-4.2 shoulda

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); } } }; } 文件夹中失败。

1 个答案:

答案 0 :(得分:7)

shoulda-matchers 3.0有选择地使其匹配器可用。我使用的ActiveModel匹配器只混合到模型规范中(af98a23)。

我有两个选择来解决这个问题:

  • 放置模型的规格,在spec/models文件夹下使用active_attr gem;
  • type: :model添加到spec/compositions/api文件夹中每个类的顶级描述块。

我决定采用第二种选择,但它确实有效。

<强>旁注

现在,以确保(ensure_inclusion_inensure_length_of)开头的匹配器会重命名为validate_inclusion_invalidate_length_of55c8d09)。