<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
		xmlns:xhtml="http://www.w3.org/1999/xhtml"
>

<channel>
	<title>Aerialarts &#187; test</title>
	<atom:link href="http://aerial.st/tags/test/feed" rel="self" type="application/rss+xml" />
	<link>http://aerial.st</link>
	<description></description>
	<lastBuildDate>Sat, 04 Sep 2010 10:15:11 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://aerial.st/tags/test/feed" />
		<item>
		<title>Machinist+DatasetでFixture代替</title>
		<link>http://aerial.st/archive/2010/02/20/fixture-replacement</link>
		<comments>http://aerial.st/archive/2010/02/20/fixture-replacement#comments</comments>
		<pubDate>Fri, 19 Feb 2010 16:53:45 +0000</pubDate>
		<dc:creator>ikm</dc:creator>
				<category><![CDATA[開発]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[rspec]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[test]]></category>

		<guid isPermaLink="false">http://aerial.st/?p=625</guid>
		<description><![CDATA[概要 Machinistは定義された条件下でテストデータを生成するプラグイン・gem。 DatasetはRubyのコードで記述したテストデータをDBに読み込むプラグイン・gem。 この2つを組み合わせることで（比較的）メンテナンスのしやすいfixtureの代替を構築することが可能になる。 流れとしては、Dataset上でMachinistを呼び出して複数のデータを生成して、それをDBに流し込むという感じ。 メリットは、 条件下でランダムなデータを生成してくれる（「特定のデータをfixture上に作って読み込む」というようなことも可能） リレーション先のデータも適宜生成してくれる（素敵！）。 デメリットは、 データがランダムなので、全条件を必ずカバーするのは苦手＆毎回同じデータが入ってくるとは限らない（回避できるかなぁ） fixtureに依存した書き方をしていると大幅な書き換えが必要かもしれない（レコード数によるテストなど。集計系では難しい…） 最終結果のコードをGithubにあげたので、そちらも参考に。 下準備 Machinist、Dataset、そして適当な文字列のデータを作ってくれるFakerをインストール・設定する。なおテストフレームワークにはRSpec on Railsを用いる。 YAMLに頼らないテストデータの作成を参考にさせていただきました。 Machinist $ cd RAILS_ROOT $ ruby script/plugin install git://github.com/notahat/machinist.git $ vi spec/blueprints.rb # 新規作成/下記参照 $ vi spec/spec_helper.rb # 下記参照 RAILS_ROOT/spec/blueprints.rbに追記： require 'machinist/active_record' require 'sham' RAILS_ROOT/spec/spec_helper.rbに追記： # 冒頭のほうに記述 require File.expand_path(File.dirname(__FILE__) + "/blueprints") # Spec::Runner.configureブロック内に以下を記述 # -> Shamで1度生成したデータはリスト形式でキャッシュされ、 # 以降はbeforeが呼ばれるたびにその先頭から順に取り出すようになる [...]]]></description>
		<wfw:commentRss>http://aerial.st/archive/2010/02/20/fixture-replacement/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://aerial.st/archive/2010/02/20/fixture-replacement" />
	</item>
	</channel>
</rss>
