Testing rails application

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 … :slight_smile: Thanks in advance

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.

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.

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
[email protected]

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:

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:

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?

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
[email protected]