# Logstash Filter development: rspec test for filter success/failure

**URL:** <https://discuss.elastic.co/t/logstash-filter-development-rspec-test-for-filter-success-failure/139222>\
**Category:** Logstash\
**Created:** [July 9, 2018, 6:17pm UTC](https://discuss.elastic.co/t/logstash-filter-development-rspec-test-for-filter-success-failure/139222 "2018-07-09T18:17:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fholzer](https://avatars.discourse-cdn.com/v4/letter/f/3da27b/32.png) [@fholzer](https://discuss.elastic.co/u/fholzer)\
**Post date:** [July 9, 2018, 6:17pm UTC](https://discuss.elastic.co/t/logstash-filter-development-rspec-test-for-filter-success-failure/139222/1 "2018-07-09T18:17:32Z")

</div>

Hi,

i couldn't find a way to test for filter success, i.e. whether the filter\_matched method was called on an event. I tried to find this by looking at the tests of some of the official filter plugins but couldn't find anything. I noticed the `raise_error` check, but that's about exception... I'm only interested in whether filter\_matched was called.  
This is my spec so far: [https://github.com/fholzer/logstash-filter-real\_ip/blob/master/spec/filters/real\_ip\_spec.rb](https://github.com/fholzer/logstash-filter-real_ip/blob/master/spec/filters/real_ip_spec.rb)

I'm new to ruby, so any help is highly appreciated.

Cheers,  
Ferdinand

---

<div class="post-metadata">

**Author:** ![fholzer](https://avatars.discourse-cdn.com/v4/letter/f/3da27b/32.png) [@fholzer](https://discuss.elastic.co/u/fholzer)\
**Post date:** [July 10, 2018, 9:56pm UTC](https://discuss.elastic.co/t/logstash-filter-development-rspec-test-for-filter-success-failure/139222/2 "2018-07-10T21:56:28Z")

</div>

Found a workaround. For anyone having the same issue, use an add\_field directive in your filter config block, then test whether the field was added.

Example:

- add\_field added here: [https://github.com/logstash-plugins/logstash-filter-grok/blob/95d4599e06aeabac6e9f3f7cda39e4c4af18f7ac/spec/filters/grok\_spec.rb#L245](https://github.com/logstash-plugins/logstash-filter-grok/blob/95d4599e06aeabac6e9f3f7cda39e4c4af18f7ac/spec/filters/grok_spec.rb#L245)
- tested for on line 257 of the same file

Cheers,  
Ferdinand

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [August 7, 2018, 9:56pm UTC](https://discuss.elastic.co/t/logstash-filter-development-rspec-test-for-filter-success-failure/139222/3 "2018-08-07T21:56:29Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
