我有一個大的rails測試套件,我只用了一次timecop。爲什麼Timecop.freeze只在運行我的完整規格套件時才起作用?
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之間的交互? (爲了記錄 - 當我運行'bundle execute'之前的所有上述內容時,我會得到相同的結果)。
我包括我的Gemfile和spec.helper以防萬一,這裏澄清任何事情。
的Gemfile:
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