RSpec View testing: How to modify params?
        Posted  
        
            by 
                sebastiangeiger
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by sebastiangeiger
        
        
        
        Published on 2009-11-26T10:03:07Z
        Indexed on 
            2011/03/18
            0:10 UTC
        
        
        Read the original article
        Hit count: 229
        
ruby-on-rails
|rspec
I am trying to test my views with RSpec. The particular view that is causing me troubles changes its appearance depending on a url parameter:
link_to "sort>name", model_path(:sort_by => 'name') which results in http://mydomain/model?sort_by=name
My view then uses this parameter like that:
<% if params[:sort_by] == 'name' %>
<div>Sorted by Name</div>
<% end %>
The RSpec looks like this:
it "should tell the user the attribute for sorting order" do
    #Problem: assign params[:sort_for] = 'name' 
    render "/groups/index.html.erb"
    response.should have_tag("div", "Sorted by Name")
end
I would like to test my view (without controller) in RSpec but I can't get this parameter into my params variable. I tried assign in all different flavours:
- assign[:params] = {:sort_by => 'name'}
- assign[:params][:sort_by] = 'name'
- ...
no success so far. Every idea is appreciated.
© Stack Overflow or respective owner