Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rspec、shoulda和spork不合作_Ruby On Rails_Rspec_Shoulda_Spork - Fatal编程技术网

Ruby on rails Rspec、shoulda和spork不合作

Ruby on rails Rspec、shoulda和spork不合作,ruby-on-rails,rspec,shoulda,spork,Ruby On Rails,Rspec,Shoulda,Spork,当我运行rspec spec/models时,结果正常 但是当我使用spork时,每个应该使用宏的测试(如it{should validate\u of(:title)}都会失败,错误如下:未定义的方法“validate\u presence\u of…” 我使用: rails (3.0.0) shoulda (2.11.3) spork (0.8.4) rspec-rails (>= 2.0.0.beta.22) spec/spec_helper.rb: require 'rubyge

当我运行
rspec spec/models
时,结果正常

但是当我使用spork时,每个应该使用宏的测试(如
it{should validate\u of(:title)}
都会失败,错误如下:
未定义的方法“validate\u presence\u of…”

我使用:

rails (3.0.0)
shoulda (2.11.3)
spork (0.8.4)
rspec-rails (>= 2.0.0.beta.22)
spec/spec_helper.rb:

require 'rubygems' require 'spork' Spork.prefork do # This file is copied to spec/ when you run 'rails generate rspec:install' ENV["RAILS_ENV"] ||= 'test' require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails' require 'shoulda' ... 需要“rubygems” 需要“spork” 做什么 #运行“rails生成rspec:install”时,此文件将复制到spec/中 环境[“RAILS_ENV”]| |=“测试” 需要文件。展开\u路径(“../../config/environment”,\u文件\u) 需要“rspec/rails” 需要“shoulda” ... 试着移动

require "shoulda"

将行放入
Spork。每次运行
块。显然,shoulda做了一些魔术,将匹配器包含到适当的示例组中。

我也有同样的问题。在prefork块中要求
rspec/rails
后,通过粘贴
require'shoulda/integrations/rspec2'
修复了这个问题


您可能还想将spork升级到最新版本(
gem'spork',>=0.9.0.rc2
),因为我没有在0.8.4上尝试此修复程序(尽管我很确定它也会起作用)

对于当前的shoulda matcher,请尝试
require'shoulda/matchers/integrations/rspec'
您可能会在这个wiki页面上找到一些帮助:对我来说,这很有效:require'shoulda/matchers/integrations/rspec'我将require'shoulda'移到了Sprok.prefork中,这对我很有效。