Module: CapybaraScreenshotIdobata::DSL

Defined in:
lib/capybara_screenshot_idobata/dsl.rb

Instance Method Summary collapse

Instance Method Details

#detect_default_option(driver) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/capybara_screenshot_idobata/dsl.rb', line 33

def detect_default_option(driver)
  case driver
  when :poltergeist
    {full: true}
  else
    {}
  end
end

#save_screenshot_and_post_to_idobata(filename = "screenshot-#{Time.now.to_i}.png", options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/capybara_screenshot_idobata/dsl.rb', line 6

def save_screenshot_and_post_to_idobata(filename = "screenshot-#{Time.now.to_i}.png", options = {})
  raise 'missing config `CapybaraScreenshotIdobata.hook_url`' unless CapybaraScreenshotIdobata.hook_url

  options = detect_default_option(Capybara.current_driver).merge(options)

  save_screenshot filename, options

  absolute_filepath, line = caller[0].split(':')

  filepath = Pathname(absolute_filepath).relative_path_from(Pathname(Dir.pwd))

  source = CapybaraScreenshotIdobata.message_formatter.call(filepath, line, self)

  File.open(filename, 'rb') do |file|
    RestClient.post(CapybaraScreenshotIdobata.hook_url,
      {
        source: source,
        format: CapybaraScreenshotIdobata.message_format,
        image:  file
      },
      {
        'User-Agent' => "CapybaraScreenshotIdobata/v#{CapybaraScreenshotIdobata::VERSION}"
      }
    )
  end
end