Ruby on rails Rails的新特性——Webrat方法在集成测试中不起作用

Ruby on rails Rails的新特性——Webrat方法在集成测试中不起作用,ruby-on-rails,testing,rack,testunit,webrat,Ruby On Rails,Testing,Rack,Testunit,Webrat,我有一个文件: source 'https://rubygems.org' gem 'rails', '3.2.11' gem 'omniauth' gem 'omniauth-facebook' gem 'thin' # Bundle edge Rails instead: # gem 'rails', :git => 'git://github.com/rails/rails.git' gem 'pg' gem 'dev

我有一个文件:

source 'https://rubygems.org' gem 'rails', '3.2.11' gem 'omniauth' gem 'omniauth-facebook' gem 'thin' # Bundle edge Rails instead: # gem 'rails', :git => 'git://github.com/rails/rails.git' gem 'pg' gem 'devise' gem 'rmagick' # Because rails_admin_jcrop autoload modules by checking plugins you use, it's # recommended to require it explictly before rails_admin_jcrop # e.g. if you use carrierwave gem 'carrierwave', :require => 'carrierwave' # Gems used only for assets and not required # in production environments by default. group :assets do gem 'sass-rails', '~> 3.2.3' gem 'coffee-rails', '~> 3.2.1' gem 'compass-rails' gem 'zurb-foundation' # See https://github.com/sstephenson/execjs#readme for more supported runtimes # gem 'therubyracer', :platforms => :ruby gem 'uglifier', '>= 1.0.3' end group :test do gem 'webrat', '>=0.7.2.pre', :git => 'http://github.com/kalv/webrat.git' gem "database_cleaner" end gem 'jquery-rails' # To use ActiveModel has_secure_password # gem 'bcrypt-ruby', '~> 3.0.0' # To use Jbuilder templates for JSON # gem 'jbuilder' # Use unicorn as the app server # gem 'unicorn' # Deploy with Capistrano # gem 'capistrano' # To use debugger # gem 'debugger' gem 'therubyracer' 来源'https://rubygems.org' gem“轨道”,“3.2.11” 宝石“omniauth” gem'omniauth facebook' 宝石“薄” #而是捆绑边缘轨道: #gem'rails',:git=>'git://github.com/rails/rails.git' 宝石“pg” 宝石“设计” 宝石“rmagick” #因为rails_admin_jcrop通过检查您使用的插件自动加载模块,所以 #建议在rails\u admin\u jcrop之前明确要求它 #例如,如果您使用carrierwave gem'carrierwave',:require=>carrierwave' #仅用于资产的宝石,不需要 #默认情况下,在生产环境中。 集团:资产做什么 gem'sass-rails',“~>3.2.3” gem“咖啡轨”,“~>3.2.1” 宝石“指南针轨道” 创业板“zurb基金会” #看https://github.com/sstephenson/execjs#readme 获取更多受支持的运行时 #gem'therubyracer',:platforms=>:ruby gem'uglifier','>=1.0.3' 结束 组:测试do gem'webrat','>=0.7.2.pre',:git=>'http://github.com/kalv/webrat.git' gem“数据库清理器” 结束 gem'jqueryrails' #要使用ActiveModel,请使用\u安全\u密码 #宝石'bcrypt ruby',“~>3.0.0” #将Jbuilder模板用于JSON #宝石“jbuilder” #使用unicorn作为应用程序服务器 #宝石“独角兽” #使用Capistrano部署 #宝石“capistrano” #使用调试器 #gem“调试器” 宝石“therubyracer” 和test_helper.rb:

ENV["RAILS_ENV"] = "test" require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' # require "webrat" Webrat.configure do |config| config.mode = :rails end class ActiveSupport::TestCase # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order. # # Note: You'll currently still have to declare fixtures explicitly in integration tests # -- they do not yet inherit this setting fixtures :all # include Webrat include Webrat::Methods include Webrat::Matchers # Add more helper methods to be used by all tests here... end class ActionController::TestCase include Devise::TestHelpers end 环境[“RAILS_ENV”]=“测试” 需要文件。展开\u路径('../../config/environment',\u文件\u) 需要“rails/test\u帮助” #需要“网络鼠” Webrat.configure do | config| config.mode=:rails 结束 类ActiveSupport::TestCase #按照字母顺序在test/fixtures/*(yml | csv)中为所有测试设置所有夹具。 # #注意:您当前仍然需要在集成测试中显式地声明fixture #--它们尚未继承此设置 固定装置:全部 #包括网络鼠 包含Webrat::方法 包括Webrat::Matchers #在此处添加所有测试要使用的更多帮助器方法。。。 结束 类ActionController::TestCase include designe::TestHelpers 结束 我的测试是:

require 'test_helper' class UserSignupTest user.first_name fill_in "user_last_name", :with => user.last_name fill_in "user_username", :with => user.username fill_in "user_email", :with => user.email fill_in "user_password", :with => user.password fill_in "user_password_confirmation", :with => user.password_confirmation choose("user_sex_male") click("commit") end end 需要“测试助手” 类UserSignupTest user.first\u name 在“user\u last\u name”中填写:with=>user.last\u name 填写“用户用户名”:with=>user.username 填写“用户电子邮件”:with=>user.email 填写“用户密码”:with=>user.password 填写“用户密码确认”:with=>user.password\u确认 选择(“用户性别男性”) 单击(“提交”) 结束 结束 但当我尝试使用“单击”方法时,我有以下错误:

1) Error: test_sign_up_flow(UserSignupTest): NoMethodError: undefined method `click' for # 1) 错误: 测试\注册\流程(UserSignupTest): NoMethodError:未定义的方法“单击”用于#
你知道我做错了什么吗?我刚刚安装了一个捆绑包,认为它应该可以工作。“单击”方法之前的方法似乎在某种程度上起作用。

只是因为评论越来越频繁,我将此作为答案发布

在您的情况下,因为“提交”是一个按钮,所以您需要使用

click_button("commit")
而不是

click("commit")
如果它是一个链接,您可以使用

click_link("commit")

您可以尝试将test\u助手作为文件包含吗?i、 e.
require./test\u helper.rb'
如果test\u helper.rb在同一目录中。如果我写:require./test\u helper'我得到:'require':无法加载这样的文件--./test\u helper(LoadError)我不确定我是否理解。在这种情况下,请尝试类似这样的操作-
require file.expand\u path('./test\u helper.rb',\u file\uu)
。另外,检查测试助手和测试是否在同一位置。否则,您需要操作此代码以获得正确的相对路径。谢谢——我明天早上会检查。我真的不明白为什么fill_in方法可以工作,但是click不能。Commit是一个按钮吗?在这种情况下,您应该尝试使用
单击按钮
,而不进行我建议的上述更改。这只是因为它变得很健谈--=]--介意我问一个随机的问题吗?我总是需要查找一些东西,但有时我会发现一些人用与所使用的gems和框架相关的代码来回答他们自己的问题。我是编程新手——如果我想达到那样的熟练程度,你有什么建议吗?@wjandali-你最初的问题更容易回答:P.我相信每个人都需要查东西,只是随着时间的推移,会发生两件事——你遇到类似的问题,或者,你学会如何查东西(提示——以“g”开头)。只要你有足够的毅力,我想问题会解决的。