TheWebs
TheWebs

Reputation: 12923

capybara is acting weird - "click_link" is undefined

Seems all of capybaras methods are magically undefined. I am trying to stub out some tests for TDD and I wrote the following test:

  it "sign in and fail" do
    click_link "login"
    fill_in "User Name", :with => "Test"
    fill_in "Password", :with => "test"
    click_button "sign in"
    page.should have_content("User does not exist. Pleae try registering in.")
  end

It should freak out on click_link, only because no such link exists, instead it freaks out saying:

NoMethodError:
       undefined method `click_link'

So I checked my gem file:

gem "rspec-rails", :group => [:test, :development]
group :test do
    gem "factory_girl_rails"
    gem "capybara"
    gem "guard-rspec"
    gem 'database_cleaner'
    gem "launchy"
end

And then I checked my pec helper, and yes I have:

require 'capybara/rspec'
require 'capybara/rails'

So what’s with the undefined method error when ever guard runs? It should be telling me "um there’s no link for me to click..." not "I don’t know what click_link" is. It freaks out on visit, click_button, contains and so on.

a far as I know capybara is installed correctly....

Upvotes: 3

Views: 1250

Answers (1)

Farooq
Farooq

Reputation: 1995

Try putting this in your env.rb:

include Capybara::DSL

And then run the test

Upvotes: 1

Related Questions