RailsKwargsTesting

Gem Build Status

Provides Rails 5 compatible testing methods for gradual migration from Rails 4 to 5.

Installation

Add this line to your application's Gemfile:

gem "rails_kwargs_testing"

And then execute:

bundle

Or install it yourself as:

gem install rails_kwargs_testing

Minitest

ActionController::TestCase

class ArticlesControllerTest < ::ActionController::TestCase
  prepend ::RailsKwargsTesting::ControllerMethods

  def test_create
    post :create, params: { name: "Hello, World!" }
    assert_equal 200, response.status
  end
end

ActionDispatch::IntegrationTest

class CreateArticleTest < ActionDispatch::IntegrationTest
  prepend ::RailsKwargsTesting::RequestMethods

  def test_create_article
    # `post "/articles", name: "Hello, World!"` in Rails 4
    post "/articles", params: { name: "Hello, World!" }
    assert_equal 200, response.status
  end
end

RSpec

Controller-specs

RSpec.describe ArticlesController do
  prepend RailsKwargsTesting::ControllerMethods

  describe "#create" do
    subject do
      # `post :create, name: "Hello, World!"` in Rails 4
      post :create, params: { name: "Hello, World!" }
    end

    it { is_expected.to eq 200 }
  end
end

Request-specs

RSpec.describe "POST /articles" do
  prepend RailsKwargsTesting::RequestMethods

  subject do
    # `post "/articles", name: "Hello, World!"` in Rails 4
    post "/articles", params: { name: "Hello, World!" }
  end

  it { is_expected.to eq 200 }
end

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/r7kamura/rails_kwargs_testing.

License

The gem is available as open source under the terms of the MIT License.