Custom reporter for passed examples showing all expects

42 views
Skip to first unread message

Attila Strba

unread,
Jan 5, 2018, 11:15:59 AM1/5/18
to rspec
Hi Guys, 
we are trying to use RSpec for our Integration and System testing. Just a short overview of our test framework to give some background regarding my question. We have a various Hardware hooked up to Jenkins clients which we control over Ruby and control the test execution/test logic currently in Minitest. The results of the test execution  are beeing pushed to a CouchDB. We want to move away from Minitest due to it's limitation for this use case like: no support for test suites, dependent tests, random execution order etc.  Rspec seems to have all the features we need. There is one point missing though, and that is my question:

Is there a possibility to create a reporter where we get also more information about passed test? What I want is to show which except's has been executed with which results.

Thank you in advance for any help. 
greetings
Attila

Myron Marston

unread,
Jan 5, 2018, 11:23:14 AM1/5/18
to rs...@googlegroups.com

Is there a possibility to create a reporter where we get also more information about passed test? What I want is to show which except’s has been executed with which results.

You could do that. Create a custom formatter that tracks the information you want and reports it however you want (e.g. to stdout or CouchDB or whatever). Our docs show how to define one and list all the events you can subscribe to. It sounds like you want this formatter to be in addition to a normal one (rather than replacing it), so be sure to call config.add_formatter twice — once with your normal output formatter, and once with your custom one.

Note that there are no events for each individual expectation. You’ll have to extend RSpec a bit to do that. It’s not too bad, though:

module ExtendExpect
  def expect(*args, &block)
    # put whatever custom logic around `expect` you want.  e.g. you could notify your custom formatter from here
    super
  end
end

RSpec.configure do |c|
  c.include ExtendExpect
end

HTH,
Myron



--
You received this message because you are subscribed to the Google Groups "rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rspec+unsubscribe@googlegroups.com.
To post to this group, send email to rs...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/39fc23b5-b721-478c-9ef8-df60d1c89297%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Attila Strba

unread,
Jan 11, 2018, 11:24:47 AM1/11/18
to rspec
Thank you Myron, that is exactly what I needed. Here is my current solution documented on StackOverflow: https://stackoverflow.com/questions/48116106/custom-rspec-formatter-to-display-passed-test-and-result-of-except/48211635#48211635


On Friday, January 5, 2018 at 5:23:14 PM UTC+1, Myron Marston wrote:

Is there a possibility to create a reporter where we get also more information about passed test? What I want is to show which except’s has been executed with which results.

You could do that. Create a custom formatter that tracks the information you want and reports it however you want (e.g. to stdout or CouchDB or whatever). Our docs show how to define one and list all the events you can subscribe to. It sounds like you want this formatter to be in addition to a normal one (rather than replacing it), so be sure to call config.add_formatter twice — once with your normal output formatter, and once with your custom one.

Note that there are no events for each individual expectation. You’ll have to extend RSpec a bit to do that. It’s not too bad, though:

module ExtendExpect
  def expect(*args, &block)
    # put whatever custom logic around `expect` you want.  e.g. you could notify your custom formatter from here
    super
  end
end

RSpec.configure do |c|
  c.include ExtendExpect
end

HTH,
Myron


On Fri, Jan 5, 2018 at 5:24 AM, Attila Strba <attila...@esrlabs.com> wrote:
Hi Guys, 
we are trying to use RSpec for our Integration and System testing. Just a short overview of our test framework to give some background regarding my question. We have a various Hardware hooked up to Jenkins clients which we control over Ruby and control the test execution/test logic currently in Minitest. The results of the test execution  are beeing pushed to a CouchDB. We want to move away from Minitest due to it's limitation for this use case like: no support for test suites, dependent tests, random execution order etc.  Rspec seems to have all the features we need. There is one point missing though, and that is my question:

Is there a possibility to create a reporter where we get also more information about passed test? What I want is to show which except's has been executed with which results.

Thank you in advance for any help. 
greetings
Attila

--
You received this message because you are subscribed to the Google Groups "rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rspec+un...@googlegroups.com.

Myron Marston

unread,
Jan 11, 2018, 2:24:56 PM1/11/18
to rs...@googlegroups.com
Glad to hear you figured out a solution!

To unsubscribe from this group and stop receiving emails from it, send an email to rspec+unsubscribe@googlegroups.com.

To post to this group, send email to rs...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages