我有一个大型 Rails 测试套件,我只使用过一次 Timecop。
it "should not include votes from today" do
assert_equal 8, @answer.todays_score
end
it "should include today's votes tomorrow" do
Timecop.travel(Date.today + 1) do
assert_equal 10, @answer.yesterdays_score
end
end
当我运行完整套件时,这些规格通过:
rake
或者
rake spec
但是,如果我尝试运行较小的集合或单个规范,Timecop.freeze 将不起作用。也就是说,以下两个都将失败:
rspec ./spec/models/answers_spec.rb
rake spec:models
有任何想法吗?我是否遗漏了有关 ruby / rspec / rake 和 bundler 之间的交互的信息?(作为记录——当我运行上述所有以“捆绑执行”开头的内容时,我得到了相同的结果)。
我包括我的 Gemfile 和 spec.helper 以防这澄清任何事情。
宝石文件:
gem 'rails', '3.2.8'
gem 'omniauth'
gem 'omniauth-twitter'
gem 'omniauth-facebook'
gem 'haml-rails'
gem 'sass'
gem 'chronic'
gem 'chronic_duration'
gem 'heroku'
gem 'pg', '0.13.1'
gem 'jquery-rails'
gem 'jquery_mobile_rails', "1.1.0"
gem "bcrypt-ruby", :require => "bcrypt"
gem 'rails_autolink'
group :assets do
gem 'sass-rails'
gem 'coffee-rails'
gem 'uglifier'
end
group :development, :test do
gem 'timecop'
gem 'ruby-prof'
gem 'factory_girl_rails'
gem 'rspec-rails'
gem 'capybara'
gem 'mocha'
end
spec_helper.rb:
require 'rubygems'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'capybara/rails'
require 'rspec/autorun'
require 'mocha'
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
RSpec.configure do |config|
config.mock_with :mocha
config.use_transactional_fixtures = true
config.infer_base_class_for_anonymous_controllers = false
config.include(MailerMacros)
config.before(:each) { reset_email }
end