我有一组针对 Rails 应用程序的 Test::Unit 测试。它是在 Ruby 1.8.6、Rails 2.3.4 下的 OS X 上开发的。
我也在使用thoughtbot-shoulda 2.10.2。
我使用的是标准 Rails 夹具,而不是工厂。
我已经将该项目签出到 CentOS Linux 5 工作站上,以供其他开发人员使用。他正在运行 Ruby 1.8.7。
(该应用程序正在生产中的 CentOS Linux 5 上运行,并且在那里运行良好。)
在我同事的 CentOS 开发机器上,所有的单元测试都通过了。
但是,大多数(但不是全部)功能测试都出错了。我已经隔离了一个测试(从项目中删除了所有其他测试)以缩小故障排除范围。
context 'on DELETE to :destroy' do
setup {
delete(:destroy, { :id => addresses(:mary_publics_address).id }, stans_id)
}
should 'delete the address' do
assert Address.find(:all, :conditions => {
:id => addresses(:mary_publics_address).id
} ).blank?
end
should 'delete the addresses phone numbers' do
assert PhoneNumber.find(:all, :conditions => {
:id => phone_numbers(:mary_publics_phone_number).id
} ).blank?
end
end
我们得到的错误是......
[abc@abc contactdb]$ rake test:functionals --trace
(in /home/abc/projects/contactdb)
[ ... ]
/usr/local/ruby_187/bin/ruby -I"lib:test" "/home/abc/.gem/ruby/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader.rb" "test/functional/addresses_controller_test.rb"
Loaded suite /home/abc/.gem/ruby/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader
Started
.E
Finished in 0.426749 seconds.
1) Error:
test: on DELETE to :destroy should delete the addresses phone numbers. (AddressesControllerTest):
ActiveRecord::RecordNotFound: Couldn't find Address with ID=1254595889
/test/functional/addresses_controller_test.rb:107:in `__bind_1255114457_160068'
/usr/local/ruby_187/lib/ruby/gems/1.8/gems/thoughtbot-shoulda-2.10.2/lib/shoulda/context.rb:369:in `call'
/usr/local/ruby_187/lib/ruby/gems/1.8/gems/thoughtbot-shoulda-2.10.2/lib/shoulda/context.rb:369:in `run_current_setup_blocks'
/usr/local/ruby_187/lib/ruby/gems/1.8/gems/thoughtbot-shoulda-2.10.2/lib/shoulda/context.rb:368:in `each'
/usr/local/ruby_187/lib/ruby/gems/1.8/gems/thoughtbot-shoulda-2.10.2/lib/shoulda/context.rb:368:in `run_current_setup_blocks'
/usr/local/ruby_187/lib/ruby/gems/1.8/gems/thoughtbot-shoulda-2.10.2/lib/shoulda/context.rb:350:in `test: on DELETE to :destroy should delete the addresses phone numbers. '
2 tests, 1 assertions, 0 failures, 1 errors
rake aborted!
Command failed with status (1): [/usr/local/ruby_187/bin/ruby -I"lib:test" ...]
我认为关键的谜团是为什么它找不到Address
具有该 ID 的。
另一个因素是,当我注释掉这个块时,剩下的测试通过了。
should 'delete the addresses phone numbers' do
assert PhoneNumber.find(:all, :conditions => {
:id => phone_numbers(:mary_publics_phone_number).id
} ).blank?
end
有人见过这个吗?
故障排除建议?