Domanda

Sto cercando di capire il motivo per cui questo test sta venendo a mancare. (Sono una specie di nuovo al test.) Sto utilizzando il framework di test Rails integrato con l'aggiunta della gemma Shoulda.

Il test:

require 'shoulda'

context "on GET to :new" do

  setup do
    get(:new)
  end

  should_render_template :new
  should_not_set_the_flash

end

Fallisce:

1) Failure:
test: on GET to :new should render template :new. (SessionsControllerTest)
[/usr/local/lib/ruby/gems/1.8/gems/thoughtbot-shoulda-2.0.6/lib/shoulda/controller   /macros.rb:220:in `__bind_1233882600_699194'
/usr/local/lib/ruby/gems/1.8/gems/thoughtbot-shoulda-2.0.6/lib/shoulda/context.rb:254:in `call'
/usr/local/lib/ruby/gems/1.8/gems/thoughtbot-shoulda-2.0.6/lib/shoulda/context.rb:254:in `test: on GET to :new should render template :new. '
/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/testing/setup_and_teardown.rb:94:in `__send__'
/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/testing/setup_and_teardown.rb:94:in `run']:
expecting <"new"> but rendering with <"">

2 tests, 2 assertions, 1 failures, 0 errors

Ma se lo faccio funzionare sulla console con app.get '/sessions/new' funziona benissimo senza errori.

E il modello "new" rende come previsto nel browser.

sto usando Haml. Forse che sta causando un problema. Il mio modello è chiamato "new.html.haml".

È stato utile?

Soluzione

Il fallimento dice che nessun modello è stato reso. Cercare di assicurarsi che non per essere reindirizzato con

should_respond_with :success

e far valere il contenuto della @ response.body solo per vedere ciò che è stato inviato indietro

# This will fail but should give you some clue about what was sent back.
should "sent something back in the body" do
  assert_match 'boohooo', @response.body
end

Si può anche affermare un modello specifico, in modo da poter dare un colpo, troppo:

should_render_template "new.html.haml"

Comunque, io non sospetto HAML essere la causa del problema.

Altri suggerimenti

ho avuto un problema simile con Shoulda, Liquidazione, e Rails 2.3.2. Credo di aver risolto il problema modificando il modo shoulda e la clearance uso 'assert_template'. Pare che ci sia un bug aperto in Rails relative a questo.

Si prega di consultare questo thread per maggiori informazioni e il mio diff dei cambiamenti (un cambio di line sia in Liquidazione e Shoulda).

http://groups.google.com/group/shoulda/browse_thread / thread / 8c0a66c80ff4fd76

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top