Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rspec feature | NoMethodError: undefined method `split' for nil:NilClass #19

zeknox opened this issue Nov 18, 2017 · 3 comments


None yet
3 participants
Copy link

commented Nov 18, 2017

Hi All-

I'm trying to write a feature spec to test my email_processor.rb to simulate an email message being sent via HTTP POST request. My sample rspec looks like below:

require 'rails_helper'

RSpec.feature "EmailProcessors", type: :feature do
  def email_params
      headers: 'Received: by with SMTP...',
      to: 'thoughtbot <>',
      cc: 'CC <>',
      from: 'John Doe <>',
      subject: 'hello there',
      text: 'this is an email message',
      html: '<p>this is an email message</p>',
      charsets: '{"to":"UTF-8","html":"ISO-8859-1","subject":"UTF-8","from":"UTF-8","text":"ISO-8859-1"}',
      SPF: "pass"

  it 'POST new Email message' do
    # visit email_processor_path, params: email_params)
    page.driver.status_code.should eql 200

When trying to test this spec it will throw the following error as seen below. NoMethodError: undefined method `split' for nil:NilClass

  POST new Email message (FAILED - 1)


  1) EmailProcessors POST new Email message
     Failure/Error:, params: email_params)
       undefined method `split' for nil:NilClass
     # /Users/user/.rvm/gems/ruby-2.3.1/gems/griddler-mailgun-1.0.3/lib/griddler/mailgun/adapter.rb:39:in `to_recipients'
     # /Users/user/.rvm/gems/ruby-2.3.1/gems/griddler-mailgun-1.0.3/lib/griddler/mailgun/adapter.rb:17:in `normalize_params'
     # /Users/user/.rvm/gems/ruby-2.3.1/gems/griddler-mailgun-1.0.3/lib/griddler/mailgun/adapter.rb:12:in `normalize_params'
     # /Users/user/.rvm/gems/ruby-2.3.1/gems/griddler-1.4.0/app/controllers/griddler/emails_controller.rb:17:in `normalized_params'
     # /Users/user/.rvm/gems/ruby-2.3.1/gems/griddler-1.4.0/app/controllers/griddler/emails_controller.rb:3:in `create'
     # /Users/user/.rvm/gems/ruby-2.3.1/gems/warden-1.2.7/lib/warden/manager.rb:36:in `block in call'
     # /Users/user/.rvm/gems/ruby-2.3.1/gems/warden-1.2.7/lib/warden/manager.rb:35:in `catch'
     # /Users/user/.rvm/gems/ruby-2.3.1/gems/warden-1.2.7/lib/warden/manager.rb:35:in `call'
     # /Users/user/.rvm/gems/ruby-2.3.1/gems/rack-1.6.8/lib/rack/etag.rb:24:in `call'
     # /Users/user/.rvm/gems/ruby-2.3.1/gems/rack-1.6.8/lib/rack/conditionalget.rb:38:in `call'
     # /Users/user/.rvm/gems/ruby-2.3.1/gems/rack-1.6.8/lib/rack/head.rb:13:in `call'
     # /Users/user/.rvm/gems/ruby-2.3.1/gems/rack-1.6.8/lib/rack/session/abstract/id.rb:225:in `context'
     # /Users/user/.rvm/gems/ruby-2.3.1/gems/rack-1.6.8/lib/rack/session/abstract/id.rb:220:in `call'
     # /Users/user/.rvm/gems/ruby-2.3.1/gems/railties-4.2.4/lib/rails/rack/logger.rb:38:in `call_app'
     # /Users/user/.rvm/gems/ruby-2.3.1/gems/railties-4.2.4/lib/rails/rack/logger.rb:20:in `block in call'
     # /Users/user/.rvm/gems/ruby-2.3.1/gems/railties-4.2.4/lib/rails/rack/logger.rb:20:in `call'
     # /Users/user/.rvm/gems/ruby-2.3.1/gems/request_store-1.3.1/lib/request_store/middleware.rb:9:in `call'
     # /Users/user/.rvm/gems/ruby-2.3.1/gems/rack-1.6.8/lib/rack/methodoverride.rb:22:in `call'
     # /Users/user/.rvm/gems/ruby-2.3.1/gems/rack-1.6.8/lib/rack/runtime.rb:18:in `call'
     # /Users/user/.rvm/gems/ruby-2.3.1/gems/rack-1.6.8/lib/rack/lock.rb:17:in `call'
     # /Users/user/.rvm/gems/ruby-2.3.1/gems/rack-1.6.8/lib/rack/sendfile.rb:113:in `call'
     # /Users/user/.rvm/gems/ruby-2.3.1/gems/railties-4.2.4/lib/rails/engine.rb:518:in `call'
     # /Users/user/.rvm/gems/ruby-2.3.1/gems/railties-4.2.4/lib/rails/application.rb:165:in `call'
     # /Users/user/.rvm/gems/ruby-2.3.1/gems/rack-1.6.8/lib/rack/urlmap.rb:66:in `block in call'
     # /Users/user/.rvm/gems/ruby-2.3.1/gems/rack-1.6.8/lib/rack/urlmap.rb:50:in `each'
     # /Users/user/.rvm/gems/ruby-2.3.1/gems/rack-1.6.8/lib/rack/urlmap.rb:50:in `call'
     # /Users/user/.rvm/gems/ruby-2.3.1/gems/rack-test-0.6.3/lib/rack/mock_session.rb:30:in `request'
     # /Users/user/.rvm/gems/ruby-2.3.1/gems/rack-test-0.6.3/lib/rack/test.rb:244:in `process_request'
     # /Users/user/.rvm/gems/ruby-2.3.1/gems/rack-test-0.6.3/lib/rack/test.rb:67:in `post'
     # /Users/user/.rvm/gems/ruby-2.3.1/gems/capybara-2.16.0/lib/capybara/rack_test/driver.rb:101:in `post'
     # ./spec/features/email_processors_spec.rb:20:in `block (2 levels) in <top (required)>'

Finished in 0.18955 seconds (files took 11.33 seconds to load)
1 example, 1 failure

Failed examples:

rspec ./spec/features/email_processors_spec.rb:18 # EmailProcessors POST new Email message


gem 'griddler-mailgun'


    griddler (1.4.0)
      rails (>= 3.2.0)
    griddler-mailgun (1.0.3)

Any advice what I might be doing wrong or how to effectively test the email_processor.rb would be much appreciated. Cheers.


This comment has been minimized.

Copy link

commented Jun 8, 2019

Hey @zeknox, I just ran into a similar problem. Digging through the source code revealed that the griddler-mailgun gem expects the params to be formatted very specifically.

Here's the relevant params you provided:

headers: 'Received: by with SMTP...',
to: 'thoughtbot <>',
cc: 'CC <>',
from: 'John Doe <>',

Here's the keys griddler-mailgun expects:

headers: '...',
"To" => 'thoughtbot <>,
"Cc" => 'CC <',


To be explicit, the to, from, cc and bcc fields all expect capitalized values.

You can explore exactly what keys are expected and how they ought to be formatted here:

I spent a while wrestling with this exact same problem. I'll have a PR in to update the README, or maybe raise a specific error, depending on @bradpauly's preference.

For now, I wanted to document this for others who might come here experiencing the same problem.


This comment has been minimized.

Copy link

commented Jun 26, 2019

I think I found the answer of the internet standards for field capitalization.


Verbs and argument values (e.g., "TO:" or "to:" in the RCPT command and extension name keywords) are not case sensitive, with the sole exception in this specification of a mailbox local-part (SMTP Extensions may explicitly specify case-sensitive elements)

The "mailbox local-part" would be smith in; RFC281 says that is distinct from, but goes on to say

However, exploiting the case sensitivity of mailbox local-parts impedes interoperability and is discouraged.

Ah. RFC 822, section 3.4.7 CASE INDEPENDENCE:

Except as noted, alphabetic strings may be represented in any combination of upper and lower case.

When matching any other syntactic unit, case is to be ignored. For example, the field-names "From", "FROM", "from", and even "FroM" are semantically equal and should all be treated identically.

To that end, I'll open up a PR that makes the keys case-insensitive.


This comment has been minimized.

Copy link

commented Jun 26, 2019

@josh-works sorry I haven't gotten to this yet and thanks for the update. I'll be able to give it some attention next week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.