我正在按照http://ruby.railstutorial.org/上的教程处理我的第一个 Rails 应用程序. 我已经完全按照教程中的说明设置了我的开发环境(我正在使用带有 Lion 的 Macbook Pro),并且它可以正常工作,除了一个小问题。我首先编写失败的测试,然后对代码进行更改以使其通过,我可以在浏览器中检查页面是否正常工作,但由于某种原因,测试结果仍然是“红色”。我有一个运行 3 个选项卡的终端,第一个选项卡在其中运行 spork(bundle exec spork),第二个选项卡在其中运行 rails 服务器(rails s),第三个选项卡在其中进行所有命令行更改并运行测试(autotest || 捆绑执行 rspec 规范/)。我必须重新启动 spork、rails 服务器,然后再次测试以查看它们是否变为“绿色”。
这是预期的行为吗?因为根据教程,大多数时候我应该能够看到它们变绿而无需重新启动服务器/spork。
编辑
这就是我的 spec_helper.rb 文件的样子
require 'rubygems'
require 'spork'
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.
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
# Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
RSpec.configure do |config|
# == Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
config.mock_with :rspec
config.fixture_path = "#{::Rails.root}/spec/fixtures"
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, comment the following line or assign false
# instead of true.
config.use_transactional_fixtures = true
end
end
Spork.each_run do
# This code will be run each time you run your specs.
end
感谢您的建议!