Rspec error when I run my rspec test of my controller - ruby-on-rails

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

Related

Getting Capybara::DriverNotFoundError when trying to run Cucumber tests

I'm getting this error when I run the cucumber tests. Everything seemed to be working fine the previous day but I can't figure out why it stopped working. I was trying to get capybara webkit working and I had changed a couple of files but I don't see why it should affect my tests. Any idea on how to fix this error I'm getting while running the cucumber tests?
Capybara::DriverNotFoundError: no driver called :rack was found, available drivers: :rack_test, :selenium, :webkit, :webkit_debug
You mentioned that you edited many files. Could it be that you didn't revert all the changes you made? I think Capybara would pick the 'rack_test' driver by default, and your system could not find the 'rack' driver.
Since you're doing Cucumber testing, you must have a file called 'env.rb' under the features/support folder. Make sure you don't force 'rack' as your Capybara driver, and your tests should run fine.

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.

RSpec not printing failure reports

I managed to mess up my gemsets by mixing rvm and sudo. Ended up having to uninstall ruby, rvm and start from scratch. Now I've got everything up and running, except my RSpec isn't behaving as it should be. All it displays is:
bundle exec rspec spec/
..................................................................F.
In the past it would display a detailed failure report showing which test failed, and why, like:
1)
'User should be in any roles assigned to it' FAILED
expected in_role?("assigned role") to return true, got nil
./user_spec.rb:7:
Finished in 0.0172110000000001 seconds
1 example, 1 failure
I've tried playing with the various formatter options. The 'd' option gives me the most verbose results, but these are too verbose as every single test that succeeds is also printed in full on a new line, which quickly starts turning the report into pages.
What can I change to make RSpec work like before?
You need ask to rspec say the complete backtrace. The option is --backtrace or -b
You can define it in your .rspec file in your directory or in your rspec command line.

Selenium Can't Find 'spec' Folder

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

How do I get 'rake test:acceptance' to run successfully on Windows?

I am currently investigating using the selenium-on-rails plug-in for testing an upcoming web app that we are developing.
I've written some tests, and can get them to run successfully in the test runner in the browser, however when I try to run them from the command line using 'rake test:acceptance' I see the following error:
rake aborted!
fork() function is unimplemented on this machine
I have installed the win32-open3 gem and win32-process, neither of these seem to have helped.
Any ideas how I can get this working?
I managed to resolve this by adding the following to the top of acceptance_test_runner.rb:
require 'win32/open3'
require 'win32/process'
However the script was also determining my platform as 'i386-mingw32', which does not match the regexp the script uses to determine if you are on windows /mswin/.
Resolved this second issue by manually specifying
RUBY_PATH=mswin
Phew.

Resources