# Cucumber and fixtures/FixtureReplacement

**URL:** <https://www.ruby-forum.com/t/cucumber-and-fixtures-fixturereplacement/148140>\
**Category:** RSpec\
**Created:** [September 9, 2008, 7:24pm UTC](https://www.ruby-forum.com/t/cucumber-and-fixtures-fixturereplacement/148140 "2008-09-09T19:24:09Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![tgreiser](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/258eb7/32.png) [@tgreiser](https://www.ruby-forum.com/u/tgreiser)\
**Post date:** [September 9, 2008, 7:24pm UTC](https://www.ruby-forum.com/t/cucumber-and-fixtures-fixturereplacement/148140/1 "2008-09-09T19:24:09Z")

</div>

Hey guys,

I’d never used RSpec Stories before, so I decided to follow the  
apparent direction of the wind and just jump right into cucumber. I’m  
dabbling with/using Cucumber and really like it. Good job, aslak!

Where i’m struggling right now is using either fixtures or a model  
factory methodology like the FixtureReplacement. In both cases, I’m  
not seeing anything getting loaded into the database.

I have some legacy fixtures that I’m willing to let go of, but I kind  
of assumed that they would work for now. When I run my Features, I’m  
not seeing anything whatsoever loaded into the db.

When I use FixtureReplacement ([http://replacefixtures.rubyforge.org/](http://replacefixtures.rubyforge.org/)),  
i’m getting errors that the methods aren’t defined. I’ve added a  
“config.include FixtureReplacement” to my spec\_helper but that didn’t  
seem to make any difference. Then I tried adding “include  
FixtureReplacement” into my Steps Before block, but that doesn’t work  
either.

## any thoughts?

Tim G.  
Rails 2.0.2  
RSpec 1.1.4

---

<div class="post-metadata">

**Author:** ![tgreiser](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/258eb7/32.png) [@tgreiser](https://www.ruby-forum.com/u/tgreiser)\
**Post date:** [September 9, 2008, 7:45pm UTC](https://www.ruby-forum.com/t/cucumber-and-fixtures-fixturereplacement/148140/2 "2008-09-09T19:45:55Z")

</div>

Remember these things should use transactions, and may do that by  
default - the database will be wiped clean once the features have run.

On 9 Sep 2008, at 18:22, Tim G. wrote:

> ## I have some legacy fixtures that I’m willing to let go of, but I any thoughts?
> 
> Tim G.  
> Rails 2.0.2  
> RSpec 1.1.4
> 
> * * *
> 
> rspec-users mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [http://rubyforge.org/mailman/listinfo/rspec-users](http://rubyforge.org/mailman/listinfo/rspec-users)

## cheers, Matt

> **[Tea-Driven Development – Matt Wynne taking it one tea at a time](http://blog.mattwynne.net)**

> **[Find the Best Concerts Near You, Tour Dates & Tickets Worldwide | Songkick](https://www.songkick.com/)**
>
> Find live music near you, track your favorite artists, get instant concert alerts and buy tickets for all the best upcoming concerts.

In case you wondered: The opinions expressed in this email are my own  
and do not necessarily reflect the views of any former, current or  
future employers of mine.

---

<div class="post-metadata">

**Author:** ![tgreiser](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/258eb7/32.png) [@tgreiser](https://www.ruby-forum.com/u/tgreiser)\
**Post date:** [September 9, 2008, 8:00pm UTC](https://www.ruby-forum.com/t/cucumber-and-fixtures-fixturereplacement/148140/3 "2008-09-09T20:00:02Z")

</div>

On Tue, Sep 9, 2008 at 7:45 PM, Matt W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Remember these things should use transactions, and may do that by default -  
> the database will be wiped clean once the features have run.

FWIW, When Cucumber is used with Rails it runs all scenarios in a  
transaction.

I haven’t tried FixtureReplacement, but it should work just fine in  
Given steps. I think you’d just have to make sure you mix in the  
FixtureReplacement module in your “world”. Put this in your  
steps/env.rb and let us know how it works:

Before do  
self.extend(FixtureReplacement)  
end

Aslak

> On 9 Sep 2008, at 18:22, Tim G. wrote:
> 
> > Hey guys,
> > 
> > I’d never used RSpec Stories before, so I decided to follow the apparent  
> > direction of the wind and just jump right into cucumber. I’m dabbling  
> > with/using Cucumber and really like it. Good job, aslak!

Thanks!

> > FixtureReplacement" to my spec\_helper but that didn’t seem to make any  
> > The spec helper doesn’t influence cucumber

> > difference. Then I tried adding “include FixtureReplacement” into my Steps

In Ruby - include is for classes/modules. Use extend to mix in a  
module in an object. See above.

HTH,  
Aslak

---

<div class="post-metadata">

**Author:** ![tgreiser](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/258eb7/32.png) [@tgreiser](https://www.ruby-forum.com/u/tgreiser)\
**Post date:** [September 9, 2008, 8:44pm UTC](https://www.ruby-forum.com/t/cucumber-and-fixtures-fixturereplacement/148140/4 "2008-09-09T20:44:07Z")

</div>

> > Before do  
> > self.extend(FixtureReplacement)  
> > end
> 
> I had previously tried this right in the steps file:  
> Before do  
> self.include(FixtureReplacement)  
> end

Actually - this turned out to almost the right thing. I just added  
this to my env.rb:  
`include FixtureReplacement`

Wrapping it in the Before block didn’t work. Removing it from the  
block did.

take care,  
tim

---

<div class="post-metadata">

**Author:** ![tgreiser](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/258eb7/32.png) [@tgreiser](https://www.ruby-forum.com/u/tgreiser)\
**Post date:** [September 9, 2008, 8:24pm UTC](https://www.ruby-forum.com/t/cucumber-and-fixtures-fixturereplacement/148140/5 "2008-09-09T20:24:45Z")

</div>

> On Tue, Sep 9, 2008 at 7:45 PM, Matt W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > Remember these things should use transactions, and may do that by  
> > default -  
> > the database will be wiped clean once the features have run.

sorry - I wasn’t trying to say that the database is empty after the  
scenarios are run, but that the specific fixtures or  
FixtureReplacements aren’t in the db during the scenario. I’m basing  
that on doing Model.find(…) calls right in the steps file.

> end  
> I had previously tried this right in the steps file:  
> Before do  
> self.include(FixtureReplacement)  
> end

That resulted in an “undefined method `create\_project’” exception.  
Trying what you suggest above (both in the env.rb file or the steps  
file) results in the same exception:

```
 Given that I am on the new project investment page
   undefined method `create_project' for

```

## #ActionController::Integration::Session:0x43b0a5c (NoMethodError) /Library/Ruby/Gems/1.8/gems/actionpack-2.0.2/lib/ action\_controller/test\_process.rb:464:in `method_missing' /Users/tim/projects/donortrust/branches/1-3-development/vendor/ plugins/rspec/lib/spec/matchers.rb:149:in `method\_missing’ /Users/tim/projects/donortrust/branches/1-3-development/vendor/ plugins/webrat/lib/webrat/rails/session.rb:26:in `method_missing' /Library/Ruby/Gems/1.8/gems/actionpack-2.0.2/lib/ action_controller/integration.rb:448:in `send!’ /Library/Ruby/Gems/1.8/gems/actionpack-2.0.2/lib/ action\_controller/integration.rb:448:in `method_missing' ./features/steps/cart_steps.rb:8:in `Given /I am on the new project investment page/’ features/cart.feature:36:in `Given that I am on the new project investment page’

Tim G.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Rails v2.0.2  
RSpec v1.1.4

---

<div class="post-metadata">

**Author:** ![tgreiser](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/258eb7/32.png) [@tgreiser](https://www.ruby-forum.com/u/tgreiser)\
**Post date:** [September 9, 2008, 8:59pm UTC](https://www.ruby-forum.com/t/cucumber-and-fixtures-fixturereplacement/148140/6 "2008-09-09T20:59:58Z")

</div>

> Did you see that my code uses extend?

Yes - tried both in my flailing about 🙂

> If that still doesn’t work, file a bug report.  
> [Lighthouse - Beautifully Simple Issue Tracking](http://rspec.lighthouseapp.com/projects/16211-cucumber/overview)
> 
> It might be a FixtureReplacement bug, but I’ll still look into it.

Could it be that FixtureReplacement is generating methods on the fly,  
so to speak?

given that it works when I just `include’ it, is it still a bug?

thanks,  
tim

---

<div class="post-metadata">

**Author:** ![tgreiser](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/258eb7/32.png) [@tgreiser](https://www.ruby-forum.com/u/tgreiser)\
**Post date:** [September 9, 2008, 8:44pm UTC](https://www.ruby-forum.com/t/cucumber-and-fixtures-fixturereplacement/148140/7 "2008-09-09T20:44:07Z")

</div>

On Tue, Sep 9, 2008 at 8:20 PM, Tim G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Model.find(…) calls right in the steps file.
> 
> > self.extend(FixtureReplacement)  
> > end
> 
> I had previously tried this right in the steps file:  
> Before do  
> self.include(FixtureReplacement)  
> end

Did you see that my code uses extend?

If that still doesn’t work, file a bug report.

> **[Lighthouse - Beautifully Simple Issue Tracking](https://lighthouseapp.com/)**

It might be a FixtureReplacement bug, but I’ll still look into it.

---

<div class="post-metadata">

**Author:** ![tgreiser](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/258eb7/32.png) [@tgreiser](https://www.ruby-forum.com/u/tgreiser)\
**Post date:** [September 9, 2008, 9:11pm UTC](https://www.ruby-forum.com/t/cucumber-and-fixtures-fixturereplacement/148140/8 "2008-09-09T21:11:08Z")

</div>

> fly, so to speak?

Maybe

> given that it works when I just `include’ it, is it still a bug?

What? Is it working? Or not? Confused. File a bug if nothing you do  
makes it work.

---

<div class="post-metadata">

**Author:** ![tgreiser](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/258eb7/32.png) [@tgreiser](https://www.ruby-forum.com/u/tgreiser)\
**Post date:** [September 10, 2008, 3:03am UTC](https://www.ruby-forum.com/t/cucumber-and-fixtures-fixturereplacement/148140/9 "2008-09-10T03:03:44Z")

</div>

On Sep 9, 2008, at 2:58 PM, Tim G. wrote:

> fly, so to speak?
> 
> given that it works when I just `include’ it, is it still a bug?

Yeah - it’s a module, but it does generate the methods only when  
included (see the following gist: [9801’s gists · GitHub](http://gist.github.com/9801))

I believe that Module does has an hook mechanism for extending, as  
well (Module#extended) - so I’ll look into doing that. Feel free to  
file a bug report on rubyforge:

[http://rubyforge.org/tracker/?group\_id=4556&atid=17542](http://rubyforge.org/tracker/?group_id=4556&atid=17542)

Scott
