# Rspec tests for logstash 2.1

**URL:** <https://discuss.elastic.co/t/rspec-tests-for-logstash-2-1/39548>\
**Category:** Logstash\
**Created:** [January 19, 2016, 1:40pm UTC](https://discuss.elastic.co/t/rspec-tests-for-logstash-2-1/39548 "2016-01-19T13:40:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rudy\_Gevaert](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rudy_gevaert/32/5904_2.png) [@Rudy\_Gevaert](https://discuss.elastic.co/u/Rudy_Gevaert)\
**Post date:** [January 19, 2016, 1:40pm UTC](https://discuss.elastic.co/t/rspec-tests-for-logstash-2-1/39548/1 "2016-01-19T13:40:51Z")

</div>

Hello,

I'm trying to write a rspec test for the following filter:

```
filter {
  if [type] == "apache-access" {
    grok {
      pattern => "%{COMBINEDAPACHELOG}"
      singles => true
    }
    date {
      match => ["timestamp", "dd/MMM/yyyy:HH:mm:ss Z"]
    }
  }

```

More specifically I have trouble figuring out what to pass to the _sample_ rspec call. And how to call the insists on the function.

This doesn't work:

```
sample( { @message => '198.151.8.4 - - [29/Aug/2012:20:17:38 -0400] "GET /favicon.ico HTTP/1.1" 200 3638 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:14.0) Gecko/20100101 Firefox/14.0.1"',
            @type => 'apache-access'}
        ) do

```

However I must admit I'm new to writing rspec tests and don't know how to inspect to contents of the subject variable. So I'm guessing a lot.

I've put a gist online of a rspec test I managed to get to work.  
[https://gist.githubusercontent.com/rgevaert/3026e57f88d79bd76a14/raw/7cea69b7596dfc32117db828c8dab303a5bf5709/apache\_no\_type.rb](https://gist.githubusercontent.com/rgevaert/3026e57f88d79bd76a14/raw/7cea69b7596dfc32117db828c8dab303a5bf5709/apache_no_type.rb)

But this is the one I would like to get to work:  
[https://gist.githubusercontent.com/rgevaert/3026e57f88d79bd76a14/raw/7cea69b7596dfc32117db828c8dab303a5bf5709/apache\_type.rb](https://gist.githubusercontent.com/rgevaert/3026e57f88d79bd76a14/raw/7cea69b7596dfc32117db828c8dab303a5bf5709/apache_type.rb)

Thanks in advance,

Rudy

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [January 20, 2016, 7:28pm UTC](https://discuss.elastic.co/t/rspec-tests-for-logstash-2-1/39548/2 "2016-01-20T19:28:04Z")

</div>

Do the tests have to be rspec-based? If not and the end goal is simply to test the filters you want to use you may find [https://github.com/magnusbaeck/logstash-filter-verifier](https://github.com/magnusbaeck/logstash-filter-verifier) easier to work with.

---

<div class="post-metadata">

**Author:** ![Rudy\_Gevaert](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rudy_gevaert/32/5904_2.png) [@Rudy\_Gevaert](https://discuss.elastic.co/u/Rudy_Gevaert)\
**Post date:** [January 21, 2016, 8:19am UTC](https://discuss.elastic.co/t/rspec-tests-for-logstash-2-1/39548/3 "2016-01-21T08:19:33Z")

</div>

Hello Magnus,

Thank you for taking the time to reply to my question. This is the second post I do here, where the first one was left unanswered. So I'm happy now 😉

My tests don't need to be rspec based. Maybe it's even better to not depend on logstash specific functions for doing the tests. I also didn't like the need I had to download the plugins.

What I want to really test is the flow through logstash using the logstash version I'm running.

To be honest I didn't like I had to download logstash sources to get the tests running. Your tool looks nice. I'm going to try it because it would solve my problem.

I hope I can get it to run after I upgrade my go version (go1.1.1 linux/amd64)

rgevaert@eames:~/go$ go get [github.com/magnusbaeck/logstash-filter-verifier](http://github.com/magnusbaeck/logstash-filter-verifier)

# [github.com/magnusbaeck/logstash-filter-verifier](http://github.com/magnusbaeck/logstash-filter-verifier)

src/github.com/magnusbaeck/logstash-filter-verifier/logstash-filter-verifier.go:109: undefined: VERSION

If I don't get it to work I'll open an issue in your github project page 😉

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [January 21, 2016, 9:36pm UTC](https://discuss.elastic.co/t/rspec-tests-for-logstash-2-1/39548/4 "2016-01-21T21:36:32Z")

</div>

> If I don't get it to work I'll open an issue in your github project page

For posterity, Rudy filed [issue #1](https://github.com/magnusbaeck/logstash-filter-verifier/issues/1) which has been addressed by updating the documentation.

---

<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:** [July 6, 2017, 5:14am UTC](https://discuss.elastic.co/t/rspec-tests-for-logstash-2-1/39548/5 "2017-07-06T05:14:52Z")

</div>


