# Customise testing report

**URL:** <https://discourse.chef.io/t/customise-testing-report/11722>\
**Category:** Chef InSpec\
**Created:** [October 10, 2017, 1:06am UTC](https://discourse.chef.io/t/customise-testing-report/11722 "2017-10-10T01:06:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jazjas](https://avatars.discourse-cdn.com/v4/letter/j/9e8a1a/32.png) [@jazjas](https://discourse.chef.io/u/jazjas)\
**Post date:** [October 10, 2017, 1:06am UTC](https://discourse.chef.io/t/customise-testing-report/11722/1 "2017-10-10T01:06:32Z")

</div>

**I would like to be able to generate a report in my own way with my own content.**

I want to know whether and how to capture a test result and write something out to a separated file if a particular test failed.

For instance, for the given control below:

```
describe security_policy do
  its('PasswordComplexity') { should_not be 0 }
  its('MinimumPasswordLength') { should be >= 10 }
end

```

I want to write a test report into a file A.txt if the PasswordComplexity is disabled, (ie the its(‘PasswordComplexity’) { should\_not be 0 } test failed), and want to generate another report in B.txt when the PasswordComplexity is enabled (ie the its(‘PasswordComplexity’) { should\_not be 0 } test passed) but the min password length is less then 10.

Any hints will be really appreciated.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![simark](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/simark/32/2099_2.png) [@simark](https://discourse.chef.io/u/simark)\
**Post date:** [October 10, 2017, 7:48am UTC](https://discourse.chef.io/t/customise-testing-report/11722/2 "2017-10-10T07:48:00Z")

</div>

You could define the output of the InSpec result as json and parse the json object accordingly

---

<div class="post-metadata">

**Author:** ![Franklin](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/franklin/32/1340_2.png) [@Franklin](https://discourse.chef.io/u/Franklin)\
**Post date:** [December 1, 2017, 9:38pm UTC](https://discourse.chef.io/t/customise-testing-report/11722/3 "2017-12-01T21:38:30Z")

</div>

Another way to address this problem would be to create a customer formatter and use that formatter when running `inspec exec`. However, I don’t actually believe that the InSpec CLI allows support for customer formatters without some monkey patching.

- [https://relishapp.com/rspec/rspec-core/v/3-0/docs/formatters/custom-formatters](https://relishapp.com/rspec/rspec-core/v/3-0/docs/formatters/custom-formatters)

- [https://github.com/chef/inspec/blob/master/lib/inspec/rspec\_json\_formatter.rb](https://github.com/chef/inspec/blob/master/lib/inspec/rspec_json_formatter.rb)

- [https://ieftimov.com/how-to-write-rspec-formatters-from-scratch](https://ieftimov.com/how-to-write-rspec-formatters-from-scratch)

Because `inspec` does not support `--require ... --format ...` the only point of entry I see would be to write a formatter (Ruby class) as a ruby file and include it a profile.

---

<div class="post-metadata">

**Author:** ![Franklin](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/franklin/32/1340_2.png) [@Franklin](https://discourse.chef.io/u/Franklin)\
**Post date:** [December 1, 2017, 10:02pm UTC](https://discourse.chef.io/t/customise-testing-report/11722/4 "2017-12-01T22:02:07Z")

</div>

Another workaround would be to catch the exception generated when the expectation fails and then write out something to a file. This isn’t really that great of a solution either:

```auto
describe security_policy do
  it 'has password complexity enabled' do
    begin
      security_policy.PasswordComplexity.should_not be 0
    rescue Exception => e
      File.write('A.txt','PasswordComplexity is disabled')
      raise e
    end
  end

```

This is an example of how you could intercept the exception generated from the failure, write out a file upon failure, and then continue to raise the exception up the stack so that the example fails.

This does not include the logic if one passes and the other does not. I assume that these may be tied together so you might not need to worry about that but if you did, you would likely have to combine both of these expectations, maintain some state (hard if the expectations are run in a random order), or do some introspection on RSpec to see if the other example has failed.

I don’t recommend this as a long term solution or something that you would want to litter throughout your controls but wanted to give you something that you could possibly use if you **must** have this feature.

---

<div class="post-metadata">

**Author:** ![sailaja](https://avatars.discourse-cdn.com/v4/letter/s/47e85d/32.png) [@sailaja](https://discourse.chef.io/u/sailaja)\
**Post date:** [March 12, 2019, 1:53am UTC](https://discourse.chef.io/t/customise-testing-report/11722/5 "2019-03-12T01:53:42Z")

</div>

Please help me to get the code for customizing HTML reports (More business friendly reports)
