私はRails 3.2.3アプリから一連のモデルを宝石に抽出しようとしているので、アプリケーション間の共有インターフェースとして使うことができます。 宝石の中のActiveRecordモデルをテストしますか?
は私がモジュールにモデルを移動し、私はgemfileにRSpecのploppedmodule InviteInterface
class Invite < ActiveRecord::Base
belongs_to :user
end
def to_json; end;
def from_json; end;
end
のlib/invite_interface/invite.rbに入れて、それが正常に動作して得た、以下の仕様作成:
require 'spec_helper'
describe InviteInterface::EncounterSurvey do
it 'should belong to user' do
subject.should respond_to(:user)
end
end
を
残念ながら、アクティブレコード/ rspecがアクティブな接続を必要とするため、モデルでrspecを実行できません。
1) InviteInterface::Invite should belong to encounter survey set
Failure/Error: subject.should respond_to(:user)
ActiveRecord::ConnectionNotEstablished:
ActiveRecord::ConnectionNotEstablished
# /Users/justin/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:398:in `retrieve_connection'
# /Users/justin/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract/connection_specification.rb:168:in `retrieve_connection'
# /Users/justin/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract/connection_specification.rb:142:in `connection'
# /Users/justin/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/activerecord-3.2.3/lib/active_record/model_schema.rb:228:in `columns'
# /Users/justin/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/activerecord-3.2.3/lib/active_record/model_schema.rb:243:in `column_defaults'
どのようにしてActiveRecordがDB接続を検索しないようにしますか?
ありがとうございました。これは最終的に私のために働いていましたが(苦しいsqlite3の問題のためにrspecからminitestに移動しなくてはなりませんでしたが) –
これは素晴らしいです。以下のオプションを使用してください:database => ':memory:' – ghayes
@juwileyあなたの経験に基づいてminitestまたはrspecを使用するべきことをアドバイスできますか? –