Skip to content

Instantly share code, notes, and snippets.

@r7kamura
Created December 18, 2018 09:09
Show Gist options
  • Save r7kamura/776988f9cf3f2d7667c778b0a9f5efde to your computer and use it in GitHub Desktop.
Save r7kamura/776988f9cf3f2d7667c778b0a9f5efde to your computer and use it in GitHub Desktop.
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'rails', '5.1.6'
end
require 'action_controller/railtie'
require 'minitest/autorun'
require 'rails/test_help'
class TestApp < Rails::Application
secrets.secret_key_base = 'secret_key_base'
::Rails.logger = ::Logger.new(nil)
routes.draw do
get '/' => 'test#index'
end
end
class TestController < ActionController::Base
include ::Rails.application.routes.url_helpers
def index
head(200)
end
end
class ControllerParamsTest < ActionController::TestCase
def setup
super
@controller = ::TestController.new
end
def test_params_with_empty_hash
get :index, params: {}
assert_equal 200, response.status
end
def test_params_with_nil
get :index, params: nil
assert_equal 200, response.status
end
end
@r7kamura
Copy link
Author

Expected

$ ruby controller_params_test.rb
Run options: --seed 8188

# Running:

..

Finished in 0.069279s, 28.8688 runs/s, 28.8688 assertions/s.
2 runs, 2 assertions, 0 failures, 0 errors, 0 skips

Actual

$ ruby controller_params_test.rb
Run options: --seed 46396

# Running:

.E

Error:
ControllerParamsTest#test_params_with_nil:
NoMethodError: undefined method `symbolize_keys' for nil:NilClass



bin/rails test controller_params_test.rb:43



Finished in 0.065820s, 30.3859 runs/s, 15.1930 assertions/s.
2 runs, 1 assertions, 0 failures, 1 errors, 0 skips

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment