Tuesday, 6 August 2013

Capybara: ExpectationNotMet when trying to match contents of a search results div

Capybara: ExpectationNotMet when trying to match contents of a search
results div

So I am writing a Capybara test to verify that the search bar of my
website is working the way I expect it to. The search is written so that
if one looks up something that is not available on the site, it displays
"No Results" in a div named result-columns. I am getting the following
error when I run rspec:
Failure/Error: page.should have_selector(".result-columns", :text => "No
Results")
Capybara::ExpectationNotMet:
expected to find css ".result-columns" with text "No Results" but there
were no matches
I am verifying that in an RSpec file with the following code:
require 'spec_helper'
describe 'Search' , :js => true do
it 'displays no results when non-existent things are looked up' do
visit root_path
page.first(".search-icon-small").click
fill_in "search", with: "NonExistent"
#simulate pressing Enter
keypress ="var e = $.Event('keydown', { keyCode: 13 });
$('body').trigger(e);"
page.driver.execute_script(keypress)
page.should have_selector(".result-columns", :text => "No Results")
end
end
Here is the implementation of the search functionality within the
home_controller
def search
query = params[:search]
@directors= Director.search(query)
@projects = Project.search(query)
@clients = Client.search(query)
@director_results = make_pages(@directors)
@project_results = make_pages(@projects)
@client_results = make_pages(@clients)
render partial: 'search_results'
end
Here is the search_results.html.haml partial that is rendered on the home
page:
.shane-box-center(style="width:100%; height:100%; margin-top:20px;")
.shane-inside-center(style="float:left; position:relative; width:100%;
height:100%;")
.result-columns
- if @project_results.empty? && @client_results.empty? &&
@director_results.empty?
= render 'search_no_results'
- else
= render 'search_results_column', results_pages: @director_results
= render 'search_results_column', results_pages: @client_results
= render 'search_results_column', results_pages: @project_results
Here is the search_no_results.html.html that is rendered by the above partial
%ul
%li(style="cursor:default")
%img(src="/assets/logotest.png")
%p
No Results
I would appreciate any help you could proffer my humble self! Thank you
kindly.

No comments:

Post a Comment