Hir*_*sai 2 ruby-on-rails autotest spork ruby-on-rails-3
我正在按照http://ruby.railstutorial.org/上的教程开始我的第一个rails应用程序.我完全按照教程中的说法设置了我的开发环境(我正在使用带有Lion的Macbook Pro),除了一次打嗝之外它没有任何问题.我首先编写失败的测试然后我对代码进行更改以便它们通过,我可以在浏览器中检查页面是否正常工作但由于某种原因,测试结果仍然是"红色".我有一个运行3个选项卡的终端,第一个选项卡,我有spork运行(bundle exec spork),第二个选项卡,我有rails服务器运行(rails s)和第三个选项卡,我进行所有命令行更改并运行测试(自动测试) || bundle exec rspec spec /).我必须重新启动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
Run Code Online (Sandbox Code Playgroud)
谢谢你的建议!
Sam*_*cey 17
在尝试使用spork和watchr设置环境时,我遇到了同样的问题,并且在这里找到了解决方案(至少在我的情况下):http://www.rubyinside.com/how-to-rails- 3 -和- rspec的-2-4336.html
编辑 config/environments/test.rb
更改
config.cache_classes = true
Run Code Online (Sandbox Code Playgroud)
至
config.cache_classes = false
Run Code Online (Sandbox Code Playgroud)
这应该得到spork来获取控制器和模型的更改,而无需重新启动.
编辑:
我已经遇到了cache_classes设置为false的问题(它引起了机械师和黄瓜的问题 - rspec和机械师很奇怪就好了).
无论如何,似乎有一个更好的解决方案(取自这里:http://ablogaboutcode.com/2011/05/18/spork-rspec-sham-and-caching-classes/,在这里:http://mikbe.tk / 2011/02/10 / blazingly-fast-tests /)将以下代码添加到Spork.each_run块
Spork.each_run do
ActiveSupport::Dependencies.clear
ActiveRecord::Base.instantiate_observers
load "#{Rails.root}/config/routes.rb"
Dir["#{Rails.root}/app/**/*.rb"].each { |f| load f }
end if Spork.using_spork?
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2167 次 |
| 最近记录: |