Hello,
I'm trying to write a couple of tests but keep getting errors or failures and I really think it is because I am making a mistake writing the test, rather than the actual app (just cause it works when I check it). Anyhow, here goes.
1. I am using EasySearch plugin. When I try to test that search works fine, I did: def searches_for_foo foo = Search.products.with("foo") get '/catalog/search' assert_response :success assert_template "search" assert_equal 1, Search.products.with("foo").size assert_tag :tag => "h1", :content => "Search Results for #{foo}" assert_tag :tag => "a", :attributes => { :href => "/catalog/# {foo.id}"} end
And in the catalog controller: def search @search_results = Search.products.with(params[:search_string]) unless @search_results.size > 0 flash.now[:notice] = "No products found matching your criteria" end end
Error says: Expected response to be a <:success>, but was <500> <"You have a nil object when you didn't expect it!\nThe error occurred while evaluating nil.match">
I understand that it does not see the phrase I am searching for. Because I get the same error is I go to /catalog/search manually. But I don't know how to: a) fix the test b) fix the controller so I will not see this exception page
2. I have a model for pages with a column whether it is a news pages or not (boolean) My test is: def views_news get "/news" assert_response :success assert_template "index" @news_months.each do |month, items| assert_tag :tag => "h3", :content => month for item in items assert_tag :tag => "li", :content => item.title end end check_news_links end