2011-02-03 79 views
2

我正在升級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!

+0

我發現,也許錯誤來自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

回答

1

有一個webrat的分支,可以在https://github.com/joakimk/webrat與rails3一起使用。在某個時候,它應該被拉進主分支。 rails 2.3在這個時候仍然非常流行。

+0

Thx爲您的答案!但我決定使用水豚而不是網絡。它在Rails3中工作正常,並且測試對於水豚的重寫並不那麼困難 – 23tux 2011-02-13 19:22:18