Rspec not running on an application - ruby-on-rails

Ok so I am a ruby on rails developer and I am about to start trying to use the TDD (test driven development) approach and I am not sure what I am doing wrong. I have an existing app that has some rpec tests already and I am trying to figure how to run them but when i do
rake spec
(in /Users/tamer/Sites/preview)
/Users/tamer/.rvm/gems/ruby-1.9.2-p290#my_app/gems/aws-s3-0.6.2/lib/aws/s3/extensions.rb:206:in `const_missing_from_s3_library': uninitialized constant PreviewsController (NameError)
from /Users/tamer/.rvm/gems/ruby-1.9.2-p290#my_app/gems/rspec-core-2.5.1/lib/rspec/core/backward_compatibility.rb:20:in `const_missing'
from /Users/tamer/Sites/preview/spec/controllers/previews_controller_spec.rb:3:in `<top (required)>'
from /Users/tamer/.rvm/gems/ruby-1.9.2-p290#my_app/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `block in load_spec_files'
from /Users/tamer/.rvm/gems/ruby-1.9.2-p290#my_app/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `map'
from /Users/tamer/.rvm/gems/ruby-1.9.2-p290#my_app/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `load_spec_files'
from /Users/tamer/.rvm/gems/ruby-1.9.2-p290#my_app/gems/rspec-core-2.5.1/lib/rspec/core/command_line.rb:18:in `run'
from /Users/tamer/.rvm/gems/ruby-1.9.2-p290#my_app/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:55:in `run_in_process'
from /Users/tamer/.rvm/gems/ruby-1.9.2-p290#my_app/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:46:in `run'
from /Users/tamer/.rvm/gems/ruby-1.9.2-p290#my_app/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:10:in `block in autorun'
rake aborted!
(See full trace by running task with --trace)
Is there something that i am missing and what I need to do to get the previous tests to run

The error is pretty self-explanatory.
uninitialized constant PreviewsController (NameError)
Chances are the PreviewsController class referenced by ./spec/controllers/previews_controller_spec.rb no longer exists in /app/controllers.
Either update the spec or remove it if the corresponding controller has been removed.

Related

How do i fix in ruby on rails the undefined method `alias_method_chain' error?

I have just cloned a github repo https://github.com/maxitron93/p2pcollective.com, as i was exploring this awesome p2p lending app i encountered an error
NoMethodError: undefined method `alias_method_chain' for ActiveRecord::ConnectionAdapters::PostgreSQLColumn:Class
both when migrationg db or raunning server. I'm using the cloud9 ide to avoid my pc environment.
Running through a couple of solution posts, i updated my gem store with device and erubis but still returned back to that 'alias_method_chain' error.
Here's a snippet of my logs:
rake db:migrate
rake aborted!
NoMethodError: undefined method `alias_method_chain' for ActiveRecord::ConnectionAdapters::PostgreSQLColumn:Class
Did you mean? alias_method
/usr/local/rvm/gems/ruby-2.3.4/gems/activerecord-postgres-hstore-0.7.8/lib/activerecord-postgres-hstore/activerecord.rb:80:in `<class:PostgreSQLColumn>'
/usr/local/rvm/gems/ruby-2.3.4/gems/activerecord-postgres-hstore-0.7.8/lib/activerecord-postgres-hstore/activerecord.rb:74:in `<module:ConnectionAdapters>'
/usr/local/rvm/gems/ruby-2.3.4/gems/activerecord-postgres-hstore-0.7.8/lib/activerecord-postgres-hstore/activerecord.rb:70:in `<module:ActiveRecord>'
/usr/local/rvm/gems/ruby-2.3.4/gems/activerecord-postgres-hstore-0.7.8/lib/activerecord-postgres-hstore/activerecord.rb:2:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.3.4/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:292:in `require'
/usr/local/rvm/gems/ruby-2.3.4/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:292:in `block in require'
/usr/local/rvm/gems/ruby-2.3.4/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:256:in `block in load_dependency'
/usr/local/rvm/gems/ruby-2.3.4/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:662:in `new_constants_in'
/usr/local/rvm/gems/ruby-2.3.4/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:256:in `load_dependency'
/usr/local/rvm/gems/ruby-2.3.4/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:292:in `require'
/usr/local/rvm/gems/ruby-2.3.4/gems/activerecord-postgres-hstore-0.7.8/lib/activerecord-postgres-hstore/railties.rb:18:in `block (2 levels) in <class:Hstore>'
/usr/local/rvm/gems/ruby-2.3.4/gems/activesupport-5.1.6/lib/active_support/lazy_load_hooks.rb:69:in `instance_eval'
/usr/local/rvm/gems/ruby-2.3.4/gems/activesupport-5.1.6/lib/active_support/lazy_load_hooks.rb:69:in `block in execute_hook'
/usr/local/rvm/gems/ruby-2.3.4/gems/activesupport-5.1.6/lib/active_support/lazy_load_hooks.rb:60:in `with_execution_control'
I expect my rails server to run smoothly from here.
alias_method_chain was deprecated and removed in Rails 5, but existed prior to that. It looks like a dependency (possibly pg) that has been installed is incompatible. You may be able to resolve the issue with bundle update pg, and if not, a broader bundle update should do the trick.
EDIT:
This is what I get for internet'ing before coffee. The gem responsible is in your stacktrace: activerecord-postgres-hstore, which isn't in the project you linked to, which suggests you've made other changes. You don't need that gem for Rails 4+. More info here
In my case, I had gem 'foreigner package from Gemfile
gem uninstall foreigner
bundle install
rails db:migrate
I hope it will be helpfull

Rails database migration error

I wanna get started with ror but this problem seems unsolvable. I know there are many threads about it this database error but none of the solutions appear to work out. I now searched through the forums all afternoon, with no success.
I basically just perform the first tasks from the textbook, which are as follows:
I create a new RoR project (Windows 10, SQLite3) with
rails new depot
Then I create a scaffold in this project with the following code:
rails generate scaffold Product title:string description:text image_url:string price:decimal
And as i test the application I get the db:migrate error. I tried rake db:migrate, db:rollback, db:drop and then db:create, I checked the migration file for mistakes, but nothing appears to work.
I assume the solution should be quite simple, since the application should be as uncomplex as it gets at this state, but I just cannot get behind the secret it appears.
Migrations are pending. To resolve this issue, run:
bin/rails db:migrate RAILS_ENV=test
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activerecord-5.0.1/lib/active_record/migration.rb:586:in `load_schema_if_pending!'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activerecord-5.0.1/lib/active_record/migration.rb:592:in `block in maintain_test_schema!'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activerecord-5.0.1/lib/active_record/migration.rb:823:in `suppress_messages'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activerecord-5.0.1/lib/active_record/migration.rb:597:in `method_missing'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activerecord-5.0.1/lib/active_record/migration.rb:592:in `maintain_test_schema!'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-5.0.1/lib/rails/test_help.rb:15:in `<top (required)>'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:293:in `require'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:293:in `block in require'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:293:in `require'
from C:/Users/Flori/Desktop/bsp/test/test_helper.rb:3:in `<top (required)>'
from C:/Users/Flori/Desktop/bsp/test/controllers/products_controller_test.rb:1:in `require'
from C:/Users/Flori/Desktop/bsp/test/controllers/products_controller_test.rb:1:in `<top (required)>'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-5.0.1/lib/rails/test_unit/test_requirer.rb:11:in `require'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-5.0.1/lib/rails/test_unit/test_requirer.rb:11:in `block in require_files'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-5.0.1/lib/rails/test_unit/test_requirer.rb:10:in `each'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-5.0.1/lib/rails/test_unit/test_requirer.rb:10:in `require_files'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-5.0.1/lib/rails/test_unit/minitest_plugin.rb:86:in `plugin_rails_init'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/minitest-5.10.1/lib/minitest.rb:80:in `block in init_plugins'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/minitest-5.10.1/lib/minitest.rb:78:in `each'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/minitest-5.10.1/lib/minitest.rb:78:in `init_plugins'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/minitest-5.10.1/lib/minitest.rb:129:in `run'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-5.0.1/lib/rails/test_unit/minitest_plugin.rb:73:in `run'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/minitest-5.10.1/lib/minitest.rb:62:in `block in autorun'
Switch of your server, then run
rake db:drop db:create db:migrate
This must fix your problem

When upgrading from Rails 3.2 to Rails 4, why does rake give 'uninitialized constant ActiveModel::ForbiddenAttributesProtection'?

I am currently attempting to upgrade a Rails 3.2 app to Rails 4. I updated my Gemfile by referencing the correct version of Rails:
gem 'rails', '~>4.0.0'
as well as removing the assets header, per here.
Next, I attempted to run rake rails:update. It gave me this error:
rake aborted!
NameError: uninitialized constant ActiveModel::ForbiddenAttributesProtection
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/activerecord-4.0.13/lib/active_record/attribute_assignment.rb:6:in `<module:AttributeAssignment>'
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/activerecord-4.0.13/lib/active_record/attribute_assignment.rb:3:in `<module:ActiveRecord>'
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/activerecord-4.0.13/lib/active_record/attribute_assignment.rb:2:in `<top (required)>'
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/activerecord-4.0.13/lib/active_record/base.rb:300:in `<class:Base>'
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/activerecord-4.0.13/lib/active_record/base.rb:281:in `<module:ActiveRecord>'
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/activerecord-4.0.13/lib/active_record/base.rb:22:in `<top (required)>'
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/activerecord-4.0.13/lib/active_record/railtie.rb:38:in `block in <class:Railtie>'
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/railties-4.0.13/lib/rails/railtie.rb:201:in `instance_exec'
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/railties-4.0.13/lib/rails/railtie.rb:201:in `block in run_tasks_blocks'
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/railties-4.0.13/lib/rails/railtie.rb:201:in `each'
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/railties-4.0.13/lib/rails/railtie.rb:201:in `run_tasks_blocks'
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/railties-4.0.13/lib/rails/application.rb:253:in `block in run_tasks_blocks'
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/railties-4.0.13/lib/rails/engine/railties.rb:17:in `each'
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/railties-4.0.13/lib/rails/engine/railties.rb:17:in `each'
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/railties-4.0.13/lib/rails/application.rb:253:in `run_tasks_blocks'
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/railties-4.0.13/lib/rails/engine.rb:446:in `load_tasks'
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/railties-4.0.13/lib/rails/railtie/configurable.rb:30:in `method_missing'
/vagrant/Rakefile:7:in `<top (required)>'
(See full trace by running task with --trace)
What is causing this error?
The only place I could find this error online was this GitHub issue.
I searched for ActiveModel::ForbiddenAttributesProtection on that page, and found it here.
As I was reading that comment and following, I found this one, which said:
Rails 3.2 apps can just add strong_parameter gem AFAIK and it would work out of the box.
Looking at my Gemfile again I realized what the problem was. It contained this line:
gem 'strong_parameters'
The problem is that the strong_parameters gem duplicates the Rails 4 way of doing things, allowing newer, better code to be used in Rails 3.2. Thus, it conflicts with the built-in functionality in Rails 4.
I removed that line from my Gemfile, and after running bundle, the rake command worked.
Edit: After restarting unicorn, I was getting a similar error in the log. I deleted config/initializers/strong_parameters.rb, but that didn't seem to help. However, after rebooting my VM, it was working properly.

uninitialized constant when migrating rails from ubuntu to osx

i'm trying to move my rails app from ubuntu to osx. when running rspec, i get the following obscure error:
/Users/josh/dev/myproject/spec/support/devise.rb:3:in `block in <top (required)>': uninitialized constant RequestHelpers (NameError)
from /Users/josh/.rvm/gems/ruby-1.9.3-p286#myproject/gems/rspec-core-2.11.1/lib/rspec/core.rb:92:in `configure'
from /Users/josh/dev/myproject/spec/support/devise.rb:1:in `<top (required)>'
from /Users/josh/dev/myproject/spec/spec_helper.rb:21:in `block (2 levels) in <top (required)>'
from /Users/josh/dev/myproject/spec/spec_helper.rb:21:in `each'
from /Users/josh/dev/myproject/spec/spec_helper.rb:21:in `block in <top (required)>'
from /Users/josh/.rvm/gems/ruby-1.9.3-p286#myproject/gems/spork-0.9.2/lib/spork.rb:24:in `prefork'
from /Users/josh/dev/myproject/spec/spec_helper.rb:4:in `<top (required)>'
from /Users/josh/dev/myproject/spec/controllers/comments_controller_spec.rb:1:in `require'
from /Users/josh/dev/myproject/spec/controllers/comments_controller_spec.rb:1:in `<top (required)>'
from /Users/josh/.rvm/gems/ruby-1.9.3-p286#myproject/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `load'
from /Users/josh/.rvm/gems/ruby-1.9.3-p286#myproject/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `block in load_spec_files'
from /Users/josh/.rvm/gems/ruby-1.9.3-p286#myproject/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `map'
from /Users/josh/.rvm/gems/ruby-1.9.3-p286#myproject/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `load_spec_files'
from /Users/josh/.rvm/gems/ruby-1.9.3-p286#myproject/gems/rspec-core-2.11.1/lib/rspec/core/command_line.rb:22:in `run'
from /Users/josh/.rvm/gems/ruby-1.9.3-p286#myproject/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:66:in `rescue in run'
from /Users/josh/.rvm/gems/ruby-1.9.3-p286#myproject/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:62:in `run'
from /Users/josh/.rvm/gems/ruby-1.9.3-p286#myproject/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:8:in `block in autorun'
everything works nicely in Ubuntu, so i guess it must be environmental. Any ideas where to start digging?
thanks
- Josh
EDIT: no idea why, but the file request_helpers.rb could not be found by rake. moving it elsewhere resolved the issue.
This hardly seems an operating system problem, much rather a matter of configuration. Make sure your environemnt is the same in terms of:
using rvm installed the same way
having all the needed gems in the Gemfile
using bundle to execute rspec
using the same version of everything.
By te way this is not an obscure message, it's in fact pretty clear:
uninitialized constant RequestHelpers (NameError)
so the spec/support/devise.rb file can't find the needed class.
Have you written that file? If not, how did you generate it? Repeat the procedure to generate it (probably rake something or rails generate something) and it will be OK.

Mocha::Integration uninitialized constant

I am trying to re-write a unit test cases for a web application for the test cases is not updated for long. The following is the error that I get when I run 'rake test'.
Note: the web application is upgraded from 2.3.1 to 2.3.8 in mean while.
And the following is the stacktrace:
Loaded suite /apps/rails/website/install/local/ruby-1.8.7-p299/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader
Started
/apps/rails/website/install/local/ruby-1.8.7-p299/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:440:in `load_missing_constant': uninitialized constant Mocha::Integration (NameError)
from /apps/rails/website/install/local/ruby-1.8.7-p299/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:80:in `const_missing'
from /apps/rails/website/install/local/ruby-1.8.7-p299/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/testing/setup_and_teardown.rb:51:in `run'
from /apps/rails/website/install/local/ruby-1.8.7-p299/lib/ruby/1.8/test/unit/testsuite.rb:34:in `run'
from /apps/rails/website/install/local/ruby-1.8.7-p299/lib/ruby/1.8/test/unit/testsuite.rb:33:in `each'
from /apps/rails/website/install/local/ruby-1.8.7-p299/lib/ruby/1.8/test/unit/testsuite.rb:33:in `run'
from /apps/rails/website/install/local/ruby-1.8.7-p299/lib/ruby/1.8/test/unit/testsuite.rb:34:in `run'
from /apps/rails/website/install/local/ruby-1.8.7-p299/lib/ruby/1.8/test/unit/testsuite.rb:33:in `each'
from /apps/rails/website/install/local/ruby-1.8.7-p299/lib/ruby/1.8/test/unit/testsuite.rb:33:in `run'
from /apps/rails/website/install/local/ruby-1.8.7-p299/lib/ruby/1.8/test/unit/ui/testrunnermediator.rb:46:in `run_suite'
from /apps/rails/website/install/local/ruby-1.8.7-p299/lib/ruby/1.8/test/unit/ui/console/testrunner.rb:67:in `start_mediator'
from /apps/rails/website/install/local/ruby-1.8.7-p299/lib/ruby/1.8/test/unit/ui/console/testrunner.rb:41:in `start'
from /apps/rails/website/install/local/ruby-1.8.7-p299/lib/ruby/1.8/test/unit/ui/testrunnerutilities.rb:29:in `run'
from /apps/rails/website/install/local/ruby-1.8.7-p299/lib/ruby/1.8/test/unit/autorunner.rb:216:in `run'
from /apps/rails/website/install/local/ruby-1.8.7-p299/lib/ruby/1.8/test/unit/autorunner.rb:12:in `run'
from /apps/rails/website/install/local/ruby-1.8.7-p299/lib/ruby/1.8/test/unit.rb:279
from /apps/rails/website/install/local/ruby-1.8.7-p299/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5
please help me in this regard.
This helped me in this regard:
require 'mocha'
require 'mocha/integration/test_unit'
To be done in the test file, or in a helper if you are including one.
I had the same error, and re-installing of all gems helped me.

Resources