# Testing rails application

**URL:** <https://www.ruby-forum.com/t/testing-rails-application/179650>\
**Category:** Rails\
**Created:** [December 1, 2009, 9:12am UTC](https://www.ruby-forum.com/t/testing-rails-application/179650 "2009-12-01T09:12:14Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![hemantborole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b782af/32.png) [@hemantborole](https://www.ruby-forum.com/u/hemantborole)\
**Post date:** [December 1, 2009, 9:12am UTC](https://www.ruby-forum.com/t/testing-rails-application/179650/1 "2009-12-01T09:12:14Z")

</div>

Hi

Actually i am doing testing of a ROR project… So what i need now is  
that is there any way/ways by which i cam dump the data of an sql table  
(lets suppose abc) into its yml file which is located in  
“test/fixtures/abc.yml”

I hope you people got it right … 🙂 Thanks in advance

---

<div class="post-metadata">

**Author:** ![hemantborole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b782af/32.png) [@hemantborole](https://www.ruby-forum.com/u/hemantborole)\
**Post date:** [December 1, 2009, 8:34pm UTC](https://www.ruby-forum.com/t/testing-rails-application/179650/2 "2009-12-01T20:34:39Z")

</div>

Hemant B. wrote:

> Hi
> 
> Actually i am doing testing of a ROR project… So what i need now is  
> that is there any way/ways by which i cam dump the data of an sql table  
> (lets suppose abc) into its yml file which is located in  
> “test/fixtures/abc.yml”

That sounds backwards! The point of test/fixtures files is to dump their  
contents into the test database between each test run. You don’t need,  
nor want, “real” data in your fixtures. You want data designed  
specifically for your tests.

---

<div class="post-metadata">

**Author:** ![hemantborole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b782af/32.png) [@hemantborole](https://www.ruby-forum.com/u/hemantborole)\
**Post date:** [December 2, 2009, 6:37am UTC](https://www.ruby-forum.com/t/testing-rails-application/179650/3 "2009-12-02T06:37:18Z")

</div>

So writing data to the yml’s(fixtures) can be created manually or is  
there any other way … ?

Robert W. wrote:

> Hemant B. wrote:
> 
> > Hi
> > 
> > Actually i am doing testing of a ROR project… So what i need now is  
> > that is there any way/ways by which i cam dump the data of an sql table  
> > (lets suppose abc) into its yml file which is located in  
> > “test/fixtures/abc.yml”
> 
> That sounds backwards! The point of test/fixtures files is to dump their  
> contents into the test database between each test run. You don’t need,  
> nor want, “real” data in your fixtures. You want data designed  
> specifically for your tests.

---

<div class="post-metadata">

**Author:** ![hemantborole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b782af/32.png) [@hemantborole](https://www.ruby-forum.com/u/hemantborole)\
**Post date:** [December 2, 2009, 3:51pm UTC](https://www.ruby-forum.com/t/testing-rails-application/179650/4 "2009-12-02T15:51:07Z")

</div>

Hemant B. wrote:

> So writing data to the yml’s(fixtures) can be created manually or is  
> there any other way … ?

You can certainly create the fixture YAML files manually.

However, Rails’ implementation of fixtures is extremely problematic.  
I’d advise you to avoid fixtures entirely and use something like  
Machinist instead.

Best,  
–Â  
MarnenÂ Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![hemantborole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b782af/32.png) [@hemantborole](https://www.ruby-forum.com/u/hemantborole)\
**Post date:** [December 2, 2009, 3:42pm UTC](https://www.ruby-forum.com/t/testing-rails-application/179650/5 "2009-12-02T15:42:23Z")

</div>

Hemant B. wrote:

> So writing data to the yml’s(fixtures) can be created manually or is  
> there any other way … ?

Yes, all you need is a text editor. If you need to know what the  
database schema looks like take a look at the db/schema.rb file. That  
will tell you what columns and column types your tables contain.

The fixture files should be created as tests are written. Enter data  
into the fixtures to support the tests that you write.

The best time to write the tests is before the code is written. This is  
referred to as Test Driven Development (TDD). There also exists a  
variant of TDD called Behavior Driven Development (BDD). The difference  
between the two is subtle. Think about BDD as an evolution of TDD. In  
BDD you write specs, as opposed to tests in the TDD world.

The idea of BDD is to systematically enforce “test first” development.  
In this technique you specify the behavior you want before the code  
providing the behavior exists. Only then do you write the code to make  
the specs pass. TDD is essentially the same. The only real difference is  
in terminology and syntax. In TDD you “assert” that the application will  
do what you expect. In BDD you “specify” that the application “should”  
behave a certain way and create “expectations” to ensure that it will.

For more information on TDD/BDD see:

> **[RSpec: Behaviour Driven Development for Ruby](http://rspec.info/)**

> **[GitHub - thoughtbot/shoulda: Makes tests easy on the fingers and the eyes](https://github.com/thoughtbot/shoulda)**
>
> Makes tests easy on the fingers and the eyes. Contribute to thoughtbot/shoulda development by creating an account on GitHub.

P.S. There is an alternative to using fixtures called factories. I  
personally use a factory gem called factory\_girl. I actually use  
factory\_girl with rSpec, but I’m sure it works great with Shoulda as  
well. Especially given that it’s from the same developer as Shoulda. I  
just happen to prefer rSpec.

Factory Girl:

> **[GitHub - thoughtbot/factory\_bot: A library for setting up Ruby objects as...](https://github.com/thoughtbot/factory_bot)**
>
> A library for setting up Ruby objects as test data. - GitHub - thoughtbot/factory\_bot: A library for setting up Ruby objects as test data.

---

<div class="post-metadata">

**Author:** ![hemantborole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b782af/32.png) [@hemantborole](https://www.ruby-forum.com/u/hemantborole)\
**Post date:** [December 4, 2009, 5:15pm UTC](https://www.ruby-forum.com/t/testing-rails-application/179650/6 "2009-12-04T17:15:54Z")

</div>

Marnen Laibow-Koser wrote:

> However, Rails’ implementation of fixtures is extremely problematic.  
> I’d advise you to avoid fixtures entirely and use something like  
> Machinist instead.

+1

I’ve been using factory\_girl, but I’ve been meaning to take a look at  
Machinist. Have you compared the two ? If so what was it that tipped the  
scales to Machinist over factory\_girl, or was it just a personal  
preference?

---

<div class="post-metadata">

**Author:** ![hemantborole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b782af/32.png) [@hemantborole](https://www.ruby-forum.com/u/hemantborole)\
**Post date:** [December 4, 2009, 6:06pm UTC](https://www.ruby-forum.com/t/testing-rails-application/179650/7 "2009-12-04T18:06:10Z")

</div>

Robert W. wrote:

> Marnen Laibow-Koser wrote:
> 
> > However, Rails’ implementation of fixtures is extremely problematic.  
> > I’d advise you to avoid fixtures entirely and use something like  
> > Machinist instead.
> 
> +1
> 
> I’ve been using factory\_girl, but I’ve been meaning to take a look at  
> Machinist. Have you compared the two ? If so what was it that tipped the  
> scales to Machinist over factory\_girl, or was it just a personal  
> preference?

I think I found Machinist’s syntax clearer, IIRC. Certainly it was  
developed put of dissatisfaction with Factory Girl’s UI.

Best,  
–Â  
MarnenÂ Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid
