new to rspec, need to work on a test, when I run rake spec I get these errors, searched thru a bunch of old similar issues but nothing is working. not sure what to do...please help.
ruby -v 2.1.2
rails -v 4.1.4
http://pastebin.com/VJUh0Hhg
Thanks.
I guess the file located at /Users/jessep/work/noterizer/spec/helpers/notes_helper_spec.rb have an issue in the line 2
probably it looks like:
require File.expand_path("../../config/environment", __FILE__)
to fix the issue just add ../ so should look like:
require File.expand_path("../../../config/environment", __FILE__)
Related
I have a project in jRuby that I try to run.
So I'm installling jruby using rvm like this
rvm install jruby-9.1.15.0 (bc thats the version required by the project)
then im making sure that im actually using jruby by typing
ruby -v which shows me that I have jruby
next thing, I want to run the rails server so I'm typing
bundle exec rails server
and unfortunately I get an error:
/Users/foouser/Documents/Projects/fooproject/bin/config/application
LoadError: no such file to load -- /Users/foouser/Documents/Projects/fooproject/bin/config/application
require at org/jruby/RubyKernel.java:955
block in server at /Users/foouser/.rvm/gems/jruby-9.1.15.0-jrubu/gems/railties-4.2.10/lib/rails/commands/commands_tasks.rb:78
tap at org/jruby/RubyKernel.java:1741
server at /Users/foouser/.rvm/gems/jruby-9.1.15.0-jrubu/gems/railties-4.2.10/lib/rails/commands/commands_tasks.rb:75
run_command! at /Users/foouser/.rvm/gems/jruby-9.1.15.0-jrubu/gems/railties-4.2.10/lib/rails/commands/commands_tasks.rb:39
<main> at /Users/foouser/.rvm/gems/jruby-9.1.15.0-jrubu/gems/railties-4.2.10/lib/rails/commands.rb:17
require at org/jruby/RubyKernel.java:955
<main> at bin/rails:5
I've tried googling that but to no avail. People seem to not encounter this issue at all. I'm sure it's got something to do with my setup because other people are successfully using said project.
Any ideas?
rails version - 4.2
jruby version - 9.1.15.0
EDIT:
after some digging, in bin/rails file the line defining the APP_PATH was like that:
APP_PATH = File.expand_path('../config/application', __FILE__)
which somehow made it looking for application.rb inside fooproject/bin/config instead of fooproject/config
but when I changed the line to
APP_PATH = File.expand_path('../../config/application', __FILE__)
it goes to the correct path where application.rb exist but still reports it as not existing.
the error is nearly the same (apart for path)
LoadError: no such file to load -- /Users/foouser/Documents/Projects/fooproject/config/application
require at org/jruby/RubyKernel.java:955
block in server at /Users/foouser/.rvm/gems/jruby-9.1.15.0-jrubu/gems/railties-4.2.10/lib/rails/commands/commands_tasks.rb:78
tap at org/jruby/RubyKernel.java:1741
server at /Users/foouser/.rvm/gems/jruby-9.1.15.0-jrubu/gems/railties-4.2.10/lib/rails/commands/commands_tasks.rb:75
run_command! at /Users/foouser/.rvm/gems/jruby-9.1.15.0-jrubu/gems/railties-4.2.10/lib/rails/commands/commands_tasks.rb:39
<main> at /Users/foouser/.rvm/gems/jruby-9.1.15.0-jrubu/gems/railties-4.2.10/lib/rails/commands.rb:17
require at org/jruby/RubyKernel.java:955
<main> at bin/rails:4
EDIT 2:
requested permissions for application.rb:
-rw-r--r-- 1 foouser staff 5818 20 Jun 15:12 config/application.rb
config.ru:
# This file is used by Rack-based servers to start the application.
require ::File.expand_path('../config/environment', __FILE__)
run Rails.application
environment.rb
# Load the Rails application.
require File.expand_path('../application', __FILE__)
# Initialize the Rails application.
Rails.application.initialize!
So, the solution I have is the "have you tried to turn it off and on again?" type.
I have deleted the whole project and cloned it again from the repo.
Everything is working now, it must have been something with my local env but I can't tell what.
Anyway, if you ever encounter something similar - purge and clone is definitely something you can try.
I'm using the following:
Rails 4.1.1
guard-zeus 2.0.0
rspec-rails 3.0.1
Out of box default rails g rspec:install and guard init
When I run guard and save a spec file, I get the error:
undefined method `configure` for RSpec:Module (NoMethodError)
I can run specs with rspec spec and rake just fine.
In spec_helper, if I require 'rspec/rails before the configure block,
guard works fine, but then rspec spec fails with the error:
uninitialized constant ActiveSupport::Autoload (NameError)
I'm guessing there's a problem with load order now that rails_helper and spec_helper
are separated.
Two questions:
How can I fix this?
Is there a different solution for continuous integration locally that you can recommend that works with latest Rails and Rspec.
You only have to answer one question.
The following fix worked for me:
#spec/spec_helper.rb
require 'rspec/core'
Throwing out a quick answer that may be the problem. Your spec_helper file should have the following order:
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
rspec/rails needs to be required after the config/environment require.
The following:
undefined method `configure` for RSpec:Module (NoMethodError)
suggests you are are missing a
require 'rspec'
This normally isn't necessary, but if you put it in your spec/spec_helper.rb that should work.
(If you run RSpec directly, it's included already with RSpec).
The reason it's not included is perhaps:
you are not running guard through bundler
or your Gemfile does not have:
gem 'rspec' # without the require: false
or something may be wrong with your .rspec file (which should be present)
The require 'rspec/rails' should probably go into the spec/rails_helper.rb...
... but a better way would be to update your rspec-rails gem and run:
rails generate rspec:install
and if you're prompted - used 'd' to differences (and ideally use the recommended changes).
You should add following require to top of file spec_helper.rb
require 'rspec/rails'
Take the reference here: Zeus GitHub issue 308
I am trying to run rspec for Ruby on Rails. I am running Rails 4.1.1. I have installed the gem, have established a spec folder with some tests. I have created a directory through $ rails g rspec:install
I tried to create a testing database through $ rake db:test:prepare but it throws this error message:
WARNING: db:test:prepare is deprecated. The Rails test helper now maintains your test
schema automatically, see the release notes for details.
So I ended up looking at this stack overflow post, and of the two options, the one that worked was:
rake db:schema:load RAILS_ENV=test
So, now I need to run rspec.
When I run $ rspec spec from the command line I get this error:
/Users/myname/.rbenv/versions/2.1.1/lib/ruby/2.1.0/rubygems/core_ext/
kernel_require.rb:55:in `require': cannot load such file -- rails_helper (LoadError)
How do I resolve this so that I can start running tests?
There is some problem with rspec V3. But in your case you are using V2.
change
require 'rails_helper'
to
require 'spec_helper'
Other description find here https://teamtreehouse.com/forum/problem-with-rspec
For V3 :
If someone using rspec V3 then similar error occurs when generator not run. So before trying anything run generator.
rails generate rspec:install
If you are getting a huge list of warning on your console. Then you need to remove --warnings from .rspec file.
I actually just had this error on rails 4 with rspec 3, but in my case I forgot to run the generator:
rails generate rspec:install
Also I had to remove warnings from .rspec, as stated by one of rpsec developers
For me, the problem was due to a different "rspec-support" version loaded and activated. I solved by prepending a "bundle exec":
bundle exec rspec
Always remember to run the
rspec or the bundle exec rspec from the root of your project.
Something like:
bundle exec rspec spec/features/file_test_spec.rb
For newer versions (3.5), if you need to run the generator, rails generate rspec:install doesn't work for me. I used:
rspec --init
Creates .rspec and spec/spec_helper.rb.
EDIT:
Just in case, I found out that I installed rspec gem for ruby, not the one for Rails, so rspec:install wasn't available. Should use https://github.com/rspec/rspec-rails.
Sometimes you need to run rspec command from Project's parent directory
Please install the following gem:
gem install 'rspec-rails'
And then run:
rails generate rspec:install
This will generate the spec folder and rails_helper.rb and spec_helper.rb. Your error should be taken care once this is done.
None of these suggestions worked for me on Rails 4.2.0 with rspec-rails 3.2.3.
Instead, I placed the following two lines at the top of my spec file:
require 'rails_helper'
require 'spec_helper'
Now I can execute rspec spec/features/my_spec.rb.
I had the same error but there was no reference to rails_helper anywhere and we weren't even using rails.
However, I eventually found that my ~/.rspec was requiring rails_helper (presumably from creating rails app in the past) which was causing the issue ...
$ cat ~/.rspec
--color
--format documentation
--require spec_helper
--require rails_helper
The fix is as simple as removing that line. Hope this helps someone else grappling with the same issue!
One possibility that worked for me is to make sure you're requiring spec_helper. RubyMine can default require rspec and this can sometimes lead to this error.
You may also have your file named incorrectly. Make sure it ends in _spec.rb. I had misspelled my file to end in _soec.rb and was scratching my head for a while...
I got the error you described when running a controller test. However, when I ran a model test, I got the true error. it ended up saying that the error was occuring because my database wasn't migrated. I fixed the error by running this command...
rake db:test:prepare
For someone. If you got that error when you trynna test a specific file. you might can like this
$ bundle exec rspec ./spec/features/user_login_spec.rb
$ bundle exec rspec ./spec/models/user_login_spec.rb
This is bizarre because I am relatively certain that minitest is an independent testing framework from rspec.
In any case, what is happening is that when I run.
rspec at my rails root directory, I get this error:
Could not find minitest-4.7.5 in any of the sources
However in my Gemfile I have the following:
gem 'minitest', '~> 4.7.5'
I have tried running bundle update and bundle install to no avail. Also I feel weird even adding the gem file as I only added it after I got the error but had no intention of using the gem to begin with.
For reference here is my spec_helper.rb file.
require 'rubygems'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
Hard to know w/o more information, it's likely something else is bringing it in if you aren't... Do this:
Revert to a clean state in your repository
Remove minutest from Gemfile
Run bundle (not update)
Look in your Gemfile.lock and see what is depending upon minitest
Post the information here if the answer doesn't become clear.
You may also want re-run rails generate rspec:install, that spec_helper.rb you posted looks pretty thin.
It turns out I just needed to run bundle exec rspec to run my tests.
I'm trying to run individual tests through ruby test/unit/mytest.rb, but I always get a "no such file to load - test_helper" error. Google brought up a few suggestions, but none of them worked for me. I'm running Rails 3.0, Ruby 1.9.2 (through RVM) on Ubuntu 10.10
Here's what I've tried so far - any suggestions really appreciated
Changed the "require test_helper" to "require File.dirname(FILE) + "/../test_helper"
" in test/unit/mytest_test.rb. It brings back " no such file to load -- test/unit/../test_helper"
Tried running rvm test/unit/mytest_test.rb Same as above
Tried running ruby -I test/unit/mytest_test.rb. No messages to the terminal. After about 5 minutes waiting for something to happen, ctrl+c'd out of it
Any suggestions very appreciated - I'm stumped.
ruby 1.9.2 removed ".", the current directory, from the load path. I have to do this to get it to work:
require 'test_helper'
and call it like:
ruby -I. unit/person_test.rb
I was fighting this thing myself today and i dislike the big require with whole path to file and stuff...
In my case it was fault of Rakefile..
so now it looks like this:
require "bundler/gem_tasks"
require "rake/testtask"
Rake::TestTask.new do |t|
t.libs << "lib"
t.libs << "test" # here is the test_helper
t.pattern = "test/**/*_test.rb"
end
task default: :test
I know its old and has answer marked accepted, but maybe this will also help someone :)
have a nice day
I've added the following to the top of my test files.
require File.expand_path("../../test_helper", __FILE__)
This restores the previous behavior and allows the call to be simply:
ruby test/unit/person_test.rb
Maybe you should run your test cases in this way:
$ rake test
There is no need to change the "require" statement from generated code if you use rake.
Tested with Ruby 1.9.3 and Rails 3.2.8
If you are creating a gem or engine, running rake test in the test dummy application directory will cause this error. Running rake test in the root of the gem will avoid this.
Rails 1.9 no longer includes the current directory in the LOAD_PATH, which causes this problem. You have a few options.
call the test with the -I option from the app dir:
ruby -I test test/functional/test_foo.rb
and use a require with no path:
require "test_helper.rb"
use a full path in the require. Either
require 'pathname'
require Pathname.new(FILE).realpath.dirname.join('/../test_helper.rb')
or
require (File.dirname(File.realdirpath(__FILE__)) + '/../test_helper.rb')