我有一個Gemfile中:新來的Rails - 在集成測試工作不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 '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'
而且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
我的測試是:
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
但是當我嘗試使用「點擊」方法時,我遇到以下錯誤:
1) Error: test_sign_up_flow(UserSignupTest): NoMethodError: undefined method `click' for #
你知道我在做什麼錯嗎?我只是捆綁安裝,並認爲它應該工作。 'click'方法之前的方法似乎以某種方式工作。
你可以嘗試包括test_helper作爲一個文件嗎?即如果test_helper.rb位於同一個目錄中,則'require'。/ test_helper.rb'。 – 2013-03-09 08:23:47
如果我寫: 需要 './test_helper' 我得到: '需要':無法加載這樣的文件 - ./test_helper(LoadError) 不知道我理解。 – wjandali 2013-03-09 09:17:14
在這種情況下,嘗試像這樣 - '需要File.expand_path('./ test_helper.rb',__FILE __)''。另外,檢查test_helper和測試是否在同一個位置。否則,您需要操作此代碼以擁有正確的相對路徑。 – 2013-03-09 09:41:34