Peter Boling
2011-Mar-30 16:28 UTC
[rspec-users] [HOOKS] spec_helper aware of full test suite being run? After hook to run code after running all specs?
Sorry if multiple postings of this show up. I had to RTFM a few times before I figured out how to post correctly. I use VCR to record interactions, and when the recordings change filenames, and directory structure, over time, as the test suite evolves, the old recordings, no longer used, are rarely pruned. I would like to have the ability to run rspec with an option to check for unused VCR recordings, and another to both check and delete unused recordings. I need a way to know if the full spec suite is being run. I think this can be determined with some fancy testing on ARGV. I can get the full list of recordings like this (or similar): FileList["spec/fixtures/vcr/**/*.yml"].reject{|file|File.directory?(file)} And then prune the list as each recording is used by the spec suite, afterwards having a list of the recordings that should be deleted. I need a hook that will run after the complete spec suite is run, before exiting the process, while still in the context of the thread, and the variable containing my list of files to delete is still accessible. Failing that I can write the list to a file, and hook in the deletion in the rake spec task. The downside of this is I currently run the test suite with `bundle exec rspec spec`, and don''t really use the `rake spec` task. Aside: It would involve some (lots?) of work to get `rake spec` working in this project. Currently when I run `rake spec` there is no output at all. It appears to load the rails env, and do nothing. Any one have an idea about that? -- |7eter H. l3oling -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110330/09dfbc24/attachment.html>
Peter Boling
2011-Mar-30 17:59 UTC
[rspec-users] [HOOKS] spec_helper aware of full test suite being run? After hook to run code after running all specs?
Update: I have fixed rake spec. Someone else on the team had removed the gem dependency from the development group in the Gemfile. Once added back rake spec worked fine.
Peter Boling
2011-Mar-31 13:14 UTC
[rspec-users] [HOOKS] spec_helper aware of full test suite being run? After hook to run code after running all specs?
Some additional data: rspec 2.5.1 rspec-rails 2.5.1 rails 3.0.4 ruby 1.9.2p0 rake 0.8.7 I have gotten all of this working now with the exception of a way to hook some code to be run after finishing all specs while still in the same thread. When I run Rake::Task["spec"].invoke within another rake task the list of VCR cassettes that have been ''touched'' by the tests is not retained after the invoke method executes. I''ve tried storing it in a class instance variable @@file_list, as well as a global ruby var $file_list, with no dice. I think the only option to persist the list of file is now to write the file list to a yaml, and then pull it back out. :(
Peter Boling
2011-Mar-31 18:16 UTC
[rspec-users] [HOOKS] spec_helper aware of full test suite being run? After hook to run code after running all specs?
I have implemented a full solution. Had to persist the list of unused VCR cassettes to the file system. Cheers! It would be still be cool if there was an after hook on rspec, as there is on capistrano! -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110331/681d6d3a/attachment.html>
Justin Ko
2011-Mar-31 18:27 UTC
[rspec-users] [HOOKS] spec_helper aware of full test suite being run? After hook to run code after running all specs?
On Thu, Mar 31, 2011 at 11:16 AM, Peter Boling <peter.boling at gmail.com>wrote:> I have implemented a full solution. Had to persist the list of unused VCR > cassettes to the file system. > Cheers! > It would be still be cool if there was an after hook on rspec, as there is > on capistrano! > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >http://relishapp.com/rspec/rspec-core/v/2-5/dir/hooks/before-and-after-hooks -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110331/2d47ec2d/attachment.html>
Peter Boling
2011-Apr-01 13:19 UTC
[rspec-users] [HOOKS] spec_helper aware of full test suite being run? After hook to run code after running all specs?
Wow! That''s perfect, I think. I''ll have to play around with it and make sure the after suite can be made to only run code if the entire suite has been run, but it looks promising! - Peter -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110401/35ac290c/attachment.html>
Peter Boling
2011-Apr-01 15:34 UTC
[rspec-users] [HOOKS] spec_helper aware of full test suite being run? After hook to run code after running all specs?
The before and after :suite hooks work for running code before and after rspec runs all the tests specified, but I need it to explicitly *not run* when anything less than every single spec is being run. In other words is we are running rspec spec or rake spec I need this before and after :suite hooks to run (to clean-up VCR cassettes). If we are not running the full suite, then it would mistakenly delete the VCR cassettes that were not used by the spec run. So I need it to not run the before and after :suite code if running, for example, rake spec:models or rspec spec/controllers. I am not sure if rspec, or spec helper is aware of the full test suite being run. ARGV won''t work because when rake spec runs it executes rspec with every individual spec''s path, so there is no way to tell from ARGV if it is the full suite, without getting really hacky. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110401/11d72463/attachment.html>
Justin Ko
2011-Apr-01 16:31 UTC
[rspec-users] [HOOKS] spec_helper aware of full test suite being run? After hook to run code after running all specs?
On Fri, Apr 1, 2011 at 8:34 AM, Peter Boling <peter.boling at gmail.com> wrote:> The before and after :suite hooks work for running code before and after > rspec runs all the tests specified, but I need it to explicitly *not run* when > anything less than every single spec is being run. In other words is we are > running rspec spec or rake spec I need this before and after :suite hooks to > run (to clean-up VCR cassettes). If we are not running the full suite, then > it would mistakenly delete the VCR cassettes that were not used by the spec > run. > > So I need it to not run the before and after :suite code if running, for > example, rake spec:models or rspec spec/controllers. I am not sure if > rspec, or spec helper is aware of the full test suite being run. ARGV won''t > work because when rake spec runs it executes rspec with every individual > spec''s path, so there is no way to tell from ARGV if it is the full suite, > without getting really hacky. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >You could make your own task that depends on "spec": task :task_to_run_all_spec_and_do_something_with_vcr => :spec do # my VCR code end Obviously, this wouldn''t work with "rspec spec" -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110401/0c022d4c/attachment-0001.html>