RailsKwargsTesting
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
For controller tests
Prepend RailsKwargsTesting::ControllerMethods. Supported options are:
- :flash
- :format
- :params
- :session
- :xhr
- :as
Minitest
class ArticlesControllerTest < ::ActionController::TestCase
prepend ::RailsKwargsTesting::ControllerMethods
def test_create
# `post :create, name: "Hello, World!"` in Rails 4
post :create, params: { name: "Hello, World!" }
assert_equal 200, response.status
end
end
RSpec
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
For request tests
Prepend RailsKwargsTesting::RequestMethods. Supported options are:
- :env
- :headers
- :params
Minitest
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
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.