Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think the best way would be using RSpec's configuration and Formatter. This would not involve parsing the IO stream, also gives much richer result customisation programmatically. </p> <h3>RSpec 2:</h3> <pre><code>require 'rspec' config = RSpec.configuration # optionally set the console output to colourful # equivalent to set --color in .rspec file config.color = true # using the output to create a formatter # documentation formatter is one of the default rspec formatter options json_formatter = RSpec::Core::Formatters::JsonFormatter.new(config.output) # set up the reporter with this formatter reporter = RSpec::Core::Reporter.new(json_formatter) config.instance_variable_set(:@reporter, reporter) # run the test with rspec runner # 'my_spec.rb' is the location of the spec file RSpec::Core::Runner.run(['my_spec.rb']) </code></pre> <p>Now you can use the <code>json_formatter</code> object to get result and summary of a spec test. </p> <pre><code># gets an array of examples executed in this test run json_formatter.output_hash </code></pre> <p>An example of <code>output_hash</code> value can be found <a href="https://gist.github.com/4467752#file-03-rspec_json_formatter_result-json" rel="noreferrer">here</a>:</p> <h3>RSpec 3</h3> <pre><code>require 'rspec' require 'rspec/core/formatters/json_formatter' config = RSpec.configuration formatter = RSpec::Core::Formatters::JsonFormatter.new(config.output_stream) # create reporter with json formatter reporter = RSpec::Core::Reporter.new(config) config.instance_variable_set(:@reporter, reporter) # internal hack # api may not be stable, make sure lock down Rspec version loader = config.send(:formatter_loader) notifications = loader.send(:notifications_for, RSpec::Core::Formatters::JsonFormatter) reporter.register_listener(formatter, *notifications) RSpec::Core::Runner.run(['spec.rb']) # here's your json hash p formatter.output_hash </code></pre> <h3>Other Resources</h3> <ul> <li><a href="http://jing.io/t/programmatically-execute-rspec-and-capture-result.html" rel="noreferrer">Detailed work through</a></li> <li><a href="https://gist.github.com/4467752" rel="noreferrer">Gist example</a></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload