Created
August 11, 2013 14:29
-
-
Save rogercampos/6205137 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def save_screenshot(path = nil) | |
path ||= "capybara-#{Time.new.strftime("%Y%m%d%H%M%S")}#{rand(10**10)}.png" | |
path = File.expand_path(path, Capybara.save_and_open_page_path) if Capybara.save_and_open_page_path | |
FileUtils.mkdir_p(File.dirname(path)) | |
super(path, full: true) | |
path | |
end | |
def shoot(opts = {}) | |
raise ArgumentError, "must give a block" unless block_given? | |
yield | |
name = opts[:name] || current_path | |
path = save_screenshot | |
conn = Faraday.new('http://shooter.camaloon.com/') do |f| | |
f.request :multipart | |
f.request :url_encoded | |
f.adapter :net_http | |
end | |
payload = { | |
page: name, | |
image: Faraday::UploadIO.new(path, 'image/jpeg'), | |
api_token: "<api token>" | |
} | |
conn.post("/api/snapshots", payload) | |
end | |
def shoot_all_paths(*args) | |
args.flatten.compact.each do |path| | |
shoot { visit send("#{path}_path") } | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# spec_helper.rb | |
Capybara.register_driver :poltergeist_for_shooter do |app| | |
Capybara::Poltergeist::Driver.new(app, | |
window_size: [1280, 1024], | |
phantomjs_options: ['--ignore-ssl-errors=yes']) | |
end | |
# spec/shoots_spec.rb | |
describe "shoots", type: :feature, js: true, driver: :poltergeist_for_shooter do | |
it { | |
shoot { visit root_path } | |
shoot_all_paths %w(about_us shipping_info) | |
} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment