【发布时间】:2014-12-24 12:46:11
【问题描述】:
我有一个奇怪的问题。我的功能测试如下所示: 需要“rails_helper”
feature "Doctors" do
let(:ordering_unit) { build(:ordering_unit, name: "Test ordering unit") }
let!(:doctor) { create(:doctor, fullname: "Doctor", specialization: "Specialization", ordering_unit: ordering_unit)}
let!(:doctor2) { create(:doctor, fullname: "Test doctort", specialization: "Test specialization") }
before { visit doctors_path }
feature "Searching" do
scenario "Should find proper doctors", js: true do
fill_in "search_form_query", with: "Test"
expect(page).to have_text(doctor2.fullname)
expect(page).to_not have_text(doctor1.fullname)
save_and_open_page
end
end
这个测试负责测试索引页面上的ajax搜索。但问题是,当我运行这个测试时,我的 Firefox 窗口正在打开,并且在索引页面上没有显示任何医生。但是当我删除“js:true”选项并使用“save_and_open_page”检查页面时,两个医生在索引页面上。有什么问题? 我的 rails_helper.rb
ENV["RAILS_ENV"] ||= 'test'
require 'spec_helper'
require File.expand_path("../../config/environment", __FILE__)
require 'capybara'
require 'rspec/rails'
require 'capybara/rspec'
ActiveRecord::Migration.maintain_test_schema!
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
RSpec.configure do |config|
config.include FactoryGirl::Syntax::Methods
config.include Capybara::DSL
config.before(:suite) do
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
config.infer_spec_type_from_file_location!
end
【问题讨论】:
标签: ruby-on-rails selenium rspec capybara