Can't run Rails tests - ruby-on-rails

I've reviewed the questions that seem to be relevant to my problem, and I can't find a solution. When I try to run the tests in a Rails 3.0.3 App, I get this error:
willmac:signalkit wbarrett$ rake test
(in /Users/wbarrett/Sites/signalkit)
LOADING CONFIG/ENVIRONMENT.RB
./test/unit/authentication_test.rb:3: uninitialized constant ActiveSupport (NameError)
from /Users/wbarrett/.rvm/gems/ree-1.8.7-2011.03#global/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5:in `load'
from /Users/wbarrett/.rvm/gems/ree-1.8.7-2011.03#global/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5
from /Users/wbarrett/.rvm/gems/ree-1.8.7-2011.03#global/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5:in `each'
from /Users/wbarrett/.rvm/gems/ree-1.8.7-2011.03#global/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5
./test/functional/authentications_controller_test.rb:3: uninitialized constant ActionController (NameError)
from /Users/wbarrett/.rvm/gems/ree-1.8.7-2011.03#global/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5:in `load'
from /Users/wbarrett/.rvm/gems/ree-1.8.7-2011.03#global/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5
from /Users/wbarrett/.rvm/gems/ree-1.8.7-2011.03#global/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5:in `each'
from /Users/wbarrett/.rvm/gems/ree-1.8.7-2011.03#global/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5
Errors running test:units, test:functionals!
As you can see, the tests are requiring test_helper and requiring environment.rb (I added the LOADING.. output to the top of the environment.rb config file)
Here's my Gemfile:
source 'http://rubygems.org'
gem 'rails', '3.0.3'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3-ruby', :require => 'sqlite3'
gem 'devise'
gem 'unicorn'
gem 'omniauth', :git => 'git://github.com/signalkit/omniauth.git', :branch => 'signalkit'
gem 'mongrel'
# gem 'tinder'
gem 'oauth2', :git => 'git://github.com/signalkit/oauth2.git', :branch => 'signalkit' #0.1.1 with modification for Basecamp
gem 'crack'
gem 'delayed_job'
gem "builder", "2.1.2"
gem "haml", "3.0.12"
gem "maruku", "0.6.0"
gem "RedCloth", "4.2.2"
gem "sinatra", "1.1.0", :require => "sinatra/base"
gem "monkeywrench"
gem "httparty"
gem "hoptoad_notifier"
group :test do
gem "shoulda", "~> 2.11.3"
gem "mocha", "~> 0.9.12"
gem "webmock", "= 0.7.3"
gem "test-unit"
end
What's wrong with this picture? Thanks all!
UPDATE: 6/30/2011 4:05PM CST
For whatever reason, changing the require at the top of all the test files from
require 'test_helper'
to
require File.dirname(__FILE__) + '/../test_helper'
solved my problem. +25 to whoever can tell me why this is, since the helper was being loaded fine the other way as well.

Related

Rails 3.2 precompilation fails

I'm a newby in Rails, and I'm developing some app with 3.2.0. So, all is good, it works on my local environment, but when I try to push it to Heroku there are troubles with assets - my css files don't compile into one application.css file, therefore my final application.css is clean (you can see it by link my app on Heroku). There are no problems on my local machine. I've found some answers in Google and people recommended do the following command:
RAILS_ENV=production bundle exec rake assets:precompile
I tried to do it and got the following output:
/Users/marya/.rvm/rubies/ruby-1.9.3-p448/bin/ruby: No such file or directory -- ruby /Users/marya/.rvm/gems/ruby-1.9.3-p448#global/bin/rake assets:precompile (LoadError)
rake aborted!
Command failed with status (1): [/Users/marya/.rvm/rubies/ruby-1.9.3-p448/b...]
/Users/marya/.rvm/gems/ruby-1.9.3-p448/gems/actionpack-3.2.0/lib/sprockets/assets.rake:9:in `ruby_rake_task'
/Users/marya/.rvm/gems/ruby-1.9.3-p448/gems/actionpack-3.2.0/lib/sprockets/assets.rake:17:in `invoke_or_reboot_rake_task'
/Users/marya/.rvm/gems/ruby-1.9.3-p448/gems/actionpack-3.2.0/lib/sprockets/assets.rake:25:in `block (2 levels) in <top (required)>'
/Users/marya/.rvm/gems/ruby-1.9.3-p448/bin/ruby_executable_hooks:14:in `eval'
/Users/marya/.rvm/gems/ruby-1.9.3-p448/bin/ruby_executable_hooks:14:in `<main>'
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)
I don't understand what it does mean, therefore I need your help. My Gemfile:
source 'https://rubygems.org'
gem 'rails', '3.2.0'
gem 'bootstrap-sass', '2.1'
gem 'bcrypt-ruby', '3.0.1'
gem 'faker', '1.0.1'
gem 'will_paginate', '3.0.3'
gem 'bootstrap-will_paginate', '0.0.6'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
group :development, :test do
gem 'sqlite3', '1.3.5'
gem 'rspec-rails', '2.11.0'
end
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '3.2.5'
gem 'coffee-rails', '3.2.2'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer'
gem 'uglifier', '1.2.3'
end
gem 'jquery-rails', '2.0.2'
group :test do
gem 'capybara', '1.1.2'
gem 'factory_girl_rails', '4.1.0'
end
group :production do
gem 'pg', '0.12.2'
gem 'rails_12factor'
end
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# To use Jbuilder templates for JSON
# gem 'jbuilder'
# Use unicorn as the web server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'
If you need another project files, please, just tell me about it and Ill do it. Thanks in advance!
Seems to be an RVM quirk. I ran into this using rvm + ruby 2.0.0-p247 and this worked for me:
rvm ruby-2.0.0-p247#global do gem install executable-hooks

Error running rspec test in rails

Hi I have created a test case in spec/myprocess as follows
before :each do
#my_base = MyBase.new
end
describe "new_my_base" do
it "should not take any arguments and retuens a MyBase object" do
#my_base.should be_an_instance_of MyBase
end
end
describe "#my_path" do
it "returns the correct mybase file path" do
$path.should eql App::Application.config.my_encode_type.to_s
end
end
and when I tun rspec spec/lib/mybasetest.rb it throws me the following error.
kalanamith#kalanamith:~/Documents/projects/leena$ rspec spec/lib/mybasetest.rb
*** Mocha deprecation warning: Change `require 'mocha'` to `require 'mocha/setup'`.
/var/lib/gems/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `block in require': iconv will be deprecated in the future, use String#encode instead.
*** Mocha deprecation warning: `require 'mocha/standalone'` has been deprecated. Please use `require 'mocha/api' instead.
/var/lib/gems/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require': cannot load such file -- mocha/object (LoadError)
/home/kalanamith/Documents/projects/fakturabank/spec/lib/mybasetest.rb:4:in `<top (required)>': undefined method `before' for main:Object (NoMethodError)
from /var/lib/gems/1.9.1/gems/rspec-core-2.10.1/lib/rspec/core/configuration.rb:746:in `load'
from /var/lib/gems/1.9.1/gems/rspec-core-2.10.1/lib/rspec/core/configuration.rb:746:in `block in load_spec_files'
from /var/lib/gems/1.9.1/gems/rspec-core-2.10.1/lib/rspec/core/configuration.rb:746:in `map'
from /var/lib/gems/1.9.1/gems/rspec-core-2.10.1/lib/rspec/core/configuration.rb:746:in `load_spec_files'
from /var/lib/gems/1.9.1/gems/rspec-core-2.10.1/lib/rspec/core/command_line.rb:22:in `run'
from /var/lib/gems/1.9.1/gems/rspec-core-2.10.1/lib/rspec/core/runner.rb:69:in `run'
from /var/lib/gems/1.9.1/gems/rspec-core-2.10.1/lib/rspec/core/runner.rb:10:in `block in autorun'
This is my gem file
source 'https://rubygems.org'
gem 'rails', '3.2.13'
gem 'jquery-rails' , '3.0.0'
gem 'pg'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
end
group :development, :test do
gem 'rails-dev-tweaks', '~> 0.6.1'
gem 'debugger'
gem 'rspec-rails', '2.10.0'
gem 'annotate'
gem 'factory_girl_rails'
gem 'shoulda-matchers'
gem 'simplecov', :require => false
gem 'simplecov-rcov', :require => false
gem 'pry'
gem "guard-rspec"
end
group :test do
gem 'mocha'
end
group :test do
gem "webmock"
end
gem 'debugger' # This gem works with ruby 1.9.3 it wraps these other things
gem 'savon', "~> 1.2.0"
gem 'airbrake'
gem 'aasm'
gem 'paranoia'
gem 'acts_as_tree'
gem 'will_paginate'
gem 'translate-rails3'
gem 'wicked_pdf'
gem 'activemerchant'
gem 'libxml-ruby'
gem 'libxslt-ruby'
gem 'ruby-xslt'
gem 'exception_notification', :require => 'exception_notifier'
gem "uuidtools", "~> 2.1.3"
gem "ruby-filemagic"
gem "rmagick", :require => false
gem "rubyzip"
gem "spreadsheet"
gem "multi_json"
gem "multi_xml"
gem "httparty"
#FormBuilder backwards compatibility
gem "dynamic_form"
gem "prototype-rails"
gem "formtastic"
gem "net-ssh"
gem "net-scp"
Um quite new to rails and this is my first experience with rspec framework . I will be grateful if anyone can assist me. Thank you in advance
There must be a "describe" that wraps before :each do
describe "Bla bla" do
before :each do
#my_base = MyBase.new
end
etc...
end
Anyway, the file name should be suffixed with _spec.rb
The before block should be inside the describe method
If you're using RSpec the end of the file must be suffixed with _spec.rb
Example: my_base_spec.rb
To Run: bundle exec rspec spec/my_base_spec.rb or simply bundle exec rspec

Rails: OAuth gem dependency error w/ bundler?

Trying to start the server and I'm getting this:
/Users/Ross/.rvm/gems/ruby-1.9.2-p180#webapp/gems/ruby/1.9.1/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:240:in `require': no such file to load -- addressable/uri (LoadError)
from /Users/Ross/.rvm/gems/ruby-1.9.2-p180#webapp/gems/ruby/1.9.1/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:240:in `block in require'
from /Users/Ross/.rvm/gems/ruby-1.9.2-p180#webapp/gems/ruby/1.9.1/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:223:in `block in load_dependency'
from /Users/Ross/.rvm/gems/ruby-1.9.2-p180#webapp/gems/ruby/1.9.1/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:640:in `new_constants_in'
from /Users/Ross/.rvm/gems/ruby-1.9.2-p180#webapp/gems/ruby/1.9.1/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:223:in `load_dependency'
from /Users/Ross/.rvm/gems/ruby-1.9.2-p180#webapp/gems/ruby/1.9.1/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:240:in `require'
from /Users/Ross/.rvm/gems/ruby-1.9.2-p180#webapp/gems/ruby/1.9.1/gems/faraday-0.7.5/lib/faraday/connection.rb:1:in `<top (required)>'
I've tried a number of versions, deleting the Gemfile.lock, updating the bundler, etc. I've searched a lot of the threads around and it there looks to be a conflict between OmniAuth and devise but not with my error. Version conflict? How do you diagnose?
Here's my Gemfile:
source 'http://rubygems.org'
require 'rubygems'
gem 'rails'
gem 'actionpack'
gem 'jquery-rails'
gem 'haml'
gem "devise", :git => "https://github.com/plataformatec/devise.git"
# gem 'oa-core'
gem 'omniauth'
gem 'omniauth-openid'
gem 'omniauth-twitter'
gem 'omniauth-facebook'
gem 'omniauth-github'
gem "settingslogic"
gem 'composite_primary_keys'
gem 'addressable'
# gem 'faraday'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'pg'
gem 'squeel'
gem 'sqlite3'
gem 'mysql2', '~> 0.2.6'
gem "bcrypt-ruby", :require => "bcrypt"
group :development, :test do
gem 'rspec-rails'
gem 'ruby-debug19', :require => 'ruby-debug'
gem 'hpricot', :require => false #html2haml
gem 'ruby_parser', :require => false # html2haml
gem 'pickle'
gem 'awesome_print', :require => 'ap'
gem 'factory_girl_rails'
end
group :development do
gem 'heroku', :require => false
gem 'sass'
end
group :test do
gem 'shoulda'
gem 'cucumber-rails'
gem 'spork', '~> 0.9.0.rc3'
gem 'guard-spork'
gem 'database_cleaner'
end
It actually was a ownership issue the dependent gem was installed as root. I updated the ownership all the directories and files in the gems directory and it worked. If you have a problem installing (i.e. generate native code) a gem where you sudo it, remember to go back and change the ownership of files back in the gems directory back to your user account

no such file to load -- openid/store/filesystem (Rails omniauth)

This is first time I'm trying to use Omniauth. While I was testing https://github.com/pt/devise-omniauth-example this example from github I came across an error
.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:240:in `require': no such file to load -- openid/store/filesystem (LoadError)
Here is my Gemfile content
source 'http://rubygems.org'
gem 'rake'
gem 'rails'
gem 'sqlite3-ruby', :require => 'sqlite3'
gem 'devise', :git => 'git://github.com/plataformatec/devise', :branch => 'master'
gem "omniauth", "1.0.1"
gem 'paperclip'
gem "simple_form", "~> 1.5.2"
gem 'twitter_oauth', '0.4.3'
gem "rest-client", "1.6.7", :require => "restclient"
gem "sluggable"
group :development, :test do
gem 'rspec-rails'
gem 'fixjour'
end
I search web but there was no luck.
According to this:
If you get "openid/store/filesystem (LoadError)" then you may need to add this to your Gemfile:
gem "oa-openid"
This is due to various versions of Gems you are using and the dependencies among them.
In the example at https://github.com/pt/devise-omniauth-example,
if you notice the Gemfile ,there is
gem 'omniauth', '0.2.0'
but in your Gemfile above, you are using
gem "omniauth", "1.0.1"
Add gem 'ruby-openid-apps-discovery', and add below in application.rb.
require 'omniauth-openid'
require 'openid'
require 'openid/store/filesystem'
require 'gapps_openid'

Rails 3 annotate doesn't work

When I run annotate at the command-line, I get the following error:
$ annotate
/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.7/lib/rails/application.rb:215:in `initialize_tasks': undefined method `task' for #<MyApp::Application:0x00000102e03b90> (NoMethodError)
from /.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.7/lib/rails/application.rb:139:in `load_tasks'
from /.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.7/lib/rails/application.rb:77:in `method_missing'
from Rakefile:8:in `<top (required)>'
from /.rvm/gems/ruby-1.9.2-p0/gems/annotate-2.4.0/lib/annotate.rb:17:in `load'
from /.rvm/gems/ruby-1.9.2-p0/gems/annotate-2.4.0/lib/annotate.rb:17:in `load_tasks'
from /.rvm/gems/ruby-1.9.2-p0/gems/annotate-2.4.0/bin/annotate:66:in `<top (required)>'
from /.rvm/gems/ruby-1.9.2-p0/bin/annotate:19:in `load'
from /.rvm/gems/ruby-1.9.2-p0/bin/annotate:19:in `<main>'
This is what my Gemfile looks like:
source 'http://rubygems.org'
gem 'rails'
gem 'sqlite3-ruby', :require => 'sqlite3'
gem 'will_paginate', '3.0.pre2'
gem 'paperclip', :git => 'git://github.com/thoughtbot/paperclip.git'
gem 'mime-types', :require => 'mime/types'
gem 'rails3-generators'
gem 'devise', '~> 1.1.3'
gem 'devise_invitable', '~> 0.3.4'
gem 'declarative_authorization', :git => 'git://github.com/stffn/declarative_authorization.git'
gem 'aasm'
gem 'braintree'
#For voting
gem 'thumbs_up'
# For In-Place-Editing
gem 'best_in_place'
#For slugs for the plans
gem "friendly_id", "~> 3.2"
gem 'aws-s3'
group :development do
# Server
gem 'thin'
gem 'annotate-models', '1.0.4'
#gem 'rails-erd'
gem 'annotate'
gem 'faker', '0.3.1'
gem 'ruby_parser'
end
This is all on my localhost btw.
Marcamillion, it probably broke because at one stage you had rake 0.9.0 installed, which broke a lot of things for a lot of people without deprecating methods or warning people. When you ran bundle update, it would have installed rake 0.9.2 which fixed this. Hope this helps someone else.
I've solved this problem using gem 'annotate', ">=2.5.0".
I'm using ruby 1.9.2p320 and Rails 3.2.13.

Resources