# Cucumber and fixtures

**URL:** <https://www.ruby-forum.com/t/cucumber-and-fixtures/150431>\
**Category:** RSpec\
**Created:** [October 8, 2008, 3:16pm UTC](https://www.ruby-forum.com/t/cucumber-and-fixtures/150431 "2008-10-08T15:16:00Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![agnathan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/919ad9/32.png) [@agnathan](https://www.ruby-forum.com/u/agnathan)\
**Post date:** [October 8, 2008, 3:16pm UTC](https://www.ruby-forum.com/t/cucumber-and-fixtures/150431/1 "2008-10-08T15:16:00Z")

</div>

Is it possible to use spec fixtures with Cucumber, and if so, how?

Thanks,  
Daniel H.

---

<div class="post-metadata">

**Author:** ![agnathan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/919ad9/32.png) [@agnathan](https://www.ruby-forum.com/u/agnathan)\
**Post date:** [October 8, 2008, 4:29pm UTC](https://www.ruby-forum.com/t/cucumber-and-fixtures/150431/2 "2008-10-08T16:29:01Z")

</div>

On Wed, Oct 8, 2008 at 3:16 PM, Daniel H.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Is it possible to use spec fixtures with Cucumber, and if so, how?

Google for cucumber fixtures

[http://www.ruby-forum.com/topic/165215](http://www.ruby-forum.com/topic/165215)  
[http://www.ruby-forum.com/topic/165777](http://www.ruby-forum.com/topic/165777)

---

<div class="post-metadata">

**Author:** ![agnathan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/919ad9/32.png) [@agnathan](https://www.ruby-forum.com/u/agnathan)\
**Post date:** [October 8, 2008, 4:44pm UTC](https://www.ruby-forum.com/t/cucumber-and-fixtures/150431/3 "2008-10-08T16:44:49Z")

</div>

aslak hellesoy wrote:

> On Wed, Oct 8, 2008 at 3:16 PM, Daniel H.  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > Is it possible to use spec fixtures with Cucumber, and if so, how?
> 
> Google for cucumber fixtures
> 
> [Cucumber and fixtures/FixtureReplacement - RSpec - Ruby-Forum](http://www.ruby-forum.com/topic/165215)  
> [Cucumber - stub! or mock? - RSpec - Ruby-Forum](http://www.ruby-forum.com/topic/165777)

Yep, I’ve read those threads and they both explain how to use  
alternatives to fixtures, not fixtures themselves. In the first thread  
you posted, the OP mentions that he was trying to use fixtures and they  
were never loaded into his DB.

Is there some way to use fixtures with Cucumber - not  
FixtureReplacement, not mocks, not ObjectDaddy, just fixtures?

Thanks,  
Daniel H.

---

<div class="post-metadata">

**Author:** ![agnathan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/919ad9/32.png) [@agnathan](https://www.ruby-forum.com/u/agnathan)\
**Post date:** [October 9, 2008, 1:05am UTC](https://www.ruby-forum.com/t/cucumber-and-fixtures/150431/4 "2008-10-09T01:05:23Z")

</div>

Zach D. wrote:

> I use seed\_fu with cucumber.
> 
> [http://github.com/mbleigh/seed-fu/tree](http://github.com/mbleigh/seed-fu/tree)
> 
> To load them I use the following my features/steps/env.rb. I reload  
> them for every scenarios:
> 
> Before do  
> ActiveRecord::Base.establish\_connection(ActiveRecord::Base.configurations[‘test’])  
> ActiveRecord::Schema.verbose = false  
> load “#{RAILS\_ROOT}/db/schema.rb”  
> Dir[File.join(RAILS\_ROOT, “features/fixtures”, ‘\*.rb’)].sort.each {  
> |fixture| load fixture }  
> end
> 
> My fixture files live in features/fixtures/ and each looks like:
> 
> # my\_model.rb
> 
> MyModel.transaction do  
> MyModel.seed\_many(:id, [  
> { :name =\> “blah”, :id =\> 1 },  
> { :name =\> “foo”, :id =\> 2  
> ])  
> end
> 
> I use seed\_fu for seeding production data as well. I don’t use it in  
> the sense of Rails fixtures. I use it in the sense of “the app needs  
> this data to even run, period.” Seems maybe this is what you’re  
> looking for,
> 
> Zach

This isn’t quite what I’m looking for. I’d actually like to be able to  
use the fixtures in spec/fixtures , just as I can for plain old specs.  
With specs, you can define which fixtures to use in each “describe”  
block, using something like

describe TodoList do  
fixtures :todo\_lists, :todos, :users

it “should return an error when blah blah blah” do  
…  
end  
end

Are you similarly able to load your YAML fixtures from spec/fixtures  
when you’re running a Cucumber feature?

Thanks,  
Daniel H.

---

<div class="post-metadata">

**Author:** ![agnathan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/919ad9/32.png) [@agnathan](https://www.ruby-forum.com/u/agnathan)\
**Post date:** [October 8, 2008, 9:56pm UTC](https://www.ruby-forum.com/t/cucumber-and-fixtures/150431/5 "2008-10-08T21:56:58Z")

</div>

I use seed\_fu with cucumber.

[http://github.com/mbleigh/seed-fu/tree](http://github.com/mbleigh/seed-fu/tree)

To load them I use the following my features/steps/env.rb. I reload  
them for every scenarios:

Before do  
ActiveRecord::Base.establish\_connection(ActiveRecord::Base.configurations[‘test’])  
ActiveRecord::Schema.verbose = false  
load “#{RAILS\_ROOT}/db/schema.rb”  
Dir[File.join(RAILS\_ROOT, “features/fixtures”, ‘\*.rb’)].sort.each {  
|fixture| load fixture }  
end

My fixture files live in features/fixtures/ and each looks like:

# my\_model.rb

MyModel.transaction do  
MyModel.seed\_many(:id, [  
{ :name =\> “blah”, :id =\> 1 },  
{ :name =\> “foo”, :id =\> 2  
])  
end

I use seed\_fu for seeding production data as well. I don’t use it in  
the sense of Rails fixtures. I use it in the sense of “the app needs  
this data to even run, period.” Seems maybe this is what you’re  
looking for,

Zach

On Wed, Oct 8, 2008 at 10:44 AM, Daniel H.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> * * *
> 
> 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)

–  
Zach D.  
[http://www.continuousthinking.com](http://www.continuousthinking.com)

> **[Homepage | Mutually Human](https://www.mutuallyhuman.com)**
>
> We empower businesses to overcome challenges with a holistic focus on People, Process, and Technology for lasting results and innovation.

---

<div class="post-metadata">

**Author:** ![agnathan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/919ad9/32.png) [@agnathan](https://www.ruby-forum.com/u/agnathan)\
**Post date:** [October 9, 2008, 4:30pm UTC](https://www.ruby-forum.com/t/cucumber-and-fixtures/150431/6 "2008-10-09T16:30:42Z")

</div>

Pat M. wrote:

> Daniel H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:
> 
> > > ActiveRecord::Schema.verbose = false  
> > > { :name =\> “blah”, :id =\> 1 },
> > 
> > end  
> > end
> > 
> > Are you similarly able to load your YAML fixtures from spec/fixtures  
> > when you’re running a Cucumber feature?
> > 
> > Thanks,  
> > Daniel H.
> 
> I don’t know that it’s built into Cucumber, but loading fixtures is  
> pretty simple from what I remember. Something like  
> AR::Fixtures.load(‘path/to/file.yml’) or something. Look around and I’m  
> sure you can find the couple lines to make it work.
> 
> Pat

Thanks Pat!

It looks like

Fixtures.create\_fixtures(“spec/fixtures”, “users”)

works.

---

<div class="post-metadata">

**Author:** ![agnathan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/919ad9/32.png) [@agnathan](https://www.ruby-forum.com/u/agnathan)\
**Post date:** [October 10, 2008, 9:55am UTC](https://www.ruby-forum.com/t/cucumber-and-fixtures/150431/7 "2008-10-10T09:55:09Z")

</div>

Hilarious. This is exactly what I needed today as well and eventually  
found this thread through Google, not realizing it was already sitting  
in my inbox. :-).

In my case I wanted to use fixtures in testing because the development  
db had already been populated by a data migration, and I didn’t want to  
write more code to both define and load the data as would be required  
using seed-fu. It seemed easier to install the ar\_fixtures plugin and  
use that to dump the data to a yaml file and then load the data in as  
part of my story execution. Hence my need for the solution Daniel  
mentioned.

Despite my inexperience, I was a little surprised that I had difficulty  
figuring out how to do this. I’m still not sure why “fixtures :model”  
like you would use in Test::Unit does not work. And I can report that  
“self.class.fixtures :all” recommended here:  
[http://www.mail-archive.com/removed\_email\_address@domain.invalid/msg03194.html](http://www.mail-archive.com/removed_email_address@domain.invalid/msg03194.html), did  
not work for me. I presume that at some point some more extensive  
documentation for Cucumber will appear and I think this is an example of  
an issue that would be helpful to have described in more detail.

Mark.

---

<div class="post-metadata">

**Author:** ![agnathan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/919ad9/32.png) [@agnathan](https://www.ruby-forum.com/u/agnathan)\
**Post date:** [October 9, 2008, 1:19am UTC](https://www.ruby-forum.com/t/cucumber-and-fixtures/150431/8 "2008-10-09T01:19:44Z")

</div>

Daniel H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

> > ActiveRecord::Schema.verbose = false  
> > { :name =\> “blah”, :id =\> 1 },
> 
> end  
> end
> 
> Are you similarly able to load your YAML fixtures from spec/fixtures  
> when you’re running a Cucumber feature?
> 
> Thanks,  
> Daniel H.

I don’t know that it’s built into Cucumber, but loading fixtures is  
pretty simple from what I remember. Something like  
AR::Fixtures.load(‘path/to/file.yml’) or something. Look around and I’m  
sure you can find the couple lines to make it work.

Pat
