I'm working through Agile Web Development With Rails for Rails 3.0, and I'm at a point where running rake test:functionals gives a successful result.
When I add the following code to my .html.erb and re-run the same command, I get errors all over the place.
Code:
<span>
<% if session[:counter] > 5 %>
You've visited this page <%= pluralize(session[:counter], 'time') %>
<% end %>
</span>
Error:
ActionView::Template开发者_开发问答::Error: undefined method '>' for nil:NilClass
~/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.0.3/lib/active_support/whiny_nil.rb:48:in `method_missing'
It looks like the :counter
member of your session is not being properly set, so session[:counter]
evaluated to nil
. Make sure that you're properly setting your session variables in your test. For example, get(:show, {'id' => "12"}, {'user_id' => 5})
would set session[:user_id]
to 5.
See http://guides.rubyonrails.org/testing.html#functional-tests-for-your-controllers for more info.
精彩评论