FactoryGirl を使用すると、この問題が発生します。
テストを実行するたびに、次のエラーが表示されます: Undefined method `to_i' for Array
整数に変換しようとしている場所がわかりません。私の最善の推測は、レコードの ID を保存するだけでなく、クライアント レコードを数値として保存しようとしているということです。ドキュメントを検索して、工場の設定が間違っていないかどうかを確認してみました。
db:test:prepare
そうなることを願ってrake を走らせました。
何が問題なのかを確認できますか?
仕様/factories.rb
FactoryGirl.define do
factory :client do
name "Example"
email "email@example.com"
end
factory :book do
title "Book Title"
client_id {[FactoryGirl.create(:client)]}
end
end
spec/views/books/index.html.erb_spec.rb
require 'spec_helper'
describe "books/index" do
before do
FactoryGirl.create(:book)
end
it "renders a list of books" do
render
# Run the generator again with the --webrat flag if you want to use webrat matchers
assert_select "tr>td", :text => "Title".to_s, :count => 2
assert_select "tr>td", :text => 1.to_s, :count => 2
end
end
テスト出力
1) books/index renders a list of books
Failure/Error: FactoryGirl.create(:book)
NoMethodError:
undefined method `to_i' for #<Array:0x########>
# ./spec/views/books/index.html.erb_spec.rb:5:in `(root)'