Skip to content

Instantly share code, notes, and snippets.

View suchov's full-sized avatar
🌎
Evolution through Education

Artem Sychov suchov

🌎
Evolution through Education
View GitHub Profile
@suchov
suchov / NERDTree.mkd
Created November 13, 2015 10:06 — forked from m3nd3s/NERDTree.mkd
My Vim Cheat Sheet

NERDTree

o.......Open files, directories and bookmarks....................|NERDTree-o|
go......Open selected file, but leave cursor in the NERDTree.....|NERDTree-go|
t.......Open selected node/bookmark in a new tab.................|NERDTree-t|
T.......Same as 't' but keep the focus on the current tab........|NERDTree-T|
i.......Open selected file in a split window.....................|NERDTree-i|
gi......Same as i, but leave the cursor on the NERDTree..........|NERDTree-gi|
s.......Open selected file in a new vsplit.......................|NERDTree-s|
gs......Same as s, but leave the cursor on the NERDTree..........|NERDTree-gs|

O.......Recursively open the selected directory..................|NERDTree-O|

@suchov
suchov / gist:7263330
Created November 1, 2013 10:05
RoR Course JS task
Задача №1
Напишите реализацию функции getObject(path, obj), которая вернет значение аттрибута объекта obj по заданному пути:
var o = {a: {b: ‘c’}};
getObject(‘a.b’, o) // ‘c’
getObject(‘a’, o) // {b: ‘c’}
getObject(‘d’, o) // undefined
Задача №2
Напишите реализацию конструктора, принимающего на вход объект и создающего аттрибуты\методы по ключам этого объекта:
Task:
Implement site with main page + login page (using DM, of course).
Given user comes to site
When he navigates to /login
Then he sees inputs for login and password with button 'sign up'
Given user on login page
When he enters his name & password
When there's record of him in db and pass/login match
Our scenarios:
scenario "create a new todo" do
sign_in_as "person@example.com"
todo = todo_on_page
todo.create
expect(todo).to be_visible
end
@suchov
suchov / no_sleep
Last active April 11, 2017 16:55
Don't use sleep or wait:
This breaks if we try to test via Capybara:
first(".modal-open").click
first(".confirm").click
It will click the button but the next interaction will fail because the modal hasn’t finished loading.
We could add a sleep here in the test but this would slow the test down a lot and won’t guarantee that the modal is loaded.
Luckily, Capybara provides some helpers for this exact situation.
Finders such as `first` or `all` return `nil` if there is no such element.
`find` on the other hand will keep trying until the element shows up on the page or a maximum wait time has been exceeded (default 2 seconds).
@suchov
suchov / gist:8fa2966ae8a27a36e69a1a32e9285e21
Created April 12, 2017 08:49
Have a fast spec helper
Rspec-rails 3.0 introduced multiple default spec helpers.
When you initialize a Rails app with RSpec, it creates a `rails_helper.rb` which loads Rails and a `spec_helper.rb`
which doesn’t. When you don’t need Rails, or any of its de- pendencies, require your `spec_helper.rb`
for a modest time savings.
@suchov
suchov / gist:52ca59d9005db68021bef8d5c1662539
Last active April 12, 2017 08:51
Have a fast spec helper
Rspec-rails 3.0 introduced multiple default spec helpers.
When you initialize a Rails app with RSpec, it creates a `rails_helper.rb` which loads Rails and a `spec_helper.rb`
which doesn’t. When you don’t need Rails, or any of its dependencies, require your `spec_helper.rb`
for a modest time savings.
@suchov
suchov / spring
Last active April 12, 2017 09:01
Use an application preloader
Rails 4.1 introduced another default feature that reduces some of the time it takes to load Rails.
The feature is bundled in a gem called Spring https://github.com/rails/spring ,
and classifies itself as an application preloader.
@suchov
suchov / NO excessive database interaction
Created April 12, 2017 09:06
Only persist what is necessary
Persisting to the database takes far longer than initializing objects in memory, and
while we’re talking fractions of a second, each of these round trips to the database
adds up when running your entire suite.
When you initialize new objects, try to do so with the least overhead. Depending
on what you need, you should choose your initialization method in this order:
Object.new - initializes the object without FactoryGirl. Use this when you
don’t care about any validations or default values.
FactoryGirl.build_stubbed(:object)-initializestheobjectwithFactoryGirl,
@suchov
suchov / feature are slow
Created April 12, 2017 09:08
Move sad paths out of feature specs
Feature specs are slow. They have to boot up a fake browser and navigate around.
They’re particularly slow when using a JavaScript driver which incurs even more
overhead. While you do want a feature spec to cover every user facing feature of
your application, you also don’t want to duplicate coverage.
Many times, feature specs are written to cover both happy paths and sad paths. In
an attempt to mitigate duplicate code coverage with slower tests, we’ll often write
our happy path tests with feature specs, and sad paths with some other medium,
such as request specs or view specs. Finding a balance between too many and too
few feature specs comes with experience.