Sha256: 5cc83e3bf34f3443576f7219c4e42561d46dd659979dfc6b771f0dcfcf368cb1

Contents?: true

Size: 1.2 KB

Versions: 2

Compression:

Stored size: 1.2 KB

Contents

require 'capybara/rails' if Bbq.rails?
require 'capybara/dsl'
require 'securerandom'
require 'bbq/util'
require 'bbq/test_user/eyes'
require 'bbq/test_user/within'

module Bbq
  class TestUser
    if Bbq.rails?
      include ActionDispatch::Routing::UrlFor
      include Rails.application.routes.url_helpers
      include ActionDispatch::Routing::RouteSet::MountedHelpers unless Rails.version < "3.1"
    end
    include Capybara::DSL
    include Bbq::TestUser::Eyes
    include Bbq::TestUser::Within

    attr_reader :options

    def initialize(options = {})
      @session_name = options.delete(:session_name)
      @current_driver = options.delete(:driver)
      @options = options
    end

    def page
      Capybara.using_driver(current_driver) do
        Capybara.using_session(session_name) do
          Capybara.current_session
        end
      end
    end

    # Discuss: Shall we freeze ?
    def session_name
      @session_name ||= SecureRandom.hex(8)
    end

    # Discuss: Shall we freeze ?
    def current_driver
      @current_driver
    end

    def roles(*names)
      names.each do |name|
        module_obj = Bbq::Util.find_module(name, self)
        self.extend(module_obj)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bbq-0.0.4 lib/bbq/test_user.rb
bbq-0.0.3 lib/bbq/test_user.rb