I poked at the RSpec source code and realized that the following would work. Just put this code in spec_helper.rb or some other file that loads when you run the tests:
RSpec.configure do |config| config.after(:suite) do examples = RSpec.world.filtered_examples.values.flatten if examples.none?(&:exception)
The RSpec.world.filtered_examples hash associates group examples with an array of examples from this group. Rspec has functions for filtering specific examples, and this hash, apparently, contains only those examples that were actually running.
One alternative way to configure your system would be to check the rspec process return code. If it is 0, all tests are passed and you can change the seed.
In a shell script, you can define a command that modifies the seed and runs:
rspec && change_seed
If your project has a Rakefile, you can configure something like this:
task "default" => "spec_and_change_seed" task "spec" do sh "rspec spec/my_spec.rb" end task "spec_and_change_seed" => "spec" do
If the specifications do not work, then the rake "spec" task will fail and it will not continue to modify the seed.
source share