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 trialRia Carmin
Courses Plus Student 11,848 PointsDepreciation Warnings in bin/rake spec
I keep getting these depreciation warnings when I run bin/rake spec
Generally, they refer to RSpec::Core::ExampleGroup.pending
and stub_model
Does anyone know how to fix it? Are these warnings important?
Deprecation Warnings:
--------------------------------------------------------------------------------
The semantics of `RSpec::Core::ExampleGroup.pending` are changing in RSpec 3.
In RSpec 2.x, it caused the example to be skipped. In RSpec 3, the example will
still be run but is expected to fail, and will be marked as a failure (rather
than as pending) if the example passes, just like how `pending` with a block
from within an example already works.
To keep the same skip semantics, change `pending` to `skip`. Otherwise, if you
want the new RSpec 3 behavior, you can safely ignore this warning and continue
to upgrade to RSpec 3 without addressing it.
Called from /home/treehouse/projects/odot/spec/helpers/todo_lists_helper_spec.rb:14:in `block in <top (required)>'.
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
The semantics of `RSpec::Core::ExampleGroup.pending` are changing in RSpec 3.
In RSpec 2.x, it caused the example to be skipped. In RSpec 3, the example will
still be run but is expected to fail, and will be marked as a failure (rather
than as pending) if the example passes, just like how `pending` with a block
from within an example already works.
To keep the same skip semantics, change `pending` to `skip`. Otherwise, if you
want the new RSpec 3 behavior, you can safely ignore this warning and continue
to upgrade to RSpec 3 without addressing it.
Called from /home/treehouse/projects/odot/spec/models/todo_list_spec.rb:4:in `block in <top (required)>'.
--------------------------------------------------------------------------------
`stub_model` is deprecated. Use the `rspec-activemodel-mocks` gem instead. Called from /home/treehouse/projects/odot/spec/views/todo_lists/edit.html.erb_spec.rb:5:in `block (2 levels) in <top (required)>'.
`stub_model` is deprecated. Use the `rspec-activemodel-mocks` gem instead. Called from /home/treehouse/projects/odot/spec/views/todo_lists/show.html.erb_spec.rb:5:in `block (2 levels) in <top (required)>'.
`stub_model` is deprecated. Use the `rspec-activemodel-mocks` gem instead. Called from /home/treehouse/projects/odot/spec/views/todo_lists/new.html.erb_spec.rb:5:in `block (2 levels) in <top (required)>'.
Too many uses of deprecated '`stub_model`'. Pass `--deprecation-out` or set `config.deprecation_stream` to a file for full output.
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.
7 deprecation warnings total
Finished in 2.48 seconds
37 examples, 0 failures, 2 pending
4 Answers
Sebastian Velandia
24,676 PointsOk I fixed it just doing the following: in my Gemfile just added these gems
# Support for its syntax
gem 'rspec-its', '~> 1.0.1’
# Support for stubbing model in view specs:
gem 'rspec-activemodel-mocks', '~> 1.0.1'
then in the spec_helper.rb I just added
config.raise_errors_for_deprecations!
After that I just upgrade to rspec 3.0, capybara to 2.3 and rspec-expectations to 3.0, changed the version of rspec in my Gemfile
gem 'rspec-rails', '~> 3.0.0'
gem 'rspec-expectations', '~> 3.0.0'
gem 'capybara', '~> 2.3.0'
then I ran a bundle update, just typing "bundle" in the command line
then the last step was add these lines to my spec_helper.rb into the RSpec.configure block
config.mock_with :rspec do |c|
c.syntax = [:should, :expect]
end
config.expect_with :rspec do |c|
c.syntax = [:should, :expect]
end
After that all the tests are runnign successfully without any warnings. Thanks
Aurelien Schlumberger
6,127 PointsThe depreciation warnings won't hinder on your application, but they do become annoying when they start clogging your terminal.
Make sure to read the depreciation warning (in your case replacing the method pending with the method skip)
I suggest you read the Rspec upgrade docs as they explain on how to upgrade Rspec and what to do with the depreciation warnings. https://relishapp.com/rspec/docs/upgrade
Also when you have depreciation warnings, it usually suggests that a method will disappear or be replaced with something else. It can become a problem when you upgrade a gem that has/had dependencies with these methods. Usually when you do bundle update your gemlist it will update all your gems and the most popular gems developers work hard on making sure that the dependencies are up to date.
As I recall, Rails 4 created a lot of problems with dependencies during its launch with many popular gems like simple_form or the twitter bootstrap gem. It is sometimes better to stay on an older version, and in my most recent application, I am still working with Rails 3 because of missing dependencies.
Ria Carmin
Courses Plus Student 11,848 PointsThanks a lot, Aurelien!
gusf
11,070 PointsHow can i fix this 4 failures without having to update/upgrade any gems?
Failed examples:
rspec ./spec/views/todo_lists/show.html.erb_spec.rb:11 # todo_lists/show renders attributes in
rspec ./spec/views/todo_lists/index.html.erb_spec.rb:17 # todo_lists/index renders a list of todo_lists
rspec ./spec/views/todo_lists/edit.html.erb_spec.rb:11 # todo_lists/edit renders the edit todo_list form
rspec ./spec/views/todo_lists/new.html.erb_spec.rb:11 # todo_lists/new renders new todo_list form
Anyone knows what method should disappear or be replaced in order to fix this issues?
Thanx
Fenian Noakes
Courses Plus Student 5,212 PointsHi - experienced the same issue as Ria(above), then followed the instructions as indicated by Sebastian for the suggested work around/fix. I then again ran $bin/rake spec I then get; ./spec/views/todo_lists/show.html.erb_spec.rb failed
not sure where to go from there... any suggestions would be really appreciated. thanks
Kim Setili
12,419 PointsKim Setili
12,419 PointsThis worked wonderfully! It's exactly what I was looking for.
David Clausen
11,403 PointsDavid Clausen
11,403 PointsPerfect, this fixed it. Reading the warning and searching online this was the proper way to handle it. Updated the package as recommended by the log warnings. Added the :should as suggested by log warnings after upgrade.
Thanks a lot for doing the leg work on this!
Geoffrey Emerson
18,726 PointsGeoffrey Emerson
18,726 PointsI had to run
bundle update
to get bundler to resolve the conflicts from scratch, but otherwise this worked.Also, I did not need the
config.raise_errors_for_deprecations!
line.David Clausen
11,403 PointsDavid Clausen
11,403 PointsI actually change my mind. Upgrading rspec to 3 is completely different way they name their helper file and their header in each test.
Next time you generate new test it will throw errors.
I found changing pending to skip worked, and there was another depreciation warning that I followed the instructions to fix.
Upgrading rspec 2 to 3 will cause other issues. Just a warning.