When trying to run rspec, I get uninitialized constant ActiveModel
Why are you running rspec spec
? The typical thing to run is rake spec
.
Try bundle exec rspec spec
or bundle exec rake spec
.
If that doesn't work, try to see if something is wrong with the rest of your environment -- try bundle exec rails console
and bundle exec rails server
Another thing to check, is there anything odd in .rspec in your project file, or ~/.rspec?
Rspec uninitialized constant ActiveRecord(NameError)
I think the tutorial might be trying to transition from using RSpec on a plain Ruby object to using the rspec-rails
gem on an ActiveRecord object. For the examples that use rspec-rails
, you should have a model in the file app/models/zombie.rb
. This is what the spec in spec/models/zombie_spec.rb
will look for. Also, your specs will need to require rails_helper
rather than spec_helper
.
# app/models/zombie.rb
class Zombie < ActiveRecord::Base
validates :name, presence: true
def hungry?
true
end
end
# spec/models/zombie_spec.rb
require 'rails_helper'
describe Zombie do
it 'is invalid without a name' do
zombie = Zombie.new
zombie.should_not be_valid
end
end
Rspec error uninitialized constant
Read your assignment carefully - maybe one of your tasks is to add the file and implement the class TitleBracketsValidator
so it passes all the provided tests?
I'd search for the class in your sources. If not there - maybe you should create one. If it's there - then it's a loading issue. require
it in your specs and notify the recruiter that you fixed a possible bug (for extra points maybe)
Failing to run RSpec (uninitialized constant User (NameError)
After removing --warnings from .rspec (thank you kirti), current error was about capybara version being too low (requires 2.2). After installing the latest version (modifying gemfile and bundle install), rspec appears to be executing correctly. Thank you to all for your comments.
When run RSpec I get uninitialized constant Name::Name::Engine
Use the fully qualified name in your spec instead of placing your specs in a module.
Do:
RSpec.describe Foo::Bar::Baz do
end
Don't:
module Foo
module Bar
RSpec.describe Baz do
end
end
end
Besides the fact that writing specs at 3 levels of indentation is ugly as heck you're asking for a kick in the privates by changing the context as it will try to resolve everything from the Foo
namespace so that you have to use ::SomeOtherModule
to refer to everything else.
Related Topics
What Ruby Features Are Used in Chef Recipes
How to Sort a Ruby Array by Two Conditions
Why Does Shoveling a String into a Hash Cause This Result
Why Rails Instance Method Can Be Used as Class Method in Rspec
Ruby on Rails CSV Upload&Import - File Name Too Long
Bind and Destructure Block Arguments
How to Condense Summable Metrics to a Unique Identifier in a Ruby Table
Why Does 'Defined' Return a String or Nil
Selenium Webdriver Take Screenshot of Viewport Only
Webpack Error on Heroku Deployment
Implementing Dry-Run in Ruby Script
Adding Nested Attributes to Devise User Model
Ruby/Rails - Active Record Db Migration to MySQL - Timestamp Type
Duplicate Elements of Array in Ruby
Why Must I Explicitly Call Self on Accessor When Using the Array Union Operator |= in Ruby
How to Send Notifications to the User Whose Post Received a Comment