Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Benjamin Flores
Benjamin Flores
3,297 Points

Failing one test, don't know how to fix it

Hello!

I'm following the rails videos, and just created my scaffold for a new rails app.. cool. I was then prompted to do bin/rake spec and it gave me 12 errors! Through some googling, I narrowed it down to one.. and this last one I don't know how to fix.

Underneath I am including what my terminal gives me.

1) TodoListsController PUT update with valid params updates the requested todo_list Failure/Error: if @todo_list.update(todo_list_params)

   #<TodoList id: 1, title: "MyString", description: nil, created_at: "2016-07-09 20:03:27", updated_at: "2016-07-09 20:03:27"> received :update with unexpected arguments
     expected: ({"title"=>"MyString"})
          got: (<ActionController::Parameters {"title"=>"MyString"} permitted: true>)
   Diff:
   @@ -1,2 +1,2 @@
   -[{"title"=>"MyString"}]
   +[<ActionController::Parameters {"title"=>"MyString"} permitted: true>]

 # ./app/controllers/todo_lists_controller.rb:44:in `block in update'
 # ./app/controllers/todo_lists_controller.rb:43:in `update'
 # ./spec/controllers/todo_lists_controller_spec.rb:110:in `block (4 levels) in <top (required)>'

Deprecation Warnings:

Requiring rspec/autorun when running RSpec via the rspec command is deprecated. Called from /Users/benjaminflores/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:293:in `require'.

Using any_instance from rspec-mocks' old :should syntax without explicitly enabling the syntax is deprecated. Use the new :expect syntax or explicitly enable :should instead. Called from /Users/benjaminflores/treehouse/projects/odot/spec/controllers/todo_lists_controller_spec.rb:87:in `block (4 levels) in <top (required)>'.

Using should from rspec-expectations' old :should syntax without explicitly enabling the syntax is deprecated. Use the new :expect syntax or explicitly enable :should with config.expect_with(:rspec) { |c| c.syntax = :should } instead. Called from /Users/benjaminflores/treehouse/projects/odot/spec/routing/todo_lists_routing_spec.rb:15:in `block (3 levels) in <top (required)>'.

If you need more of the backtrace for any of these deprecations to identify where to make the necessary changes, you can configure config.raise_errors_for_deprecations!, and it will turn the deprecation warnings into errors, giving you the full backtrace.

3 deprecation warnings total

Finished in 0.5833 seconds (files took 2.16 seconds to load) 30 examples, 1 failure, 2 pending

Failed examples:

rspec ./spec/controllers/todo_lists_controller_spec.rb:103 # TodoListsController PUT update with valid params updates the requested todo_list

Randomized with seed 37019

/Users/benjaminflores/.rbenv/versions/2.2.2/bin/ruby -I/Users/benjaminflores/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.1/lib:/Users/benjaminflores/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-support-3.5.0/lib /Users/benjaminflores/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.1/exe/rspec --pattern spec/**{,/*/**}/*_spec.rb failed

Vlad Filiucov
Vlad Filiucov
10,665 Points

would be usefull if you included your update action and strong parameters. What version of rails are you using?

1 Answer

Sérgio Haruo Hattori
Sérgio Haruo Hattori
5,867 Points

I was having this trouble too!

I fixed by changing the following line on spec->controllers->todo_lists_controller_spec.rb I think the original method "any_instance" depracated, the error log suggest something to solve it but it didn´t work out. I found this answer on StackOverflow. ( link )

describe "PUT update" do
    describe "with valid params" do
      it "updates the requested todo_list" do
        todo_list = TodoList.create! valid_attributes
        # Assuming there are no other todo_lists in the database, this
        # specifies that the TodoList created on the previous line
        # receives the :update_attributes message with whatever params are
        # submitted in the request.

       #THE LINE BELOW WITH THE ALLOW_ANY_INSTANCE_OF WAS CHANGED
      allow_any_instance_of(TodoList).to receive(:update).and_return({ "title" => "MyString" }) 


        put :update, {:id => todo_list.to_param, :todo_list => { "title" => "MyString" }}, valid_session
      end
Nelly Nelly
Nelly Nelly
7,134 Points

Thanks !That's helpful ! And for the others who would have the same problem, do not forget to run your test several times then you won't miss a line to change :)