我正在升级Rails 2.3.5应用程序到Rails 3.0.3。但我的集成测试 无法正常工作。与webrat和Rails3集成测试
require "webrat"
require 'webrat/core/matchers'
include Webrat::Methods
Webrat.configure do |config|
config.mode = :rack
end
我使用早该2.11:我得到这个错误:
NoMethodError: undefined method `content_type' for nil:NilClass
线责怪是
assert_select "input#artist.title.unsolved", 1
我对webrat test_helper.rb中看起来喜欢这一点。 3和webrat 0.7.3进行测试。我读过, webrat和shoulda与Rails3兼容。
任何一个想法如何解决这个问题?
谢谢! 礼服
加成:
看来,该NoMethodError出现从早该,而不是从Webrat,在标题中提到的。下面是跟踪:
NoMethodError: undefined method `content_type' for nil:NilClass
/Users/23tux/.rvm/gems/[email protected]/gems/activesupport-3.0.3/lib/active_support/whiny_nil.rb:48:in `method_missing'
/Users/23tux/.rvm/gems/[email protected]/gems/actionpack-3.0.3/lib/action_dispatch/testing/assertions/selector.rb:605:in `response_from_page_or_rjs'
/Users/23tux/.rvm/gems/[email protected]/gems/actionpack-3.0.3/lib/action_dispatch/testing/assertions/selector.rb:213:in `assert_select'
test/integration/user_integration_test.rb:52:in `block (3 levels) in <class:UserIntegrationTest>'
/Users/23tux/.rvm/gems/[email protected]/gems/shoulda-context-1.0.0.beta1/lib/shoulda/context/context.rb:412:in `call'
/Users/23tux/.rvm/gems/[email protected]/gems/shoulda-context-1.0.0.beta1/lib/shoulda/context/context.rb:412:in `block in run_current_setup_blocks'
/Users/23tux/.rvm/gems/[email protected]/gems/shoulda-context-1.0.0.beta1/lib/shoulda/context/context.rb:411:in `each'
/Users/23tux/.rvm/gems/[email protected]/gems/shoulda-context-1.0.0.beta1/lib/shoulda/context/context.rb:411:in `run_current_setup_blocks'
/Users/23tux/.rvm/gems/[email protected]/gems/shoulda-context-1.0.0.beta1/lib/shoulda/context/context.rb:393:in `block in create_test_from_should_hash'
,这里是围绕assert_select整个模块背景:
class SongIntegrationTest < ActionController::IntegrationTest
context "a visitor" do
context "solving a song" do
setup do
@song = Song.make
visit song_path(@song)
end
should "have two guess fields" do
assert_select "input#artist.title.unsolved", 1
assert_select "input#title.title.unsolved", 1
end
也许assert_select是不再与早该Rails 3中可用。 希望有人能帮助我! thx!
我发现,也许错误来自webrat,覆盖assert_select方法: https://webrat.lighthouseapp.com/projects/10503/tickets/395-assert_select-not-working-with-rails-300 -due-to-webrat 但上面的链接显示的修复程序不起作用(并顺便说一句,我没有使用黄瓜)。 有人有想法吗? – 23tux 2011-02-08 10:34:21