I have a form that is set to :remote => truewith two submit buttons (one for "Test Connection", one for creating / updating). My controller handles this correctly and displays the correct view based on the button clicked.
I have the following integration test to make sure that if the data source can connect, it will show the correct message to the user:
describe "Data Source Validation", :js => true do
before (:each) do
@user = create_logged_in_user
end
it "returns true when data source is valid" do
DataSource.any_instance.stub(:can_connect).and_return(true)
visit new_data_source_path
fill_in "Name", :with => "Example 123"
fill_in "Host", :with => "myip.example.com"
select "SQL Server", :from => "Database type"
fill_in "Database name", :with => "Example"
fill_in "Username", :with => "user"
fill_in "Password", :with => "password"
click_button "Test Connection"
expect(page).to have_content "Successfully connected to database"
end
end
I use gem "capybara-webkit"and I defined Capybara.javascript_driver = :webkitin spec_helper.rb.
When the test passes, I get the following result:
Failure/Error: expect(page).to have_content "Successfully connected to database"
expected to find text "Successfully connected to database" in ...
When I view it in Chrome, it works exactly as I expect, with the correct error message.
How can I pass this test condition?
data_source_controller.rb, " "
begin
if @data_source.valid? && @data_source.can_connect?
format.js {render "valid_connection" }
else
format.js {render "invalid_connection" }
end
rescue Exception => e
format.js {render "invalid_connection", locals: {error_msg: e.message} }
end
# 1
javascript : . wait_for_ajax :
Failure/Error: wait_for_ajax
Capybara::Webkit::InvalidResponseError:
Javascript failed to execute
webkit /:
Failure/Error: expect(page).to have_content "Successfully connected to database"
expected to find text "Successfully connected to database" in "Dashboard Reports Data Sources Account Create a New Data Source * Name * Host Port * Database type * Database name * Username * Password We encrypt all information in the database. Nothing can be retrieved without the proper credentials and encryption key. Copyright 2013"
, " " "" " "
, , github, ,