LoadError when using Selenium: no such file to load -- spec
Basically I just started to learn use Selenium on Rails 3, I started with the Selenium IDE and generated the script in RSpec format
Before I run this script I have installed gems for selenium-client
, Selenium
, selenium-rails
and selenium-webdriver
But as I using rspec command to run this script, I got
C:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:58:in `require': no such file to load -- spec (LoadError)
from C:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:58:in `rescue in require'
from C:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:35:in `require'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/selenium-client-1.2.18/lib/selenium/rspec/spec_helper.rb:2:in `<top (required)>'
from C:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from C:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/custom_requir开发者_如何学Pythone.rb:36:in `require'
from C:/Users/qsang/Desktop/Code/NextBigThing/spec/Selenium/create_new_user.rb:5:in `<top (required)>'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `load'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `block in load_spec_files'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `map'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `load_spec_files'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.5.1/lib/rspec/core/command_line.rb:18:in `run'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:55:in `run_in_process'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:46:in `run'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:10:in `block in autorun'
I have tried to search for answer, the only case I found that is close to mine is Selenium Can't Find 'spec' Folder, which no one has answered it yet.
Can someone help me please, thanks in advance.
The problem is your version of Rspec. The Selenium gems are looking for Rspec 1.2.8 or higher, but Rspec underwent drastic changes to its class structure in 2.0. Selenium is looking for files, classes, and methods that just don't exist anymore in Rspec 2. If you uninstall the current version of Rspec an then:
gem install rspec -v 1.3.1
It should fix your issues. If you're using Rspec for something else in your automation, this might not be a viable option though.
I am having trouble with this as well. However I am trying to run this standalone and not inside a rails3 project. I am however trying to use ruby 1.9.2.
I am actually trying to test an IIS/ASP website that we want to incrementally convert to rails. The first step was to take our perfectly fine "Selenese" set of test suites, export them as RSpec and run them using ruby, etc. I am new to the ruby/rails world and I find this very frustrating. What I thought would be a few hours of work has turned into days...
I followed similar tactics to your own. However, I simply removed all of the gem and require statements except require "selenium/client"
. Also I renamed append_after
to after
. The append_after
method is defined in selenium/rspec/spec_helper
file (I checked the lib).
I have spent hours and hours searching the web and I cannot find an answer as to why the require "selenium/rspec/spec_helper"
statement is failing - it seems that something called spec
(which I think is what RSpec used to be called) is missing.
I have it working I think but it is missing some functionality. The spec_helper
seems to handle capturing system state and other useful features.
I am interested to know what you put in your spec_helper
file. Could you post it?
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
spec_helper
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
RSpec.configure do |config|
# == Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
config.mock_with :rspec
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = true
end
精彩评论