rspec hook after report gets created

前端 未结 1 1536
广开言路
广开言路 2021-01-26 00:40

Is there an rspec hook that runs after a report file gets created?

For example, in my .rspec, I have included:

--format json --out test_result         


        
相关标签:
1条回答
  • 2021-01-26 01:01

    One way you could do this is by implementing your own formatter based on the JSON formatter. Something like this could work:

    class CustomFormatter < RSpec::Core::Formatters::JsonFormatter 
      RSpec::Core::Formatters.register self, :example_started
    
      def close(_notification)
        super
    
        # Do your post processing here...
      end
    end
    

    And then you can use your custom formatter like this

    rspec --require ./custom_formatter.rb --format CustomFormatter
    

    The RSpec::Core::Formatters::JsonFormatter is marked as private so it can change anytime. You have to think if you want to take the risk to need to change and adapt in a future RSpec upgrade.

    Otherwise I would recommend to just use a custom script. It should be very simple with just && or | in it like

    rspec --format json | ./run_postprocessing
    

    https://relishapp.com/rspec/rspec-core/docs/formatters/custom-formatters https://github.com/rspec/rspec-core/blob/main/lib/rspec/core/formatters/json_formatter.rb#L56

    0 讨论(0)
提交回复
热议问题