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 trialAlan Khoury
6,127 PointsHow do i removed these depreciation warnings?
when i run bin/rspec spec/features/todo_lists/edit_spec.rb
i get
.....
Deprecation Warnings:
RSpec::Core::ExampleGroup#example is deprecated and will be removed in RSpec 3. There are a few options for what you can use instead:
- rspec-core's DSL methods (
it
,before
,after
,let
,subject
, etc) now yield the example as a block argument, and that is the recommended way to access the current example from those contexts. - The current example is now exposed via
RSpec.current_example
, which is accessible from any context. -
If you can't update the code at this call site (e.g. because it is in an extension gem), you can use this snippet to continue making this method available in RSpec 2.99 and RSpec 3:
RSpec.configure do |c| c.expose_current_running_example_as :example end
(Called from /Users/myusername/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/capybara-2.1.0/lib/capybara/rspec.rb:20:in `block (2 levels) in <top (required)>')
RSpec::Core::ExampleGroup#example is deprecated and will be removed in RSpec 3. There are a few options for what you can use instead:
- rspec-core's DSL methods (
it
,before
,after
,let
,subject
, etc) now yield the example as a block argument, and that is the recommended way to access the current example from those contexts. - The current example is now exposed via
RSpec.current_example
, which is accessible from any context. -
If you can't update the code at this call site (e.g. because it is in an extension gem), you can use this snippet to continue making this method available in RSpec 2.99 and RSpec 3:
RSpec.configure do |c| c.expose_current_running_example_as :example end
(Called from /Users/myusername/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/capybara-2.1.0/lib/capybara/rspec.rb:21:in `block (2 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.
2 deprecation warnings total
Finished in 0.17866 seconds 5 examples, 0 failures
Randomized with seed 38251
What is it all about and what do i do to get rid of it? Thanks!
15 Answers
Anna Petry
14,474 PointsI was getting those deprecation errors, too, and the snippet posted above by Jayphen Simpson worked for me. I was also getting the following deprecation error:
rspec-rails 3 will no longer automatically infer an example group's spec type
from the file location. You can explicitly opt-in to this feature using this
snippet:
RSpec.configure do |config|
config.infer_spec_type_from_file_location!
end
If you wish to manually label spec types via metadata you can safely ignore
this warning and continue upgrading to RSpec 3 without addressing it.
Seems obvious, but I added the config.infer_spec_type_from_file_location!
snippet from the error message to the spec_helper.rb
file (within the 'RSpec configure do' block) and the final deprecation error went away.
Hope that might help someone.
Jayphen Simpson
1,294 PointsI'm not really sure why they're happening (it's related to rspec 2.99), but you can get rid of them by adding the following to spec_helper.rb
config.expose_current_running_example_as :example
Mark Railton
8,468 PointsPerfect, this was exactly what I was looking for.
Kelvin Knighton
6,168 Pointsworked for me, thanks jay
Michelle Cannito
8,992 PointsWow, it worked! I was happy when I could run rspec without being in the bin subdirectory. I was thrilled when I got rid of the LoadError I was struggling with for two days. And now I am in a zen-like state that the run output is both correct and uncluttered. Coding is so cool. Thank you so much.
Alejandro Ñáñez Ortiz
21,184 PointsWorked like charm.
Timothy McCune
6,744 PointsPerfect. Thanks for the fix. It worked.
Steven Hicks
14,946 PointsAdding this bit to spec_helper.rb also helped me! Thanks a bunch!
Dylan Shine
17,565 Pointsrequire 'spec_helper'
# Specs in this file have access to a helper object that includes
# the TodoListsHelper. For example:
#
# describe TodoListsHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# expect(helper.concat_strings("this","that")).to eq("this that")
# end
# end
# end
describe TodoListsHelper do
pending "add some examples to (or delete) #{__FILE__}"
end
RSpec.configure do |config|
config.expose_current_running_example_as :example
config.raise_errors_for_deprecations!
end
Still getting the errors, can you help me?
Crisoforo Gaspar Hernández
18,302 PointsThe answer:
expose_current_running_example_as :example
config option is meant to support users who are using gems that depend on the RSpec 2 API. It's not meant for library authors to use.
The source if you wan to check more.
Fábio Tavares da Costa
11,985 PointsCool!
It continues to work as Jul, 14, 2015.
I passed the following snippet at very end of odot/spec/spec_helper.rb
. The log suggests a slightly different notation, so I used the following:
RSpec.configure do |c|
# RSpec::Core::ExampleGroup#example is deprecated and will be removed in RSpec 3.
# [...] snippet to continue making this method available in RSpec 2.99 and RSpec 3:
c.expose_current_running_example_as :example
end
# VM spec
# uname --all
# Linux treehouse 3.8.0-33-generic #48~precise1-Ubuntu SMP Thu Oct 24 16:31:16 UTC 2013 i686 i686 i386 GNU/Linux
Everything works with a clean log after the addition.
treehouse:~/projects/odot (master *) $ bin/rspec spec/features/todo_lists/create_spec.rb
..
Finished in 0.44521 seconds
2 examples, 0 failures
Randomized with seed 1999
Cheers!
gmyauabalb
3,268 PointsThis fixed issue for me! Thank you, that crazy long message was annoying... Cheers!
Fábio Tavares da Costa
11,985 PointsMy pleasure Jacquelyn.
Cheers!
Louis Magnotti
4,402 PointsBy running this command, it exposes the current running example via the named helper method. Since we're using extension gem Capybara in this tutorial, this config option is used to maintain compatibility between different versions of Rspec.
Mike Nagle
4,266 PointsThere's some more information about depreciation warnings on upgrading to rspec3 here: http://rspec.info/upgrading-from-rspec-2/
I used the transpec tool to remove 7 warnings and the last two by adding the config line above
Jonathan Chua
4,136 PointsThe answer string on this question is a little convoluted. The specific solution seems to depend on the exact depreciation error that comes up and what the code in your odot/spec/spec_helper.rb file looks like.
If you see this:
rspec-rails 3 will no longer automatically infer an example group's spec type
from the file location. You can explicitly opt-in to this feature using this
snippet:
RSpec.configure do |config|
config.infer_spec_type_from_file_location!
end
then add this to the Rspec.configure do |config| block just above the line that contains end.
config.infer_spec_type_from_file_location!
My spec_helper.rb file already contained that line of code. My depreciation warning looked like this:
RSpec::Core::ExampleGroup#example is deprecated and will be removed
in RSpec 3. There are a few options for what you can use instead:
- rspec-core's DSL methods (`it`, `before`, `after`, `let`, `subject`, etc)
now yield the example as a block argument, and that is the recommended
way to access the current example from those contexts.
- The current example is now exposed via `RSpec.current_example`,
which is accessible from any context.
- If you can't update the code at this call site (e.g. because it is in
an extension gem), you can use this snippet to continue making this
method available in RSpec 2.99 and RSpec 3:
RSpec.configure do |c|
c.expose_current_running_example_as :example
end
The solution is to add this to the Rspec.configure do |c| block just above the line that contains end.
c.expose_current_running_example_as :example
However, my spec_helper.rb file does not contain a Rspec.configure do |c| block. Instead it has Rspec.configure do |config|.
In this case, the solution is to add this to the Rspec.configure do |config| block just above the line that contains end.
config.expose_current_running_example_as :example
What are deprecation warnings and why do these code snippets make them go away?
A depreciation warning tells you that in the next version of the software something will not work the way that it is working now in the current version. Adding these snippets explicitly tells rspec to continue behaving the same if and when you upgrade it to the next version. If a depreciation warning is ignored and the software is upgraded it will probably break your code and you'll have to rewrite a bunch of it to make it work again.
Sara Greer
16,032 PointsThank you for summing everything up, Jonathan!
Alan Khoury
6,127 PointsThanks!
Jason Data
6,355 PointsDoes anyone want to explain why and how this works? :)
David Eichel
28,860 PointsI would also like an explanation as to what's happening here. Thanks.
Richard Duffy
16,488 PointsThank you for this, it worked!
ogechi1
14,455 PointsThank you for the tip, worked like a charm!
Chris Blackmon
Courses Plus Student 8,769 PointsThanks a million for this :)
Owen Tran
6,822 PointsI had identical message.
I added : config.expose_current_running_example_as :example
to the spec_helper.rb
inside the RSpec.configure do |config| block at the bottom just before end.
Luke Van Lathum
462 PointsI had a larger message and I simply added
RSpec.configure do |c| c.expose_current_running_example_as :example end
to the spec_helper.rb file in the spec folder :)
Mahmud Rahman
10,011 PointsThanks it was big help
Wendel Ferreira
4,258 PointsWendel Ferreira
4,258 PointsWorked just fine, if only I have looked into the alert code first! Thanks!
Jamie Goodwin
14,251 PointsJamie Goodwin
14,251 PointsThank you, this totally sorted it for me as well. Legendary.