J'essaye d'écrire un test rspec pour un contrôleur qui accède à un groupe modèle .foo_url (mock_foo) ne fonctionne parfois pas dans les tests rspec
@request.env['HTTP_REFERER'] = group_url(@mock_group) ### Line 49
Je reçois ceci:
NoMethodError in 'ActsController responding to create should redirect to :back' You have a nil object when you didn't expect it! The error occurred while evaluating nil.rewrite /Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:621:in `url_for' (eval):17:in `group_url' /Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_controller/test_process.rb:464:in `send!' /Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_controller/test_process.rb:464:in `method_missing'
Cette ligne url_for est le problème; specifiquement @url est nul.
@url.rewrite(rewrite_options(options))
Et il semble que @url est initialisé ici: Regardez
def initialize_current_url @url = UrlRewriter.new(request, params.clone) end