Class: Masque

Inherits:
Object
  • Object
show all
Defined in:
lib/masque.rb,
lib/masque/dsl.rb,
lib/masque/version.rb

Defined Under Namespace

Modules: DSL

Constant Summary collapse

VERSION =
"0.3.0"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Masque

Returns a new instance of Masque.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/masque.rb', line 16

def initialize(options = {})
  @options = options
  @driver = options[:driver] || :webkit
  @agent = Class.new do
    include Masque::DSL

    attr_accessor :session

    def initialize(session)
      @session = session
    end

    def method_missing(*args, &block)
      if block_given?
        session.__send__(*args, &block)
      else
        session.__send__(*args)
      end
    end
  end.new(Capybara::Session.new(@driver))

  if @driver == :webkit
    h = Headless.new(options.merge(:destroy_at_exit => false, :reuse => true))
    h.start
    ObjectSpace.define_finalizer(@agent.driver.browser.instance_variable_get(:@connection)) do
      h.destroy
    end
  end
end

Instance Attribute Details

#agentObject (readonly)

Returns the value of attribute agent.



10
11
12
# File 'lib/masque.rb', line 10

def agent
  @agent
end

#optionsObject (readonly)

Returns the value of attribute options.



10
11
12
# File 'lib/masque.rb', line 10

def options
  @options
end

Class Method Details

.run(options = {}, &block) ⇒ Object



12
13
14
# File 'lib/masque.rb', line 12

def self.run(options = {}, &block)
  new(options).run(&block)
end

Instance Method Details

#compat_capybara_1x!Object



65
66
67
68
69
70
# File 'lib/masque.rb', line 65

def compat_capybara_1x!
  Capybara.configure do |config|
    config.match = :prefer_exact
    config.ignore_hidden_elements = false
  end
end

#compat_capybara_20!Object



56
57
58
59
60
61
62
63
# File 'lib/masque.rb', line 56

def compat_capybara_20!
  Capybara.configure do |config|
    config.match = :one
    config.exact_options = true
    config.ignore_hidden_elements = true
    config.visible_text_only = true
  end
end

#reset_session!Object



46
47
48
49
50
# File 'lib/masque.rb', line 46

def reset_session!
  run do
    driver.reset!
  end
end

#run(&block) ⇒ Object



52
53
54
# File 'lib/masque.rb', line 52

def run(&block)
  @agent.instance_eval(&block)
end