我在Rails 4上并注意到我的一些RSpec测试失败了,因为我的一些测试重构使用了一个前置过滤器(可能是因为交易).这篇文章描述了类似的问题:
代替使用DatabaseCleaner gem,是否有rake命令来清除测试数据库?我相信rake db:test:prepare在Rails 4中已被弃用.另外,如果之前的交易喜欢
post :create, user: Fabricate.attributes_for(:user)
Run Code Online (Sandbox Code Playgroud)
坚持不懈 是否有另一种重构方法可以避免手动清除测试数据库?
我的rails应用程序最近从Rails 3转移到Rails 4,我一直试图在各个规格(控制器,模型等)上运行rspec,而且它似乎有一个实际定位对象的问题.例如,当我尝试运行以下代码时,它会出现未初始化的常量错误.这似乎发生在多个控制器上.我已经尝试删除rails_helper.rb和spec_helper.rb并运行rails生成rspec:install但它似乎无法解决错误.为什么找不到控制器呢?
我正在尝试执行什么
-> rspec spec/controllers/activity_controller_spec.rb
/Users/osx_user/rails_projects/tealeaf_rails/ltbweb/spec/controllers/activity_controller_spec.rb:4:in `<top (required)>': uninitialized constant ActivitiesController (NameError)
Run Code Online (Sandbox Code Playgroud)
rails_helper.rb
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require 'spec_helper'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
# Add additional requires below this line. Rails is not loaded until this point!
# Requires supporting ruby files with custom matchers and macros, etc, in
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
# run as spec files by default. …Run Code Online (Sandbox Code Playgroud)