我想了解爲什麼這個測試失敗。 (我對測試很陌生。)我使用了內置的Rails測試框架,並添加了Shoulda gem。爲什麼這個Rails控制器測試失敗?
測試:
require 'shoulda'
context "on GET to :new" do
setup do
get(:new)
end
should_render_template :new
should_not_set_the_flash
end
失敗:
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
但如果我app.get '/sessions/new'
控制檯上運行它,它工作正常,沒有錯誤。
而「new
」模板按預期在瀏覽器中呈現。
我正在使用Haml。也許這是造成問題的原因。我的模板被稱爲「new.html.haml
」。
謝謝。你建議你調用assert_match來解決它。我已經忘記了之前的一個過濾器搞亂了事情。 – Ethan 2009-02-06 07:07:59