【问题标题】:rspec-rails does not run tests under spec/librspec-rails 不在 spec/lib 下运行测试
【发布时间】:2012-03-05 13:00:18
【问题描述】:

我将lib 文件夹下的模块规范放入spec/lib,但我既没有运行rspec,也没有运行spec spec/,无法获得spec/lib 中的规范进行测试。

是否需要为此进行配置?我使用的是 rails 3.2.0,下面是我的spec_helper.rb

require 'rubygems'
require 'spork'
#uncomment the following line to use spork with the debugger
#require 'spork/ext/ruby-debug'

Spork.prefork do
  # Loading more in this block will cause your tests to run faster. However,
  # if you change any configuration or code from libraries loaded here, you'll
  # need to restart spork for it take effect.
# These lines are needed for SimpleCov to generate a complete coverage report
  require 'simplecov'
  SimpleCov.start 'rails'

  # This file is copied to spec/ when you run 'rails generate rspec:install'
  ENV["RAILS_ENV"] ||= 'test'
  require File.expand_path("../../config/environment", __FILE__)
  require 'rspec/rails'
  require 'rspec/autorun'

  # Requires supporting ruby files with custom matchers and macros, etc,
  # in spec/support/ and its subdirectories.
  Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}

  RSpec.configure do |config|
    config.infer_base_class_for_anonymous_controllers = false
    config.mock_with :rspec # use rspec's built-in mock objects

    require 'database_cleaner'

    config.before(:suite) do
      DatabaseCleaner.strategy = :truncation
      DatabaseCleaner.orm = "mongoid"
    end

    config.before(:each) do
      DatabaseCleaner.clean
    end  
  end

end

Spork.each_run do
  # This code will be run each time you run your specs.

end

【问题讨论】:

    标签: rspec rspec-rails


    【解决方案1】:

    您可以通过在您的 spec/spec_helper.rb 文件中设置 config.pattern 来调整 RSpec 使用的模式

    RSpec.configure do |config|
        config.pattern = "**/*_spec.rb"
    end
    

    这将使 RSpec 运行与给定模式匹配的所有测试。 (并在 spec/lib 中运行测试)

    【讨论】:

      猜你喜欢
      • 2011-08-20
      • 1970-01-01
      • 1970-01-01
      • 2015-05-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-28
      相关资源
      最近更新 更多