Webrat installed but not working

Hello,

I am following the Ruby on Rails Tutorial
(http://ruby.railstutorial.org/) and i can’t run the integration tests
using webrat (visit and click_link method for example). However, I am
using the default Test::Unit rather than RSpec but I don’t think that is
an issue.

I have the following error when I run the integration tests :
NoMethodError: undefined method `visit’ for
#LayoutLinksTest:0x7f135554

Here are the important files involving webrat :

[Gemfile]
source ‘http://rubygems.org
gem ‘rails’, ‘3.0.12’
gem ‘sqlite3’, ‘1.3.3’
group :development do
gem ‘annotate’, ‘2.4.0’
end
group :development, :test do
gem ‘redgreen’
gem ‘webrat’ , ‘0.7.1’
end

I used ‘bundle install’.

[test_helper.rb]
ENV[“RAILS_ENV”] = “test”
require File.expand_path(‘…/…/config/environment’, FILE)
require ‘rails/test_help’
require ‘redgreen’
require ‘webrat’
Webrat.configure do |config|
config.mode = :rails
end
class ActiveSupport::TestCase
fixtures :all
end

[layout_links_test.rb]
require ‘test_helper’
class LayoutLinksTest < ActionDispatch::IntegrationTest
fixtures :all

Some tests.

test “should have the right links on the layout” do
visit root_path # Here it crashes.
assert_select ‘title’, “Ruby on Rails Tutorial Sample App | Home”
# Others assertitions
end
end

As you can see, I installed the gem, included webrat in the test helper
file and ran a simple test using webrat but it doesn’t work…

I don’t know where I made a mistake and any help would be appreciated.

Thank you!

So, I found the solution on another site and I share it here in case
someone gets stuck too.

In test_helper.rb, I replaced
config.mode = :rails
by
config.mode = :rack
and it works now.