ruby-on-railstestingracktestunitwebrat

New to Rails -- Webrat methods not working in integration test


I have a Gemfile:


        source 'https://rubygems.org'

    gem 'rails', '3.2.11'
    gem 'omniauth'
    gem 'omniauth-facebook'

    gem 'thin'
    # Bundle edge Rails instead:
    # gem 'rails', :git => 'git://github.com/rails/rails.git'

    gem 'pg'

    gem 'devise'
    gem 'rmagick'


    # Because rails_admin_jcrop autoload modules by checking plugins you use, it's
    # recommended to require it explictly before rails_admin_jcrop
    # e.g. if you use carrierwave
    gem 'carrierwave', :require => 'carrierwave'

    # Gems used only for assets and not required
    # in production environments by default.
    group :assets do
      gem 'sass-rails',   '~> 3.2.3'
      gem 'coffee-rails', '~> 3.2.1'

      gem 'compass-rails'
      gem 'zurb-foundation'

      # See https://github.com/sstephenson/execjs#readme for more supported runtimes
      # gem 'therubyracer', :platforms => :ruby

      gem 'uglifier', '>= 1.0.3'
    end

    group :test do
      gem 'webrat', '>=0.7.2.pre', :git => 'http://github.com/kalv/webrat.git' 
      gem "database_cleaner"
    end

    gem 'jquery-rails'

    # To use ActiveModel has_secure_password
    # gem 'bcrypt-ruby', '~> 3.0.0'

    # To use Jbuilder templates for JSON
    # gem 'jbuilder'

    # Use unicorn as the app server
    # gem 'unicorn'

    # Deploy with Capistrano
    # gem 'capistrano'

    # To use debugger
    # gem 'debugger'
    gem 'therubyracer'

And test_helper.rb:

 

        ENV["RAILS_ENV"] = "test"
    require File.expand_path('../../config/environment', __FILE__)
    require 'rails/test_help'
    # require "webrat"


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


    class ActiveSupport::TestCase
      # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
      #
      # Note: You'll currently still have to declare fixtures explicitly in integration tests
      # -- they do not yet inherit this setting
      fixtures :all
    #   include Webrat
      include Webrat::Methods
      include Webrat::Matchers
      # Add more helper methods to be used by all tests here...
    end

    class ActionController::TestCase
      include Devise::TestHelpers
    end

My test is:

 

        require 'test_helper'

    class UserSignupTest  user.first_name
        fill_in "user_last_name", :with => user.last_name
        fill_in "user_username", :with => user.username
        fill_in "user_email", :with => user.email
        fill_in "user_password", :with => user.password
        fill_in "user_password_confirmation", :with => user.password_confirmation
        choose("user_sex_male") 
        click("commit")
      end

    end

But I have the following errors when I try to use the 'click' method:

  

         1) Error:
    test_sign_up_flow(UserSignupTest):
    NoMethodError: undefined method `click' for #

Do you have an idea what I'm doing wrong? I just bundle installed and thought it should work. The methods preceding the 'click' method seem to work somehow.


Solution

  • Just because the comments are getting chatty, I am posting this as an answer.

    Webrat Resources and references.

    In your case, since 'Commit' is a button, you need to use

    click_button("commit")
    

    instead of

    click("commit")
    

    If it were a link, you can use

    click_link("commit")