FactoryGirl.define do # 使用する際は:team1を指定する # シンボルがそのままクラス名ならclassは省略できる # name、addressがモデルの属性 factory :team1, class: Team do name :team1.to_s address '住所' end end
2013年08月22日13:26 Ruby factory_girl で最低限知っておきたい4つの使い方 みなさん、テストを書くときには Fixture Replacement として何を使ってますか?一番メジャーなところだと factory_girl でしょうか。machinist も有名ですね。シンタックスの違いのようなので基本的にはどちらでも良さそうです。 参考(stackoverflow)Machinist vs FactoryGirl - pros and cons In other words, both are extremely similar, just with a different default syntax. 今回は(僕が factory_girl4.2.0 を使ってるので)factory_girl4.2.0 についての話です。 インストール まずインストールし
factory_girlネタも今回で3回目。今回は関連について書いていきます。 前々回はこちら。 前回はこちら。 使用したバージョンなど 今回使用したバージョンは factory_girl_rails 3.0.0 factory_girl 3.0.0 を使用しています。 関連データの記述方法 postsテーブルを次のように作成して、userへの参照を持たせるようにします。 class CreatePosts < ActiveRecord::Migration def change create_table :posts do |t| t.string :title t.text :body t.references :user t.timestamps end add_index :posts, :user_id end end また、Postモデルにbelongs_toを書いておきます。
このエントリでは,Ruby on Rails (以下 Rails)の ActiveRecord モデルテストについて,1) どこの何をテストすればよいか,2) どのようにテストを書けばよいか,のガイドラインを示します.このガイドラインは Rails 公式のものではなく,id:passingloop が使っている私的なものです.疑問・質問・批判・間違いの指摘はページ下部のコメント欄までお願いします. はじめに Rails は TDD/BDD サポートが充実した Web アプリケーション開発フレームワークです.Rails で使える Test::Unit や RSpec などといったテスティングフレームワークの使い方に関する解説も豊富にあります.しかし,「どこをどうテストすればよいのか」についての解説は,「使い方」の解説と比較して少ないように思います.もっとも,テスト一般についてどう書くかはアプ
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く