2011-03-16 58 views
1

基本上,我刚开始学on Rails的3使用Selenium,我开始与硒IDE和生成的RSpec格式LoadError使用Selenium时:没有这样的文件来加载 - 规格

剧本之前,我运行此脚本我已经安装的宝石selenium-clientSeleniumselenium-railsselenium-webdriver

但是,当我使用rspec的命令来运行该脚本,我得到了

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_require.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' 

我试图寻找答案,唯一的情况是我发现接近我的是Selenium Can't Find 'spec' Folder,这还没有人回答。

有人可以帮助我,请提前致谢。

回答

1

首先我发现Cucumber + Webrat + Selenium guide这是

其次,我删除

require "selenium/rspec/spec_helper" 
require "spec/test/unit" 

并补充

require 'spec_helper' 

spec_helper是包含在规范文件夹

我真的很有用也删除了所有的方法append_after

基本上现在的测试用例可以运行,这不是最好的解决方案,但这是我迄今为止所做的。

P.S:需要从http://seleniumhq.org/download/下载Selenium服务器和运行服务器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 
2

我有这个麻烦,以及。但是我试图运行这个独立的,而不是在一个rails3项目。然而我尝试使用ruby 1.9.2

我实际上试图测试一个我们想要增量转换为rails的IIS/ASP网站。第一步是采用我们完美的“Selenese”测试套件,将它们导出为RSpec并使用ruby等运行它们。我是ruby/rails领域的新手,我觉得这很令人沮丧。我认为几个小时的工作已经变成了几天...

我遵循类似的战术为你自己。但是,我只是删除了所有的宝石,并要求除require "selenium/client"之外的语句。我也将append_after更名为afterappend_after方法在selenium/rspec/spec_helper文件中定义(我检查了lib)。

我已经花了几个小时在网上搜索,我无法找到答案,为什么require "selenium/rspec/spec_helper"声明失败 - 它似乎spec(我认为是RSpec中使用什么被称为)缺少一种叫做。

我让它工作我认为它缺少一些功能。 spec_helper似乎处理捕获系统状态和其他有用的功能。

我有兴趣知道你在你的spec_helper文件。你可以发布吗?

+0

我已经安装了Rspec,并通过执行'rails generate rspec:install'在我的项目文件夹下生成了一个spec文件夹。 'spec_helper'文件包含在这个文件中,我把它放在我的答案中http://stackoverflow.com/questions/5330867/loaderror-when-using-selenium-no-such-file-to-load-spec/5341873#5341873 – Souloikj 2011-04-01 15:21:04

+0

感谢spec_helper澄清。 虽然我打算使用黄瓜和RSpec进一步开发此混合(rails/IIS)网站。我决定走低科技并使用测试/单元,因为Selenium可以转换为测试/单元以及RSpec。这很好,因为现有的Selenium测试不是非常“RSpec样”开始 - 而是他们更“测试/统一”;-) 这样我就可以完全独立运行这些测试,只有ruby或plop他们在rails应用程序结构中由rake运行。 – danv 2011-04-03 20:34:18

4

问题是您的Rspec版本。 Selenium宝石正在寻找Rspec 1.2.8或更高版本,但Rspec在2.0中对其类结构进行了改动,其中激烈。硒是寻找,只是不Rspec的2不复存在文件,类和方法,如果你卸载 Rspec的一则当前版本:

gem install rspec -v 1.3.1 

应该解决您的问题。如果您在自动化系统中使用Rspec来实现其他功能,这可能不是一个可行的选择。

相关问题