Ben Fyvie
2010-Feb-16 16:48 UTC
[rspec-users] adding to the callbacks that rspec-rails adds
I have some code that adds to the callbacks that rspec-rails adds by default to <a href="http://github.com/dchelimsky/rspec-rails/blob/master/lib/spec/rails/in terop/testcase.rb">setup and teardown fixtures</a>. My code looks something like: module Test module Unit class TestCase append_before(:each) do Test::Unit::AfterFixturesLoaded.custom_stuff1 end append_after(:each) do Test::Unit::AfterFixturesLoaded.custom_stuff2 end end class AfterFixturesLoaded def self.custom_stuff1 #do some stuff here end def self.custom_stuff2 #do some other stuff here end end end end This code works fine if I put it in the config\initializers directory in the rails app, but then running the app fails because it doesn''t load test unit. So my question is where can I put this code so that it will always be included when running rspec? Thanks! Ben Fyvie -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20100216/cd95e9eb/attachment.html>
David Chelimsky
2010-Feb-17 12:59 UTC
[rspec-users] adding to the callbacks that rspec-rails adds
On Tue, Feb 16, 2010 at 10:48 AM, Ben Fyvie <ben.fyvie at champsoftware.com> wrote:> I have some code that adds to the callbacks that rspec-rails adds by default > to <a > href="http://github.com/dchelimsky/rspec-rails/blob/master/lib/spec/rails/interop/testcase.rb">setup > and teardown fixtures</a>. > > > > My code looks something like: > > > > ??? module Test > > ????? module Unit > > > > ??????? class TestCase > > ????????? append_before(:each) do > > ?????????? Test::Unit::AfterFixturesLoaded.custom_stuff1 > > ????????? end > > > > ????????? append_after(:each) do > > ??????????? Test::Unit::AfterFixturesLoaded.custom_stuff2 > > ????????? end > > ??????? end > > > > ??????? class AfterFixturesLoaded > > > > ????????? def self.custom_stuff1 > > ??????????? #do some stuff here > > ????????? end > > > > ????????? def self.custom_stuff2 > > ??????????? #do some other stuff here > > ????????? end > > ??????? end > > > > ????? end > > ??? end > > > > This code works fine if I put it in the config\initializers directory in the > rails app, but then running the app fails because it doesn''t load test unit. > So my question is where can I put this code so that it will always be > included when running rspec?The convention is to put support files in spec/support/, and require .rb files in that directory from spec/spec_helper.rb. The spec/spec_helper.rb file generated by rspec-rails when you execute "script/generate rspec" ("script/rails g rspec:install" in rails 3) includes a line that handles the require for you. HTH, David
Pat Maddox
2010-Feb-20 01:04 UTC
[rspec-users] adding to the callbacks that rspec-rails adds
Look in spec/spec_helper.rb for the configuration block, and hook up your custom stuff there: Spec::Runner.configured do |config| config.before(:each) { AfterFixturesLoaded.custom_stuff1 } config.after(:each) { AfterFixturesLoaded.custom_stuff1 } end Pat On Feb 16, 2010, at 8:48 AM, Ben Fyvie wrote:> I have some code that adds to the callbacks that rspec-rails adds by default to <a href="http://github.com/dchelimsky/rspec-rails/blob/master/lib/spec/rails/interop/testcase.rb">setup and teardown fixtures</a>. > > My code looks something like: > > module Test > module Unit > > class TestCase > append_before(:each) do > Test::Unit::AfterFixturesLoaded.custom_stuff1 > end > > append_after(:each) do > Test::Unit::AfterFixturesLoaded.custom_stuff2 > end > end > > class AfterFixturesLoaded > > def self.custom_stuff1 > #do some stuff here > end > > def self.custom_stuff2 > #do some other stuff here > end > end > > end > end > > This code works fine if I put it in the config\initializers directory in the rails app, but then running the app fails because it doesn''t load test unit. So my question is where can I put this code so that it will always be included when running rspec? > > Thanks! > Ben Fyvie > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20100219/94c29d07/attachment.html>