使用webrat和Rails3进行集成测试

时间:2011-02-03 14:51:03

标签: ruby-on-rails ruby-on-rails-3 webrat shoulda

我正在将Rails 2.3.5应用升级到Rails 3.0.3。但我的集成测试 不工作。我收到了这个错误:

NoMethodError: undefined method `content_type' for nil:NilClass

归咎于

assert_select "input#artist.title.unsolved", 1

我的webrat的test_helper.rb看起来像这样:

require "webrat"
require 'webrat/core/matchers'
include Webrat::Methods

Webrat.configure do |config|
  config.mode = :rack
end

我正在使用shoulda 2.11.3和webrat 0.7.3进行测试。我读了, webrat和shoulda与Rails3兼容。

任何人都知道如何解决这个问题?

谢谢! TUX

ADDITION

似乎NoMethodError出现在shoulda中,而不是来自Webrat,如标题中所述。这是跟踪:

NoMethodError: undefined method `content_type' for nil:NilClass
    /Users/23tux/.rvm/gems/ruby-1.9.2-p136@rails3/gems/activesupport-3.0.3/lib/active_support/whiny_nil.rb:48:in `method_missing'
    /Users/23tux/.rvm/gems/ruby-1.9.2-p136@rails3/gems/actionpack-3.0.3/lib/action_dispatch/testing/assertions/selector.rb:605:in `response_from_page_or_rjs'
    /Users/23tux/.rvm/gems/ruby-1.9.2-p136@rails3/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/ruby-1.9.2-p136@rails3/gems/shoulda-context-1.0.0.beta1/lib/shoulda/context/context.rb:412:in `call'
    /Users/23tux/.rvm/gems/ruby-1.9.2-p136@rails3/gems/shoulda-context-1.0.0.beta1/lib/shoulda/context/context.rb:412:in `block in run_current_setup_blocks'
    /Users/23tux/.rvm/gems/ruby-1.9.2-p136@rails3/gems/shoulda-context-1.0.0.beta1/lib/shoulda/context/context.rb:411:in `each'
    /Users/23tux/.rvm/gems/ruby-1.9.2-p136@rails3/gems/shoulda-context-1.0.0.beta1/lib/shoulda/context/context.rb:411:in `run_current_setup_blocks'
    /Users/23tux/.rvm/gems/ruby-1.9.2-p136@rails3/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

也许在使用Shoulda的Rails 3中,assert_select不再可用。 希望可以有人帮帮我! THX!

1 个答案:

答案 0 :(得分:1)

有一个webrat的分支可以在https://github.com/joakimk/webrat处使用rails3。在某些时候它应该被拉入主分支。 rails 2.3目前仍然很受欢迎。