Is it possible to use spec fixtures with Cucumber, and if so, how? Thanks, Daniel Higginbotham -- Posted via http://www.ruby-forum.com/.
On Wed, Oct 8, 2008 at 3:16 PM, Daniel Higginbotham <lists at 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> Thanks, > Daniel Higginbotham > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
aslak hellesoy wrote:> On Wed, Oct 8, 2008 at 3:16 PM, Daniel Higginbotham > <lists at 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/165777Yep, 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 -- Posted via http://www.ruby-forum.com/.
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 at ruby-forum.com> wrote:> aslak hellesoy wrote: >> On Wed, Oct 8, 2008 at 3:16 PM, Daniel Higginbotham >> <lists at 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 > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com
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, > > ZachThis 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 -- Posted via http://www.ruby-forum.com/.
Daniel Higginbotham <lists at ruby-forum.com> writes:> 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 HigginbothamI 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
Pat Maddox wrote:> Daniel Higginbotham <lists at 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. > > PatThanks Pat! It looks like Fixtures.create_fixtures("spec/fixtures", "users") works. -- Posted via http://www.ruby-forum.com/.
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 at rubyforge.org/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. Daniel Higginbotham wrote:> Pat Maddox wrote: > >> Daniel Higginbotham <lists at 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. >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20081010/9e141ae1/attachment.html>