Skip to content

Instantly share code, notes, and snippets.

View abotalov's full-sized avatar

Andrei Botalov abotalov

View GitHub Profile
@abotalov
abotalov / first.rb
Last active August 29, 2015 13:57
Check performance of first, match: :first
require 'capybara'
require 'benchmark'
html = DATA.read
$app = proc { |env| [200, { "Content-Type" => "text/html" }, [html] ] }
def benchmark_average
sum = 0
session = Capybara::Session.new(:selenium, $app)
@abotalov
abotalov / check_racktest_text.rb
Created May 20, 2014 21:33
Check speed of text in rack_test
require 'capybara'
require 'benchmark'
[
'http://www.stackoverflow.com',
'http://www.google.com',
'http://www.facebook.com',
'http://www.github.com',
].each do |url|
sess = Capybara::Session.new(:selenium)
require 'capybara'
require 'benchmark'
html = DATA.read
$app = proc { |env| [200, { "Content-Type" => "text/html" }, [html] ] }
session = Capybara::Session.new(:selenium, $app)
session.visit("/")
puts "Capybara text: #{session.all('div').map { |el| el.text.codepoints }}" # => [[97, 32, 98], [97, 32, 98], [97, 32, 98]]
require 'capybara'
require 'benchmark'
html = DATA.read
$app = proc { |env| [200, { "Content-Type" => "text/xml" }, [html] ] }
session = Capybara::Session.new(:selenium, $app)
session.visit("/")
puts "Capybara text: #{session.all('div').map { |el| el.text.codepoints }}" # => [[97, 32, 98], [97, 32, 98], [97, 32, 98]]
@abotalov
abotalov / autoreply_to_mail.feature
Created March 3, 2012 22:14
Send mail features
Feature: Autoreply to mail
In order to say that I'm not able to respond to emails
I want to be able to setup autoreply
Background:
Given I am logged in
And another user exists
Scenario: System sends autoreply when autoreply is enabled
Given I have autoreply enabled
@abotalov
abotalov / user.rb
Created March 28, 2012 20:51
Your code
class User
attr_accessor :name, :password
def initialize new = {}
hash = {:name => "name", :password => "password"}
hash.merge! new
hash.each {|name, value| instance_variable_set("@#{name}", value)}
end
@abotalov
abotalov / email.rb
Created March 30, 2012 18:11
How to make this code DRY?
class Email
attr_accessor :recipients, :subject, :body
def initialize(options = {})
hash = {recipients: %w(localpart@site.com), subject: 'Subject', body: 'Body'}
hash.merge!(options)
hash.each {|name, value| instance_variable_set("@#{name}", value)}
end
@abotalov
abotalov / env.rb
Created April 1, 2012 11:20
говнокод
require 'capybara/cucumber'
require 'rspec'
require_relative 'user'
scheme = 'https'
$domain_name = 'testwww.confidesk.com'
$user = User.new(username: 'user31', password: 'user31')
$user2 = User.new(username: 'user41', password: 'user41')
@abotalov
abotalov / output.txt
Created August 2, 2012 18:27
Output of Capybara.methods.sort
[:!, :!=, :!~, :<, :<=, :<=>, :==, :===, :=~, :>, :>=, :__id__, :__send__, :acts_like?, :add_selector,
:alias_attribute, :alias_method_chain, :all, :ancestors, :anonymous?, :app, :app=, :app_host, :app_host=, :as_json, :asset_root, :asset_root=, :attac
h_file, :autoload, :autoload?, :automatic_reload, :automatic_reload=, :blank?, :body, :capture, :check, :choose, :class, :class_eval, :class_exec, :cl
ass_variable_defined?, :class_variable_get, :class_variable_set, :class_variables, :click_button, :click_link, :click_link_or_button, :click_on, :clon
e, :configure, :const_defined?, :const_get, :const_missing, :const_set, :constants, :cucumber_instance_exec, :current_driver, :current_driver=, :curre
nt_host, :current_path, :current_session, :current_url, :default_driver, :default_driver=, :default_host, :default_host=, :default_selector, :default_
selector=, :default_wait_time, :default_wait_time=, :define_singleton_method, :delegate, :deprecate, :display, :drivers, :dup, :duplicable?, :enable_w
arnings, :enum_
@abotalov
abotalov / gist:3255493
Created August 4, 2012 07:31
Fix broken link
There are a lot of posts at SO that have link http://particletree.com/features/rediscovering-the-button-element/. (https://www.google.com/search?q=site%3Astackoverflow.com%2Fquestions+http%3A%2F%2Fparticletree.com%2Ffeatures%2Frediscovering-the-button-element%2F).
Link is obsolete so it should be fixed to http://web.archive.org/web/20110721191046/http://particletree.com/features/rediscovering-the-button-element/
But number of such posts is quite large so I think fixing all of them myself can be considered unfair. I think all those links should be edited automatically NOT by the user of site, e.g. by Community user.