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
-------------------

The controller has the following:
@news_months = @news.group_by { |t| t.created_at.beginning_of_month }

And the viewer has:
<% @news_months.each do |month, items| -%>
  <h3><%= month.strftime('%B %Y')%></h3>
  <ul>
  <% for item in items %>
    <li><%=link_to item.title, news_page_path(item) %></li>
  <% end -%>
  </ul>
<% end -%>

Error says:
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.each

Now, once again, I understand the error. What I don't know is how to
change the test so it can see each news item.


3. This is more a theoretical question but I wanted your advice on how
much should I test for? how small a detail should I test for?


I know the above are a lot of questions. Really appreciate your help.

Thanks,
Elle

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to