运行我的测试时,javascript 没有被执行。我尝试从 :selenium 驱动程序切换到 :webkit 驱动程序,但仍然没有运气。
它在浏览器中运行良好。当测试运行并打开页面时,页面为空白
我还需要做些什么来让它在测试运行期间执行 javascript 吗?
business_integration_test.rb
require 'minitest_helper'
require 'ruby-debug'
describe "Business integration" do
before :each do
@business = Factory.build(:business)
Capybara.javascript_driver = :webkit
end
it "Should show error if business name is blank" do
visit admin_business_path
fill_in 'Name', :with => ''
click_button 'Save'
page.save_and_open_page
page.text.must_include("can't be blank")
end
end
企业控制器.rb
class Admin::BusinessesController < Admin::AdminController
def update
@business = resource
respond_to do |format|
if @business.update_attributes(params[:business])
flash[:notice] = "Your business was updated successfully."
else
flash[:notice] = "Your business failed to update."
end
format.js { render :template => "admin/businesses/edit" }
end
end
end
编辑.js.erb
$("#page-businesses #main").html("<%= escape_javascript(render :partial => 'edit_information') %>");