Ruby on rails 使用Spork时,我有rails\u助手和spec\u助手? 更新时间:2014年10月7日上午11:10
原始的 _我不确定如何使用rails\u helper和spec\u helper设置spork。我还在堆栈中使用guard_ 我尝试了不同的组合,但安装起来仍然有困难 铁路司机和图坦卡蒙帮不上忙(这次) 有人知道一个更简单的方法来设置这个吗 我的rails\u helper.rbRuby on rails 使用Spork时,我有rails\u助手和spec\u助手? 更新时间:2014年10月7日上午11:10,ruby-on-rails,gem,rubygems,spork,Ruby On Rails,Gem,Rubygems,Spork,原始的 _我不确定如何使用rails\u helper和spec\u helper设置spork。我还在堆栈中使用guard_ 我尝试了不同的组合,但安装起来仍然有困难 铁路司机和图坦卡蒙帮不上忙(这次) 有人知道一个更简单的方法来设置这个吗 我的rails\u helper.rb ENV["RAILS_ENV"] ||= 'test' require 'spec_helper' require File.expand_path("../../config/environment", __FIL
ENV["RAILS_ENV"] ||= 'test'
require 'spec_helper'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
ActiveRecord::Migration.maintain_test_schema!
RSpec.configure do |config|
config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.use_transactional_fixtures = true
config.infer_spec_type_from_file_location!
end
require 'rubygems'
require 'spork'
Spork.prefork do
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
ActiveRecord::Migration.maintain_test_schema!
RSpec.configure do |config|
config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.use_transactional_fixtures = true
config.infer_spec_type_from_file_location!
end
end
Spork.each_run do
# This code will be run each time you run your specs.
end
my spec_helper.rb
ENV["RAILS_ENV"] ||= 'test'
require 'spec_helper'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
ActiveRecord::Migration.maintain_test_schema!
RSpec.configure do |config|
config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.use_transactional_fixtures = true
config.infer_spec_type_from_file_location!
end
require 'rubygems'
require 'spork'
Spork.prefork do
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
ActiveRecord::Migration.maintain_test_schema!
RSpec.configure do |config|
config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.use_transactional_fixtures = true
config.infer_spec_type_from_file_location!
end
end
Spork.each_run do
# This code will be run each time you run your specs.
end
我又安排好了。而现在,这一负荷永远不会发生。就好像没有加载ThetRails环境一样
想法?我能让守卫和斯波克与rspec3合作。以下是我使用的文件: my_rails_project/.rspec(由
rails生成rspec:install创建):
my_rails_project/spec/rails\u helper.rb(由rails-generate-rspec:install创建):
my_rails_项目/spec/spec\u helper.rb(由rails生成rspec:install创建):
my_rails_project/Guardfile:
来源:RubyonRails教程(Hartl),根据以下文章进行了更改:
1)
(二)
然后在包含规范的文件中,例如my_rails_projects/spec/requests/static_pages\u spec.rb,使用以下要求:
require 'rails_helper'
请注意,rails_helper.rb具有以下行:
require 'rspec_helper.rb'
…因此您可以使用require rails\u helper
获得这两个文件
my_rails_项目/Gemfile:
source 'https://rubygems.org'
ruby '2.0.0'
#ruby-gemset=sample_app2_gems
gem 'rails', '4.0.8'
gem 'pg', '0.15.1'source 'https://rubygems.org'
ruby '2.0.0'
#ruby-gemset=sample_app2_gems
gem 'rails', '4.0.8'
gem 'pg', '0.15.1' #The version in rails tutorial Gemfile, latest is:
#gem 'pg', '0.17.1'
#For Bootstrap css
gem 'bootstrap-sass', '2.3.2.0'
gem 'sprockets', '2.11.0'
gem 'bcrypt-ruby', '3.1.2'
group(:development, :test) do
#gem 'sqlite3', '1.3.8'
#gem 'rspec-rails', '2.13.1'
gem 'rspec-rails', '~>3.0'
gem 'guard-rspec'
gem 'spork-rails'
gem 'guard-spork'
gem 'childprocess', '0.3.6'
gem 'factory_girl_rails', '4.2.0'
end
group :test do
gem 'selenium-webdriver', '2.35.1'
gem 'capybara'
gem 'growl', '1.0.3'
end
gem 'sass-rails', '4.0.3'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.1'
gem 'jquery-rails', '3.0.4'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'
group :doc do
gem 'sdoc', '0.3.20', require: false
end
group :production do
gem 'rails_12factor', '0.0.2'
end
#gem 'pg', '0.17.1'
#For Bootstrap css
gem 'bootstrap-sass', '2.3.2.0'
gem 'sprockets', '2.11.0'
gem 'bcrypt-ruby', '3.1.2'
group(:development, :test) do
#gem 'sqlite3', '1.3.8'
#gem 'rspec-rails', '2.13.1'
gem 'rspec-rails', '~>3.0'
gem 'guard-rspec'
gem 'spork-rails'
gem 'guard-spork'
gem 'childprocess', '0.3.6'
gem 'factory_girl_rails', '4.2.0'
end
group :test do
gem 'selenium-webdriver', '2.35.1'
gem 'capybara'
gem 'growl', '1.0.3'
end
gem 'sass-rails', '4.0.3'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.1'
gem 'jquery-rails', '3.0.4'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'
group :doc do
gem 'sdoc', '0.3.20', require: false
end
group :production do
gem 'rails_12factor', '0.0.2'
end
至于第二个链接中提到的问题,即消除Guardfile中的--drb
会关闭spork:
执行$bundle exec guard
之前:
$ time bundle exec rspec spec/
No DRb server is running. Running in local process instead ...
.........................................
Finished in 1.24 seconds
41 examples, 0 failures
Randomized with seed 20709
real 0m6.186s
user 0m5.082s
sys 0m1.018s
然后在另一个终端窗口中启动防护装置:
$ bundle exec guard
然后再这样做:
$ time bundle exec rspec spec/
.........................................
Finished in 1.66 seconds
41 examples, 0 failures
Randomized with seed 7823
real 0m3.145s
user 0m1.015s
sys 0m0.178s
…您可以看到速度加快了。您能提供一些有关设置的更多信息吗?你犯了什么错误?并请添加任何相关代码/GEM文件。@7stud。谢谢我现在有了更好的理解。然而,我有一些关于绑定器的问题,绑定器找不到gem“spork”的兼容版本:在Gemfile中:spork rails(>=0)ruby依赖于spork(>=1.0rc0)ruby guard spork(>=0)ruby依赖于spork(0.9.2)我是否应该只使用旧的spork?不,我也经历过。在Gemfile中,您必须去掉错误消息中提到的gem之后的任何版本号(并非错误消息中的所有gem都必须在您的Gemfile中,所以只需处理那些存在的gem即可);然后执行$bundle更新
。据我所知,rspec3需要很多gems的更新版本。继续这样做,直到你不再出现这些错误,或者看看我发布的gem文件,看看哪些gem没有版本号。我刚刚读到Rails现在包含了一个叫做Spring的东西,它与Spork的用途相同。安装程序在此解释:谢谢!在玩了一会儿之后,我能让斯波克站起来跑起来!然而,我也发现了春天。设置起来不那么困难,但是是的。它开始运行了!再次感谢你的帮助。
$ time bundle exec rspec spec/
No DRb server is running. Running in local process instead ...
.........................................
Finished in 1.24 seconds
41 examples, 0 failures
Randomized with seed 20709
real 0m6.186s
user 0m5.082s
sys 0m1.018s
$ bundle exec guard
$ time bundle exec rspec spec/
.........................................
Finished in 1.66 seconds
41 examples, 0 failures
Randomized with seed 7823
real 0m3.145s
user 0m1.015s
sys 0m0.178s