将Rails从3.2.6升级到3.2.7时,我的项目https://github.com/phoet/on_ruby的RSpec测试套件失败了。
rake spec
1) Authorization should create an auth and a user from an auth-hash
Failure/Error: Authorization.create_from_hash(auth)
ActiveRecord::RecordNotUnique:
SQLite3::ConstraintException: column nickname is not unique: INSERT INTO "users" ("admin", "available", "created_at", "description", "freelancer", "github", "hide_jobs", "image", "location", "name", "nickname", "slug", "updated_at", "url") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
# ./app/models/user.rb:74:in `create_from_hash!'
# ./app/models/authorization.rb:15:in `create_from_hash'
# ./spec/models/authorization_spec.rb:23:in `block (3 levels) in <top (required)>'
# ./spec/models/authorization_spec.rb:22:in `block (2 levels) in <top (required)>'
Google Geocoding API error: over query limit. | ETA: 00:00:03
2) Location finder should find users within the default scope
Failure/Error: Location.unscoped.all.size.should be(2)
expected #<Fixnum:5> => 2
got #<Fixnum:21> => 10
Compared using equal?, which compares object identity,
but expected and actual are not the same object. Use
'actual.should eq(expected)' if you don't care about
object identity in this example.
# ./spec/models/location_spec.rb:16:in `block (3 levels) in <top (required)>'
直接运行RSpec时不会发生此问题,也不会在travis上发生此问题:http://travis-ci.org/#!/phoet/on_ruby/builds/1989858
看起来好像事务没有正确回滚。有人经历过类似的行为吗?
任何想法?
答案 0 :(得分:2)
我也是这样。据我所知,rails现在设置为ENV ['RAILS_ENV'] =开发,因此您的测试针对您的开发数据库运行。试试rake spec RAILS_ENV=test