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
Michelle Cannito
8,992 Points'stub_model' is deprecated after bin/rake spec
Course: Build a Todo List Application with Rails 4
Stage: 1
Video: Write Our First Tests
Command: bin/rake spec
Result on video:
No warnings; final shows 0 failures and 2 pending
Result when I do it:
'stub_model' is deprecated.
Use the 'rspec-activemodel-mocks' gem instead. ...
Too many uses of deprecated 'stub_model'.
Pass '--deprecation-out' or set 'config.deprecation_stream' to a file for full output. ...
9 deprecation warnings total
...
...0 failures, 2 pending
Questions:
Should I ignore warnings and carry on?
How would one use the 'rspec-activemodel-mocks' gem instead?
Will staff add Instructor Notes below the video for others who encounter this problem?
Sebastian Velandia
24,676 PointsYes same here, I still do not find the asnwer how to solve this
3 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
jay niceness
7,406 PointsHi Sebastian, did you add all the rspec gems under the gemfile group :development, :test section? i.e
group :development, :test do gem 'rspec-rails', '~> 3.0.0' gem 'rspec-its', '~> 1.0.1â' gem 'rspec-activemodel-mocks', '~> 1.0.1' gem 'rspec-expectations', '~> 3.0.0'
end ? thanks
Sebastian Velandia
24,676 PointsYes you can do it in your dev group or in your test group or both, the result is going to be the same.
marjlawson
11,166 PointsThank you so much for this, I've been struggling for hours trying to fix these errors!
Cena Mayo
55,236 PointsThis is what my spec_helper.rb looks like after some digging around about the deprecation errors. I also updated my Gemfile to use the most recent versions of everything, which is probably bad practice but everything's now working. Note in particular that require 'rspec/autorun' is commented out, and the config.mock block at the end of the file.
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
#require 'rspec/autorun'
require 'capybara/rspec'
# Requires supporting ruby files with custom matchers and macros, etc, in
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
# run as spec files by default. This means that files in spec/support that end
# in _spec.rb will both be required and run as specs, causing the specs to be
# run twice. It is recommended that you do not name files matching this glob to
# end with _spec.rb. You can configure this pattern with with the --pattern
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
# Checks for pending migrations before tests are run.
# If you are not using ActiveRecord, you can remove this line.
ActiveRecord::Migration.maintain_test_schema!
RSpec.configure do |config|
# ## Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = true
# If true, the base class of anonymous controllers will be inferred
# automatically. This will be the default behavior in future versions of
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = false
# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = "random"
# RSpec Rails can automatically mix in different behaviours to your tests
# based on their file location, for example enabling you to call `get` and
# `post` in specs under `spec/controllers`.
#
# You can disable this behaviour by removing the line below, and instead
# explictly tag your specs with their type, e.g.:
#
# describe UsersController, :type => :controller do
# # ...
# end
#
# The different available types are documented in the features, such as in
# https://relishapp.com/rspec/rspec-rails/v/3-0/docs
config.infer_spec_type_from_file_location!
config.mock_with :rspec do |c|
c.syntax = [:should, :expect]
end
config.expect_with :rspec do |c|
c.syntax = [:should, :expect]
end
end
jorge martinez
2,294 Pointsjorge martinez
2,294 PointsI got the same thing.. how did you solve it ? thanks!