Tom
Tom

Reputation: 1105

Using Capybara within a Ruby class

I'm just experimenting a little with Cucumber and Capybara.

I'm writing a class that will perform some user admin for me.

I have the following class:

  class UserAdmin

  def initialize(data)
    @data = data
  end

  def add_user
    require 'rspec/expectations'
    require 'capybara/cucumber'
    require 'capybara/helpers'

    @data.hashes.each do |user_details|
      load_user_data(user_details)

    fill_in('firstname', with: @first_name)
    fill_in('surname', with: @last_name)
    fill_in('username', with: @new_username)
    fill_in('usernameConfirmation', with: @confirm_new_username)

    click_button_add_user

    end
  end

When I try and create an instance of this class, I get `NoMethodError: undefined method fill_in' for #

I thought by requieing Capybara etc, I could use their methods in my class.

Clearly I'm wrong, could anyone point out where I've gone wrong please?

Upvotes: 0

Views: 262

Answers (1)

Andrey Deineko
Andrey Deineko

Reputation: 52357

You should include Capybara::DSL:

require 'capybara/dsl'

class UserAdmin
  include Capybara::DSL
  Capybara.run_server = false
  # ...
end

Upvotes: 2

Related Questions