Is it possible to use spec fixtures with Cucumber, and if so, how?
Thanks,
Daniel H.
Is it possible to use spec fixtures with Cucumber, and if so, how?
Thanks,
Daniel H.
On Wed, Oct 8, 2008 at 3:16 PM, Daniel H.
[email protected] 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
aslak hellesoy wrote:
On Wed, Oct 8, 2008 at 3:16 PM, Daniel H.
[email protected] 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
Cucumber - stub! or mock? - RSpec - Ruby-Forum
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.
Zach D. 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 }
endMy 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
])
endI 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.
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:
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.
[email protected] wrote:
–
Posted via http://www.ruby-forum.com/.
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users
–
Zach D.
http://www.continuousthinking.com
Pat M. wrote:
Daniel H. [email protected] writes:
ActiveRecord::Schema.verbose = false
{ :name => “blah”, :id => 1 },end
endAre 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.
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/[email protected]/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 H. [email protected] writes:
ActiveRecord::Schema.verbose = false
{ :name => “blah”, :id => 1 },end
endAre 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
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs