Selenium Can't Find 'spec' Folder - ruby-on-rails

So I'm attempting to set up my local system to help finish off an existing project from an employer who uses only rails. They want me to primarily focus on rspec testing as the project is nearly functional and I need to flesh out the things they've missed. However, I cannot get 'rake spec' to build my test folder. As it is, the test folder contains a few basic user login tests using Selenium (I didn't write them). Here is the trace from the error:
/opt/local/lib/ruby/gems/1.8/gems/selenium-client-1.2.18/lib/selenium/rspec/spec_helper.rb:2:in 'require': no such file to load -- spec (LoadError)
from /opt/local/lib/ruby/gems/1.8/gems/selenium-client-1.2.18/lib/selenium/rspec/spec_helper.rb:2
from /Users/cliffhess/ampms/spec/integration/user_registration_name_not_blank_spec.rb:5:in 'require'
from /Users/cliffhess/ampms/spec/integration/user_registration_name_not_blank_spec.rb:5
from /opt/local/lib/ruby/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in 'load'
from /opt/local/lib/ruby/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in 'load_spec_files'
from /opt/local/lib/ruby/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in 'map'
from /opt/local/lib/ruby/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in 'load_spec_files'
from /opt/local/lib/ruby/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/command_line.rb:18:in 'run'
from /opt/local/lib/ruby/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:55:in 'run_in_process'
from /opt/local/lib/ruby/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:46:in 'run'
from /opt/local/lib/ruby/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:10:in 'autorun'
from /opt/local/lib/ruby/gems/1.8/bin/rspec:19
rake aborted!
As it is, I'm pretty sure I understand the problem(maybe?). Line 2 in selenium-clients's spec_helper.rb says require 'spec' which, if I'm not mistaken, is saying that selenium-client should contain a folder called spec which contains all of its rspec stuff. selenium-client does not have this folder, so I'm a little bit confused as to how its supposed to require the folder in the first place. If I change the line to require 'rspec', there are numerous other references to things within this imaginary spec folder that will also cause rake to abort.
I'm running Ruby 1.8.7, Rails 3.0.3, and the latest version of selenium. Any help would be amazing, I've been stuck googling this problem for over a day now and haven't been able to come up with a fix.

I had the same issue you had, and I tried a few things to make it runnable, so I'm just copy my answers from my question - LoadError when using Selenium: no such file to load -- spec
First I found Cucumber + Webrat + Selenium guide which is really useful
Second, I removed
require "selenium/rspec/spec_helper"
require "spec/test/unit"
And added
require 'spec_helper'
Where spec_helper is the contained in the spec folder
I also removed all the methods that is append_after
Basically now the test cases runnable, this is not the best solution, but it is what I did do so far.
P.S: need to download the Selenium server from http://seleniumhq.org/download/ and run the server with java -jar selenium-server-standalone-2.0b2.jar

Related

Trying to run a rspec test file and it can't find it

I am trying to learn RSpec, and thus starting with a simple calculator program.
Confused on how to have the rspec find the file because it keeps saying that it can't load it.
This is the process thus far:
1
Calculator class is written and saved as calculator.rb file. Create lib folder and move the calculator.rb file to it.
2
In the initial directory (i.e., outside of lib folder), I rspec --init which creates .rspec file & rspec/spec_helper.rb file.
3
Then I create write calculator_spec.rb file and put it in the rspec folder. On top of the calculator_spec.rb file, I have this require 'calculator.rb'
4
I run this command rspec calculator_spec.rb to which I get this 'load': cannot load such file
How do I fix this so the rspec command can find the file?
Thank you
This command would be in the first line of spec/spec_helper.rb:
require File.join(File.dirname(__FILE__), '../lib/calculator.rb')
Not sure which version of RSpec you are using but it should create a spec directory, not rspec in addition to the default .rspec file.
#jim-van-fleet's answer should work just fine. However, the best practice is to mirror your code directory under the spec directory. So it should look something like this:
I would also add the following to the top of your calculator_spec.rb file
require 'spec_helper'
require File.expand_path('../../../lib/calculator', __FILE__)

Tests that don't include spec_helper being ignored in rspec runs

When testing lib code there is rarely any need to require spec_helper and load all of rails. This is why I have been removing require "spec_helper" in favour of require_relative "../../lib/my_lib.rb".
These tests pass when called directly (rspec spec/lib/my_lib.rb) and are blazingly fast. Winner.
My issue comes when I try and run these tests as a group.
When I call rspec spec/lib it runs any lib specs that have a require "spec_helper" line but not any tests that don't.
I have played with spec_helper.rb to load in these tests, and that kind of works only it means that when I run rspec spec/models/blah.rb it will also run these lib tests, which obviously isn't what I want.
Is there a different way I should be calling my tests? Or is there a way I can get them added to the test run?
Notes
My spec_helper is configured to run the tests in a random order, I wonder if this has anything to do with it?
You should add _spec to your files:
spec/lib/my_lib_spec.rb
Rspec rake task will look only for files which end in _spec.

rspec2 in rails 4.0.5 app skipping specs in one spec file

I wrote some new specs in a file called, spec/requests/schedule_revise_button_next_day.rb, and was able to test the specs (red to green) so long as I ran that file alone with:
$ rspec spec/requests/schedule_revise_button_next_day.rb
When I ran all of my specs, however, with $ rspec spec/ , that file would get skipped. The specs wouldn't be run. To test running the file with other spec files, I tried renaming the file with different prefixes like a_schedule_revise_button_next_day.rb and then running commands like:
$ rspec spec/requests/a*
That file would still get skipped though the other a* files would run.
I also isolated the problem to the file name since I was able to get the specs to run when I cut and pasted them into other files. I also was able to replicate the problem on two separate computers with different hardware and OS (OSX and Ubuntu.)
Only when I changed the file name to schedule_revise_spec.rb would it not be skipped when I ran it with all of my other specs. This situation makes me nervous in that I almost didn't realize that these specs were not being run. Anyone know what the problem is with my original file name? I'd be very grateful for any thoughts anyone has.
Best,
Ben
When given a directory or file pattern on the command line, RSpec looks for files ending in _spec. See How can I get Rspec to run all tests nested under a folder? for more discussion.

What's `rspec/autorun` for?

I was having some problem with zeus + rspec and the solution I found says that I must to delete require 'rspec/autorun' from spec_helper.rb.
That worked great, but I was wondering what's the utility of rspec/autorun? It comes in spec_helper.rb by default, but the specs works anyway with or without it.
As far as i understand, you would need rspec/autorun if you want to run specs using "ruby" command.
From RSpec docs:
Generally, life is simpler if you just use the rspec command. If you must use the ruby command, however, you’ll want to do the following:
require 'rspec/autorun'
rspec/autorun installs an at_exit hook that runs your tests. That way you can simply execute your testfiles directly rather than passing them to the rspec command (and a few other tricks, like having tests run automatically when you execute a library file).
Most setups don't need it.

Rspec error when I run my rspec test of my controller

I am developing a Rails v2.3 application.
When I run the rspec test by execute command:
rspec spec/controllers/my_controller_spec.rb
I got the error message which is showing below:
/.rvm/gems/ruby-1.8.7-p352#myapp/gems/rspec-core-2.6.4/lib/rspec/core/configuration.rb:427:in `raise_if_rspec_1_is_loaded': (RuntimeError)
********************************************************************************
You are running rspec-2, but it seems as though rspec-1 has been loaded as
well. This is likely due to a statement like this somewhere in the specs:
require 'spec'
Please locate that statement, remove it, and try again.
********************************************************************************
/.rvm/gems/ruby-1.8.7-p352#myapp/gems/rspec-core-2.6.4/lib/rspec/core/configuration.rb:420:in `load_spec_files'
----update---
Since it complains about some file which contain the code require 'spec', so I follow this clue and I found "require 'spec'" in spec/spec_helper.rb , However, after I removed it , the same error still raise up, and I don't have any other file contain the code now.
Why the error still coming, what is the real cause then?
rspec is the executable for rspec-2. spec is the executable for rspec-1. rspec-2 is not compatible with rails 2.3. Your command should be:
spec spec/controllers/my_controller_spec.rb

Resources