Rspec testing fails with "NameError: uninitialized constant ActionController::TestCase::Assertions" - ruby-on-rails

I am working on a sample RoR app and I am having trouble testing it with rspec. I have rspec installed and running the tests however they are failing and I don't know why. I run the command:
bundle exec rspec spec/
And when I run this; this is the error message I get:
Failures:
1) PagesController GET 'home' should be successful
Failure/Error: Unable to find matching line from backtrace
NameError:
uninitialized constant ActionController::TestCase::Assertions
# /usr/lib/ruby/vendor_ruby/action_controller/integration.rb:18
# /usr/lib/ruby/gems/1.8/gems/webrat-0.7.1/lib/webrat/integrations/rails.rb:2
# /usr/lib/ruby/gems/1.8/gems/webrat-0.7.1/lib/webrat/core/configuration.rb:105:in `mode='
# /usr/lib/ruby/gems/1.8/gems/rspec-rails-2.6.1/lib/rspec/rails/vendor/webrat.rb:26
# /usr/lib/ruby/gems/1.8/gems/webrat-
And alot more error messages.
I'm no expert on RoR and would really appreciate help. Thanks in advance.

RSpec is only guaranteed to work out of the box for Rail defaults. Remove webrat from your Gemfile and try it again.
Depending on the tutorial this might break things again in later steps.
My solution to the problem was to remove the package installation of rails (apt-get remove rails && apt-get autoremove) and its dependencies, because it was apparently clashing with the gem install. Quite understandable. You can install it with gem (sudo gem install rails)

I had the same problem on a fresh Ubuntu 11.10 install.
After ensuring I was using the latest versions of rspec and that rails was installed using
gem install rails
I also ensured that uninstalling the ubuntu rails didn't leave any artificts with
sudo apt-get autoremove
I also had ruby 1.8.7 so I switched to 1.9.2
rvm use 1.9.2
Either my ruby version was the problem or the autoremove removed some interference. But things were working after that.

Related

bundle install does not work and says undefined methods (trying to install ruby on rails on ubuntu)

I'm trying to install Ruby on rails on my ubuntu, I've installed everything for Ruby on rails to work, I've created my ruby on rails project but when I run ruby server they say "run bundle install" but whenever I run it I get :
/snap/ruby/247/lib/ruby/3.1.0/rubygems.rb:1340:in `rescue in <top (required)>': undefined method `rubyforge_project=' for class `Gem::Specification' (NameError)
Loading the rubygems/defaults/operating_system.rb file caused an error.
Try to install ruby manually, rbenv, rvm and update RubyGems manually
Here is a good guide to walk you through the proccess
https://gorails.com/setup/ubuntu/21.04

Devise Ruby Gem NameError when installing

I was trying to install the Ruby Gem Devise and I stupidly overlooked a step. I included the gem in my gemfile then ran the bundle install on the prompt. Then I forgot to run the generator rails generate devise:install.
Then when I went to generate my User model it came up with the following error C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/activesupport-5.1.4/lib/active_support/inflector/methods.rb:269:inconst_get': uninitialized constant User (NameError)`
I've tried uninstalling the gem and removing anything that refers to Users and reinstalling the gem but it keeps coming up with the same error.
I'm hoping someone can maybe shine a bit of light on this issue
I've just fixed the issue. When you run the bundle install command, it automatically configures the routes folder, so I've removed any reference to devise and it's worked now

spree does not give any homepage when installed

I am trying to set up the basic spree home page from this guide. https://guides.spreecommerce.com/developer/getting_started_tutorial.html. Here I did the following
$ rails new shop #I have ommited the version number 4.2.0<br>
$ cd shop <br>
$ spree install --auto-accept
$ bundle install
$ bundle update
This process works fine, some 103 gems are getting installed. But when started the server, and visited localhost:3000. I am getting the default welcome aboard page instead of the home page of spree as promised, more over when I visit localhost:3000/admin I am getting NO route matches admin error.
So thinking that all this has happened because of the missing version number as I have mentioned.
I did the following
$ rails _4.2.0_ new shop<br>
$ cd shop<br>
$ spree install --auto-accept<br>
$ bundle install
I got the jquery gem versioning error, when resolved that error by specifying explicitly the version number. I am getting sprockets gem version error, What I don't understand is is there something wrong I am doing? Or is there a fix for this. Any pointers are appreciated
after doing spree install --auto-accept I was getting a message to run bundle install . I thought this is a post installation message, so I was doing bundle install and bundle update. Then I proceeded to start a server, and that default rails was showing up. So after running bundle install and bundle update, go ahead and do the spree install --auto-accept. Now start the server. Everything will work just fine

Rails command Error

Im about to start work on another web application, I change directories to
/rails_projects
and enter
rails new blank
I then get this error
Error: Command not recognized
Usage: rails COMMAND [ARGS]
The common rails commands available for engines are:
generate Generate new code (short-cut alias: "g")
destroy Undo code generated with "generate" (short-cut alias: "d")
All commands can be run with -h for more information.
If you want to run any commands that need to be run in context
of the application, like `rails server` or `rails console`,
you should do it from application's directory (typically test/dummy).
I have reinstalled rails, and still same error, any ideas?
UPDATE:
It actually give me the same error when I type just
rails -h
rails
in cmd
For anyone with a similar error that may land here, this fixed it for me:
rake rails:update:bin
This will generate "new" versions of the binaries. Just say Yes when it inquires you to replace them.
I ran into a similar issue when trying to upgrade a Rails Engine from 3.2 to 4.1.
The culprit was the presence of script/rails which contained:
#!/usr/bin/env ruby
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
ENGINE_ROOT = File.expand_path('../..', __FILE__)
ENGINE_PATH = File.expand_path('../../lib/my_project/engine', __FILE__)
require 'rails/all'
require 'rails/engine/commands'
The problem line is there at the end: require 'rails/engine/commands. That was not allowing the full Rails CLI to load which omitted the new command. Removing that file solved my problem.
I'm pretty sure this wasn't the cause of your specific problem, but the symptoms were the same as mine and this was the first link in Google for the error message. Just passing along my findings to help anyone else that runs into this same situation.
It looks like the rails command believes it's inside of a rails engine, which is why a different set of commands are available to you. Notice the 'commands available for engines' text. New is not a command available for engines. I'm not sure why rails thinks the directory you're in is an engine, but likely your directory structure is mixed up somehow.
If anyone runs into this error and needs a last resort plan.
I ended up uninstalling rails, rvm, and installing a newer version of ruby and new gemset.
rvm implode
gem uninstall rails -v=4.0.2
gem uninstall railities
install rvm :
curl -L https://get.rvm.io | bash -s
rvm get stable
for mac:
brew install libtool libxslt libksba openssl
brew install libyaml
install ruby:
rvm install 2.0.0 --with-openssl-dir=$HOME/.rvm/usr
if you have error
rvm install 2.0.0 --with-openssl-dir=$HOME/.rvm/opt/openssl
install new ruby gems from website. Unpackage it then go to folder and run
ruby setup.rb
gem update --system 2.1.9
install rails (you can choose your version)
gem install rails --version 4.0.2
gem install railties
I did this, and now system is working normal again.
Create another directory and run $ruby -v, check which version is available. Now run rails new app_name. Try once after closing the terminal and restarting.
This happen to me when a require error occurred in a gem (dependency) while loading.

on Ubuntu running 'gem install taps' gives ERROR: ... (NoMethodError) ... '<<' for #<Bundler::SpecSet:

I'm on Ubuntu 11.04 using Ruby 1.9.2 with RVM and RubyGems 1.8.5 and when I run
gem install taps
I get
ERROR: While executing gem ... (NoMethodError)
undefined method `<<' for #<Bundler::SpecSet:0x000000020fbc50>
I can successfully migrate my db with
heroku rake db:migrate
I'm trying to install taps so that I can run
heroku db:push
which gives the error
Taps Load Error: no such file to load -- taps/operation
You may need to install or update the taps gem to use db commands.
On most systems this will be:
sudo gem install taps
Thanks for any help!
I'm reaaally new to rails but have had my fair amount of similar errors, so let me have a shot at it..
how about adding
gem "taps", "~> 0.3.23"
to your gemfile, and then running (in your app root folder...)
bundle install
Another little thing: Remember NOT to use sudo IF you are working with RVM as it will install gems as root but not at your home folder (and thus making your gemsets disorganized), OK, hope it helps. Check my Source
PD: good luck on dev with Natty, i got tired of it and downgraded to Ubuntu Maverick Meerkat

Resources