Ruby on rails 轨道2和x2B;不应该

Ruby on rails 轨道2和x2B;不应该,ruby-on-rails,shoulda,Ruby On Rails,Shoulda,我在rails 2应用程序中使用thoughtbot shoulda gem。 模型如下所示 class Zone < ActiveRecord::Base belongs_to :organization has_many :volunteer_shifts validates_presence_of :organization_id validates_presence_of :name end $cat spec/models/zone_spec.rb req

我在rails 2应用程序中使用thoughtbot shoulda gem。 模型如下所示

class Zone < ActiveRecord::Base
  belongs_to :organization
  has_many :volunteer_shifts

  validates_presence_of :organization_id
  validates_presence_of :name
end

$cat spec/models/zone_spec.rb 

require 'spec_helper'
describe Zone do
  context "should" do
    it { should have_db_column(:organization_id) }#, :decimal}
    it { should have_db_column(:name) }
    it { should have_db_column(:description) }

    it { should belong_to(:organization) }
    it { should have_many(:volunteer_shifts) }

    it { should validate_presence_of(:organization_id) }
    it { should validate_presence_of(:name) }
  end
end
所有验证匹配器都失败。参考网站是

Gemfile.lock

GEM
 remote: http://rubygems.org/
 specs:
Ascii85 (1.0.2)
actionmailer (2.3.16)
  actionpack (= 2.3.16)
actionpack (2.3.16)
  activesupport (= 2.3.16)
  rack (~> 1.1.0)
active_utils (1.0.3)
  activesupport (>= 2.3.11)
  i18n
activerecord (2.3.16)
  activesupport (= 2.3.16)
activeresource (2.3.16)
  activesupport (= 2.3.16)
activesupport (2.3.16)
acts_as_xlsx (1.0.5)
  activerecord (>= 2.3.9)
  axlsx (>= 1.0.13)
  i18n (>= 0.4.1)
addressable (2.3.3)
airbrake (3.1.8)
  activesupport
  builder
  json
authorize-net (1.5.2)
  nokogiri (~> 1.4)
axlsx (1.3.5)
  htmlentities (~> 4.3.1)
  nokogiri (>= 1.4.1)
  rubyzip (>= 0.9.5)
barby (0.5.1)
builder (3.2.0)
calendar_date_select (1.16.1)
capistrano (2.9.0)
  highline
  net-scp (>= 1.0.0)
  net-sftp (>= 2.0.0)
  net-ssh (>= 2.0.14)
  net-ssh-gateway (>= 1.1.0)
capistrano-ext (1.2.1)
  capistrano (>= 1.0.0)
capybara (1.1.4)
  mime-types (>= 1.16)
  nokogiri (>= 1.3.3)
  rack (>= 1.0.0)
  rack-test (>= 0.5.4)
  selenium-webdriver (~> 2.0)
  xpath (~> 0.1.4)
capybara-webkit (0.12.1)
  capybara (>= 1.0.0, < 1.2)
  json
childprocess (0.3.9)
  ffi (~> 1.0, >= 1.0.11)
cocaine (0.4.2)
commonjs (0.2.6)
crack (0.1.8)
cucumber (1.1.0)
  builder (>= 2.1.2)
  diff-lcs (>= 1.1.2)
  gherkin (~> 2.5.0)
  json (>= 1.4.6)
  term-ansicolor (>= 1.0.6)
cucumber-rails (0.3.2)
  cucumber (>= 0.8.0)
daemon-spawn (0.3.0)
daemons (1.0.10)
delayed_job (2.0.7)
  activesupport (~> 2.0)
  daemons (= 1.0.10)
diff-lcs (1.2.1)
factory_girl (2.6.4)
  activesupport (>= 2.3.9)
faker (1.1.2)
  i18n (~> 0.5)
fakeweb (1.3.0)
fastercsv (1.5.3)
ffi (1.4.0)
gherkin (2.5.4)
  json (>= 1.4.6)
graticule (0.2.12)
  activesupport
highline (1.6.16)
hodel_3000_compliant_logger (0.1.1)
htmlentities (4.3.1)
httparty (0.6.1)
  crack (= 0.1.8)
i18n (0.5.0)
json (1.7.7)
launchy (2.2.0)
  addressable (~> 2.3)
less (2.1.0)
  commonjs (~> 0.2.0)
  therubyracer (~> 0.10.0)
libv8 (3.3.10.4)
lockfile (1.4.3)
macaddr (1.6.1)
  systemu (~> 2.5.0)
mail (2.4.1)
  i18n (>= 0.4.0)
  mime-types (~> 1.16)
  treetop (~> 1.4.8)
mechanize (1.0.0)
  nokogiri (>= 1.2.1)
mime-types (1.21)
multi_json (1.7.0)
multipart-post (1.1.0)
mysql (2.8.1)
net-scp (1.1.0)
  net-ssh (>= 2.6.5)
net-sftp (2.1.1)
  net-ssh (>= 2.6.5)
net-ssh (2.6.6)
net-ssh-gateway (1.2.0)
  net-ssh (>= 2.6.5)
newrelic_rpm (3.5.8.72)
nokogiri (1.4.7)
oink (0.1.2)
  hodel_3000_compliant_logger
paperclip (2.8.0)
  activerecord (>= 2.3.0)
  activesupport (>= 2.3.2)
  cocaine (>= 0.0.2)
  mime-types
pdf-reader (0.8.5)
  Ascii85 (>= 0.9)
pipejump (0.4.4)
polyglot (0.3.3)
postageapp (1.0.14)
  json
rack-test (0.6.2)
  rack (>= 1.0)
rails (2.3.16)
  actionmailer (= 2.3.16)
  actionpack (= 2.3.16)
  activerecord (= 2.3.16)
  activeresource (= 2.3.16)
  activesupport (= 2.3.16)
  rake (>= 0.8.3)
rake (0.8.7)
rcov (1.0.0)
rdoc (2.4.3)
rmagick (2.12.2)
rspec (1.3.2)
rspec-rails (1.2.9)
  rack (>= 1.0.0)
  rspec (>= 1.2.9)
rubyzip (0.9.7)
sanitize (2.0.0)
  nokogiri (~> 1.4.4)
selenium-webdriver (2.31.0)
  childprocess (>= 0.2.5)
  multi_json (~> 1.0)
  rubyzip
  websocket (~> 1.0.4)
steak (1.1.0)
  rspec (>= 1.3)
system_timer (1.0)
systemu (2.5.2)
term-ansicolor (1.1.1)
therubyracer (0.10.2)
  libv8 (~> 3.3.10)
thoughtbot-shoulda (2.11.1)
timecop (0.6.1)
treetop (1.4.10)
  polyglot
  polyglot (>= 0.3.1)
uuid (2.3.6)
  macaddr (~> 1.0)
vpim (0.695)
webrat (0.5.3)
  nokogiri (>= 1.2.0)
  rack (>= 1.0)
websocket (1.0.7)
wicked_pdf (0.7.9)
xpath (0.1.4)
  nokogiri (~> 1.3)
GEM
远程:http://rubygems.org/
规格:
Ascii85(1.0.2)
actionmailer(2.3.16)
actionpack(=2.3.16)
actionpack(2.3.16)
主动支持(=2.3.16)
机架(~>1.1.0)
有效效用(1.0.3)
activesupport(>=2.3.11)
i18n
activerecord(2.3.16)
主动支持(=2.3.16)
activeresource(2.3.16)
主动支持(=2.3.16)
activesupport(2.3.16)
充当xlsx(1.0.5)
activerecord(>=2.3.9)
axlsx(>=1.0.13)
i18n(>=0.4.1)
可寻址(2.3.3)
空气制动(3.1.8)
主动支持
建设者
json
授权净额(1.5.2)
nokogiri(~>1.4)
axlsx(1.3.5)
htmlentities(~>4.3.1)
nokogiri(>=1.4.1)
rubyzip(>=0.9.5)
芭比(0.5.1)
建筑商(3.2.0)
日历\日期\选择(1.16.1)
卡皮斯特拉诺(2.9.0)
高架线
净scp(>=1.0.0)
净sftp(>=2.0.0)
net ssh(>=2.0.14)
net ssh网关(>=1.1.0)
卡皮斯特拉诺分机(1.2.1)
capistrano(>=1.0.0)
水豚(1.1.4)
mime类型(>=1.16)
nokogiri(>=1.3.3)
机架(>=1.0.0)
机架测试(>=0.5.4)
selenium webdriver(~>2.0)
xpath(~>0.1.4)
水豚网络工具包(0.12.1)
水豚(>=1.0.0,<1.2)
json
子进程(0.3.9)
外国金融机构(~>1.0,>=1.0.11)
可卡因(0.4.2)
commonjs(0.2.6)
裂纹(0.1.8)
黄瓜(1.1.0)
建造商(>=2.1.2)
差异lcs(>=1.1.2)
小黄瓜(~>2.5.0)
json(>=1.4.6)
术语ansicolor(>=1.0.6)
黄瓜轨(0.3.2)
黄瓜(>=0.8.0)
守护进程繁殖(0.3.0)
守护进程(1.0.10)
延迟工作(2.0.7)
activesupport(~>2.0)
守护进程(=1.0.10)
差异lcs(1.2.1)
工厂女孩(2.6.4)
activesupport(>=2.3.9)
伪造者(1.1.2)
i18n(~>0.5)
fakeweb(1.3.0)
fastercsv(1.5.3)
外国金融机构(1.4.0)
小黄瓜(2.5.4)
json(>=1.4.6)
分划(0.2.12)
主动支持
高端(1.6.16)
hodel_3000_兼容_记录器(0.1.1)
htmlentities(4.3.1)
httparty(0.6.1)
裂纹(=0.1.8)
i18n(0.5.0)
json(1.7.7)
launchy(2.2.0)
可寻址(~>2.3)
减(2.1.0)
commonjs(~>0.2.0)
therubyracer(~>0.10.0)
libv8(3.3.10.4)
锁文件(1.4.3)
macaddr(1.6.1)
systemu(~>2.5.0)
邮件(2.4.1)
i18n(>=0.4.0)
mime类型(~>1.16)
树梢(~>1.4.8)
机械化(1.0.0)
nokogiri(>=1.2.1)
mime类型(1.21)
多线程json(1.7.0)
多部分post(1.1.0)
mysql(2.8.1)
净scp(1.1.0)
net ssh(>=2.6.5)
净sftp(2.1.1)
net ssh(>=2.6.5)
net ssh(2.6.6)
net ssh网关(1.2.0)
net ssh(>=2.6.5)
newrelic_rpm(3.5.8.72)
nokogiri(1.4.7)
oink(0.1.2)
hodel_3000_兼容_记录器
回形针(2.8.0)
activerecord(>=2.3.0)
activesupport(>=2.3.2)
可卡因(>=0.0.2)
mime类型
pdf阅读器(0.8.5)
Ascii85(>=0.9)
管道跳跃(0.4.4)
polyglot(0.3.3)
邮政总局(1.0.14)
json
机架测试(0.6.2)
机架(>=1.0)
轨道(2.3.16)
actionmailer(=2.3.16)
actionpack(=2.3.16)
活动记录(=2.3.16)
活动资源(=2.3.16)
主动支持(=2.3.16)
耙(大于等于0.8.3)
耙(0.8.7)
rcov(1.0.0)
rdoc(2.4.3)
rmagick(2.12.2)
rspec(1.3.2)
rspec钢轨(1.2.9)
机架(>=1.0.0)
rspec(>=1.2.9)
rubyzip(0.9.7)
消毒(2.0.0)
nokogiri(~>1.4.4)
selenium webdriver(2.31.0)
子进程(>=0.2.5)
多重json(~>1.0)
鲁比齐普
websocket(~>1.0.4)
牛排(1.1.0)
rspec(>=1.3)
系统定时器(1.0)
systemu(2.5.2)
术语ansicolor(1.1.1)
瑟鲁比拉克(0.10.2)
libv8(~>3.3.10)
思考不应该(2.11.1)
timecop(0.6.1)
树梢(1.4.10)
多语言文字
多克隆(>=0.3.1)
uuid(2.3.6)
macaddr(~>1.0)
vpim(0.695)
网络鼠(0.5.3)
nokogiri(>=1.2.0)
机架(>=1.0)
websocket(1.0.7)
wicked_pdf(0.7.9)
xpath(0.1.4)
nokogiri(~>1.3)

我重新创建了您的代码,一切正常(规范通过)。您的
spec\u助手中有
require'shoulda'
,对吗?我能想到的另一件事是,您可能已经有一段时间没有运行
db:migrate
。另外,您肯定是在使用ruby 1.8.7吗?很难想象你和我在本地拥有的有什么不同。

你的区域模型是什么样子?@aguynamedloren添加了模型代码我用系统信息更新了问题。我应该更新测试gems吗?唯一不同的是我有
require'shoulda'
而不是
shoulda/rails
。你能试试吗?另外,请记住检查您的测试数据库<代码>bundle exec script/console
让您访问开发数据库(请参阅“加载开发环境行”)。改为尝试
RAILS\u ENV=test bundle exec script/console
。更改为在spec\u helper中需要'shoulda',但不起作用。我使用开发数据库进行测试。实际上,我正在将Rails2应用程序升级到Rails3。迁移不起作用,因此使用了模式转储。Rails 2或3上的问题也是这样吗?能否添加完整的Gemfile.lock?
$ruby -v
ruby 1.8.7 (2012-02-08 patchlevel 358) [i686-linux]
$rails -v
Rails 2.3.16
$cat spec/spec_helper.rb | grep shoulda
require 'shoulda/rails'

group :test do
  gem 'rspec', '1.3.2', :require => false
  gem 'rspec-rails', '1.3.4', :require => false
  gem 'thoughtbot-shoulda', "2.11.1"
end

$bundle exec script/console 
NOTE: Gem.source_index is deprecated, use Specification. It will be removed on or after   2011-11-01.
Gem.source_index called from   ./script/../config/../vendor/rails/railties/lib/rails/gem_dependency.rb:21.
Loading development environment (Rails 2.3.16)
NOTE: Gem.source_index is deprecated, use Specification. It will be removed on or after 2011-11-01.
Gem.source_index called from /home/prasad/projects/app/config/../vendor/rails/railties/lib/rails/gem_dependency.rb:21.
>> Zone
SQL (0.3ms)   SET NAMES 'utf8'
SQL (0.2ms)   SET SQL_AUTO_IS_NULL=0
SQL (2.4ms)   SHOW TABLES
Zone Columns (1.6ms)   SHOW FIELDS FROM `zones`
=> Zone(id: integer, organization_id: integer, name: string, description: text, created_at: datetime, updated_at: datetime)
GEM
 remote: http://rubygems.org/
 specs:
Ascii85 (1.0.2)
actionmailer (2.3.16)
  actionpack (= 2.3.16)
actionpack (2.3.16)
  activesupport (= 2.3.16)
  rack (~> 1.1.0)
active_utils (1.0.3)
  activesupport (>= 2.3.11)
  i18n
activerecord (2.3.16)
  activesupport (= 2.3.16)
activeresource (2.3.16)
  activesupport (= 2.3.16)
activesupport (2.3.16)
acts_as_xlsx (1.0.5)
  activerecord (>= 2.3.9)
  axlsx (>= 1.0.13)
  i18n (>= 0.4.1)
addressable (2.3.3)
airbrake (3.1.8)
  activesupport
  builder
  json
authorize-net (1.5.2)
  nokogiri (~> 1.4)
axlsx (1.3.5)
  htmlentities (~> 4.3.1)
  nokogiri (>= 1.4.1)
  rubyzip (>= 0.9.5)
barby (0.5.1)
builder (3.2.0)
calendar_date_select (1.16.1)
capistrano (2.9.0)
  highline
  net-scp (>= 1.0.0)
  net-sftp (>= 2.0.0)
  net-ssh (>= 2.0.14)
  net-ssh-gateway (>= 1.1.0)
capistrano-ext (1.2.1)
  capistrano (>= 1.0.0)
capybara (1.1.4)
  mime-types (>= 1.16)
  nokogiri (>= 1.3.3)
  rack (>= 1.0.0)
  rack-test (>= 0.5.4)
  selenium-webdriver (~> 2.0)
  xpath (~> 0.1.4)
capybara-webkit (0.12.1)
  capybara (>= 1.0.0, < 1.2)
  json
childprocess (0.3.9)
  ffi (~> 1.0, >= 1.0.11)
cocaine (0.4.2)
commonjs (0.2.6)
crack (0.1.8)
cucumber (1.1.0)
  builder (>= 2.1.2)
  diff-lcs (>= 1.1.2)
  gherkin (~> 2.5.0)
  json (>= 1.4.6)
  term-ansicolor (>= 1.0.6)
cucumber-rails (0.3.2)
  cucumber (>= 0.8.0)
daemon-spawn (0.3.0)
daemons (1.0.10)
delayed_job (2.0.7)
  activesupport (~> 2.0)
  daemons (= 1.0.10)
diff-lcs (1.2.1)
factory_girl (2.6.4)
  activesupport (>= 2.3.9)
faker (1.1.2)
  i18n (~> 0.5)
fakeweb (1.3.0)
fastercsv (1.5.3)
ffi (1.4.0)
gherkin (2.5.4)
  json (>= 1.4.6)
graticule (0.2.12)
  activesupport
highline (1.6.16)
hodel_3000_compliant_logger (0.1.1)
htmlentities (4.3.1)
httparty (0.6.1)
  crack (= 0.1.8)
i18n (0.5.0)
json (1.7.7)
launchy (2.2.0)
  addressable (~> 2.3)
less (2.1.0)
  commonjs (~> 0.2.0)
  therubyracer (~> 0.10.0)
libv8 (3.3.10.4)
lockfile (1.4.3)
macaddr (1.6.1)
  systemu (~> 2.5.0)
mail (2.4.1)
  i18n (>= 0.4.0)
  mime-types (~> 1.16)
  treetop (~> 1.4.8)
mechanize (1.0.0)
  nokogiri (>= 1.2.1)
mime-types (1.21)
multi_json (1.7.0)
multipart-post (1.1.0)
mysql (2.8.1)
net-scp (1.1.0)
  net-ssh (>= 2.6.5)
net-sftp (2.1.1)
  net-ssh (>= 2.6.5)
net-ssh (2.6.6)
net-ssh-gateway (1.2.0)
  net-ssh (>= 2.6.5)
newrelic_rpm (3.5.8.72)
nokogiri (1.4.7)
oink (0.1.2)
  hodel_3000_compliant_logger
paperclip (2.8.0)
  activerecord (>= 2.3.0)
  activesupport (>= 2.3.2)
  cocaine (>= 0.0.2)
  mime-types
pdf-reader (0.8.5)
  Ascii85 (>= 0.9)
pipejump (0.4.4)
polyglot (0.3.3)
postageapp (1.0.14)
  json
rack-test (0.6.2)
  rack (>= 1.0)
rails (2.3.16)
  actionmailer (= 2.3.16)
  actionpack (= 2.3.16)
  activerecord (= 2.3.16)
  activeresource (= 2.3.16)
  activesupport (= 2.3.16)
  rake (>= 0.8.3)
rake (0.8.7)
rcov (1.0.0)
rdoc (2.4.3)
rmagick (2.12.2)
rspec (1.3.2)
rspec-rails (1.2.9)
  rack (>= 1.0.0)
  rspec (>= 1.2.9)
rubyzip (0.9.7)
sanitize (2.0.0)
  nokogiri (~> 1.4.4)
selenium-webdriver (2.31.0)
  childprocess (>= 0.2.5)
  multi_json (~> 1.0)
  rubyzip
  websocket (~> 1.0.4)
steak (1.1.0)
  rspec (>= 1.3)
system_timer (1.0)
systemu (2.5.2)
term-ansicolor (1.1.1)
therubyracer (0.10.2)
  libv8 (~> 3.3.10)
thoughtbot-shoulda (2.11.1)
timecop (0.6.1)
treetop (1.4.10)
  polyglot
  polyglot (>= 0.3.1)
uuid (2.3.6)
  macaddr (~> 1.0)
vpim (0.695)
webrat (0.5.3)
  nokogiri (>= 1.2.0)
  rack (>= 1.0)
websocket (1.0.7)
wicked_pdf (0.7.9)
xpath (0.1.4)
  nokogiri (~> 1.3)