Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/r7kamura/rails_kwargs_testing

Provides Rails 5 compatible testing methods for gradual migration from Rails 4 to 5.
https://github.com/r7kamura/rails_kwargs_testing

rails

Last synced: 3 months ago
JSON representation

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

Awesome Lists containing this project

README

        

# RailsKwargsTesting

[![Gem](https://img.shields.io/gem/v/rails_kwargs_testing.svg)](https://rubygems.org/gems/rails_kwargs_testing)
[![Build Status](https://travis-ci.org/r7kamura/rails_kwargs_testing.png)](https://travis-ci.org/r7kamura/rails_kwargs_testing)

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

## Installation

Add this line to your application's Gemfile:

```ruby
gem "rails_kwargs_testing"
```

And then execute:

```bash
bundle
```

Or install it yourself as:

```ruby
gem install rails_kwargs_testing
```

## For controller tests

Prepend RailsKwargsTesting::ControllerMethods. Supported options are:

- :flash
- :format
- :params
- :session
- :xhr
- :as

### Minitest

```ruby
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

```ruby
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

```ruby
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

```ruby
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](https://opensource.org/licenses/MIT).