small medium large xlarge

11 Apr 2016, 11:56
Patrício João dos Santos (7 posts)

I start read this book yesterday, end to follow it, I am using the Ruby 2.3.0, Rails 5.0.0.beta3 and RSpec 3.5.0.beta3

On chapter 3 , section “Who Controls the Controller”, we write the following test:

# spec/controllers/projects_controller_spec.rb
require 'rails_helper'

RSpec.describe ProjectsController, type: :controller do
  describe "POST create" do
    it "creates a project" do
      post :create, project: {name: "Runway", tasks: "Start something:2"}
      expect(response).to redirect_to(projects_path)
      expect(assigns(:action) eq("Runway")

First time I run this spec, gives the following error:

1) ProjectsController POST create creates a project Failure/Error: expect(assigns(:action) eq(“Runway”)

  assigns has been extracted to a gem. To continue using it,
          add `gem 'rails-controller-testing'` to your Gemfile.
# ./spec/controllers/projects_controller_spec.rb:9:in `block (3 levels) in <top (required)>' 

As the error suggested, I added the gem rails-controller-testing and the error goes away. But another one comes. Is not a error, but a deprecation warning:

ProjectsController POST create DEPRECATION WARNING: ActionController::TestCase HTTP request methods will accept only keyword arguments in future Rails versions.


get :show, params: { id: 1 }, session: { user_id: 1 } …

To solve this, I changed the following code:

post :create, project: { name: "Runway", tasks: "Start something:2" }

to this one:

post :create, params: { project: { name: "Runway", tasks: "Start something:2" } }


Patrício dos Santos