Forum: RSpec cucumber and fixtures

B1358e286c103b4eb7b01f6c3f3cf288?d=identicon&s=25 Daniel Higginbotham (zzd)
on 2008-10-08 15:16
Is it possible to use spec fixtures with Cucumber, and if so, how?

Thanks,
Daniel Higginbotham
0be0e4aa42aacd9a8a95c792de273ca7?d=identicon&s=25 aslak hellesoy (Guest)
on 2008-10-08 16:29
(Received via mailing list)
On Wed, Oct 8, 2008 at 3:16 PM, Daniel Higginbotham
<lists@ruby-forum.com> 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/165777
B1358e286c103b4eb7b01f6c3f3cf288?d=identicon&s=25 Daniel Higginbotham (zzd)
on 2008-10-08 16:44
aslak hellesoy wrote:
> On Wed, Oct 8, 2008 at 3:16 PM, Daniel Higginbotham
> <lists@ruby-forum.com> 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/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 Higginbotham
F86901feca747abbb5c6c020362ef2e7?d=identicon&s=25 Zach Dennis (zdennis)
on 2008-10-08 21:56
(Received via mailing list)
I use seed_fu with cucumber.

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 Higginbotham
<lists@ruby-forum.com> wrote:
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>



--
Zach Dennis
http://www.continuousthinking.com
http://www.mutuallyhuman.com
B1358e286c103b4eb7b01f6c3f3cf288?d=identicon&s=25 Daniel Higginbotham (zzd)
on 2008-10-09 01:05
Zach Dennis wrote:
> I use seed_fu with cucumber.
>
> 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 Higginbotham
42172acdf3c6046f84d644cb0b94642c?d=identicon&s=25 Pat Maddox (pergesu)
on 2008-10-09 01:19
(Received via mailing list)
Daniel Higginbotham <lists@ruby-forum.com> 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 Higginbotham

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
B1358e286c103b4eb7b01f6c3f3cf288?d=identicon&s=25 Daniel Higginbotham (zzd)
on 2008-10-09 16:30
Pat Maddox wrote:
> Daniel Higginbotham <lists@ruby-forum.com> 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 Higginbotham
>
> 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.
07dd367bcc4ae602d640ec8c1b280df6?d=identicon&s=25 Mark Thomson (Guest)
on 2008-10-10 09:55
(Received via mailing list)
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/rspec-users@rubyforge...., 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.
This topic is locked and can not be replied to.