# Logstash Rspec Encoding as US-ASCII

**URL:** <https://discuss.elastic.co/t/logstash-rspec-encoding-as-us-ascii/81112>\
**Category:** Logstash\
**Created:** [April 4, 2017, 9:44am UTC](https://discuss.elastic.co/t/logstash-rspec-encoding-as-us-ascii/81112 "2017-04-04T09:44:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Conall\_Prendergast](https://avatars.discourse-cdn.com/v4/letter/c/d26b3c/32.png) [@Conall\_Prendergast](https://discuss.elastic.co/u/Conall_Prendergast)\
**Post date:** [April 4, 2017, 9:44am UTC](https://discuss.elastic.co/t/logstash-rspec-encoding-as-us-ascii/81112/1 "2017-04-04T09:44:33Z")

</div>

Hi,

I am running an Rspec test case which takes in some json files and matches them against an expected output after being put through my filter.

However, I am getting an error during the validate\_valie phase where it is complaining that US-ASCII is being used, instead of UTF-8, even though US-ASCII is a subset of UTF-8.

Any suggestions as to how I can force the encoding?

Thanks

Below is the stack trace I am getting

```
 RuntimeError:
       expected UTF-8 encoding for value=Paid Aggregator, encoding=#<Encoding:US-ASCII>
     # /usr/local/rvm/gems/jruby-1.7.26/gems/logstash-core-event-2.4.1-java/lib/logstash/event.rb:226:in `validate_value'
     # /usr/local/rvm/gems/jruby-1.7.26/gems/logstash-core-event-2.4.1-java/lib/logstash/event.rb:230:in `validate_value'
     # /usr/local/rvm/gems/jruby-1.7.26/gems/logstash-core-event-2.4.1-java/lib/logstash/event.rb:230:in `validate_value'
     # /usr/local/rvm/gems/jruby-1.7.26/gems/logstash-devutils-0.0.22-java/lib/logstash/devutils/rspec/spec_helper.rb:43:in `[]='
     # /usr/local/rvm/gems/jruby-1.7.26/gems/logstash-core-2.4.1-java/lib/logstash/util/decorators.rb:46:in `add_tags'
     # /usr/local/rvm/gems/jruby-1.7.26/gems/logstash-core-2.4.1-java/lib/logstash/util/decorators.rb:38:in `add_tags'
     # /usr/local/rvm/gems/jruby-1.7.26/gems/logstash-core-2.4.1-java/lib/logstash/filters/base.rb:180:in `filter_matched'
     # /usr/local/rvm/gems/jruby-1.7.26/gems/logstash-filter-grok-2.0.5/lib/logstash/filters/grok.rb:287:in `filter'
     # /usr/local/rvm/gems/jruby-1.7.26/gems/logstash-core-2.4.1-java/lib/logstash/filters/base.rb:151:in `multi_filter'
     # /usr/local/rvm/gems/jruby-1.7.26/gems/logstash-core-2.4.1-java/lib/logstash/filters/base.rb:148:in `multi_filter'
     # (eval):3950:in `initialize'
     # (eval):3943:in `initialize'
     # (eval):3964:in `initialize'
     # (eval):3961:in `initialize'
     # (eval):4008:in `initialize'
     # (eval):3989:in `initialize'
     # (eval):1176:in `filter_func'
     # /usr/local/rvm/gems/jruby-1.7.26/gems/logstash-core-2.4.1-java/lib/logstash/pipeline.rb:425:in `filter'
     # /usr/local/rvm/gems/jruby-1.7.26/gems/logstash-devutils-0.0.22-java/lib/logstash/devutils/rspec/logstash_helpers.rb:49:in `results'
     # /usr/local/rvm/gems/jruby-1.7.26/gems/logstash-devutils-0.0.22-java/lib/logstash/devutils/rspec/logstash_helpers.rb:47:in `results'
     # ./spec/spec_helper.rb:50:in `run_case'
     # /usr/local/rvm/gems/jruby-1.7.26/gems/rspec-wait-0.0.9/lib/rspec/wait.rb:46:in `(root)'
```

---

<div class="post-metadata">

**Author:** ![Conall\_Prendergast](https://avatars.discourse-cdn.com/v4/letter/c/d26b3c/32.png) [@Conall\_Prendergast](https://discuss.elastic.co/u/Conall_Prendergast)\
**Post date:** [April 4, 2017, 10:04pm UTC](https://discuss.elastic.co/t/logstash-rspec-encoding-as-us-ascii/81112/2 "2017-04-04T22:04:46Z")

</div>

Got this. The solution is to use the "magic\_encoding" gem

---

<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:** [May 2, 2017, 10:04pm UTC](https://discuss.elastic.co/t/logstash-rspec-encoding-as-us-ascii/81112/3 "2017-05-02T22:04:55Z")

</div>

Closed on May 2, 2017, 10:04pm UTC

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