Class: Capybara::Apparition::Console

Inherits:
Object
  • Object
show all
Defined in:
lib/capybara/apparition/console.rb

Instance Method Summary collapse

Constructor Details

#initialize(logger = nil) ⇒ Console

Returns a new instance of Console.



5
6
7
8
# File 'lib/capybara/apparition/console.rb', line 5

def initialize(logger = nil)
  @logger = logger
  @messages = []
end

Instance Method Details

#clearObject



15
16
17
# File 'lib/capybara/apparition/console.rb', line 15

def clear
  @messages.clear
end

#log(type, message, **options) ⇒ Object



10
11
12
13
# File 'lib/capybara/apparition/console.rb', line 10

def log(type, message, **options)
  @messages << OpenStruct.new(type: type, message: message, **options)
  @logger&.puts "#{type}: #{message}"
end

#messages(type = nil) ⇒ Object



19
20
21
22
23
# File 'lib/capybara/apparition/console.rb', line 19

def messages(type = nil)
  return @messages if type.nil?

  @messages.select { |msg| msg.type == type }
end